8032066: Serialized form has broken links to non private inner classes of package private

Reviewed-by: jjg
This commit is contained in:
Bhavesh Patel 2014-04-01 23:58:04 -07:00
parent e231918e58
commit d642f92759
6 changed files with 335 additions and 12 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,7 @@
package com.sun.tools.doclets.formats.html; package com.sun.tools.doclets.formats.html;
import java.io.*; import java.io.*;
import java.util.*;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.tools.doclets.formats.html.markup.*; import com.sun.tools.doclets.formats.html.markup.*;
import com.sun.tools.doclets.internal.toolkit.*; import com.sun.tools.doclets.internal.toolkit.*;
@ -45,6 +46,8 @@ import com.sun.tools.doclets.internal.toolkit.util.DocletAbortException;
public class SerializedFormWriterImpl extends SubWriterHolderWriter public class SerializedFormWriterImpl extends SubWriterHolderWriter
implements SerializedFormWriter { implements SerializedFormWriter {
List<ClassDoc> visibleClasses;
/** /**
* @param configuration the configuration data for the doclet * @param configuration the configuration data for the doclet
* @throws IOException * @throws IOException
@ -53,6 +56,7 @@ public class SerializedFormWriterImpl extends SubWriterHolderWriter
public SerializedFormWriterImpl(ConfigurationImpl configuration) public SerializedFormWriterImpl(ConfigurationImpl configuration)
throws IOException { throws IOException {
super(configuration, DocPaths.SERIALIZED_FORM); super(configuration, DocPaths.SERIALIZED_FORM);
visibleClasses = Arrays.asList(configuration.root.classes());
} }
/** /**
@ -120,6 +124,16 @@ public class SerializedFormWriterImpl extends SubWriterHolderWriter
return ul; return ul;
} }
/**
* Checks if a class is generated and is visible.
*
* @param classDoc the class being processed.
* @return true if the class, that is being processed, is generated and is visible.
*/
public boolean isVisibleClass(ClassDoc classDoc) {
return visibleClasses.contains(classDoc) && configuration.isGeneratedDoc(classDoc);
}
/** /**
* Get the serializable class heading. * Get the serializable class heading.
* *
@ -127,7 +141,7 @@ public class SerializedFormWriterImpl extends SubWriterHolderWriter
* @return a content tree for the class header * @return a content tree for the class header
*/ */
public Content getClassHeader(ClassDoc classDoc) { public Content getClassHeader(ClassDoc classDoc) {
Content classLink = (classDoc.isPublic() || classDoc.isProtected()) ? Content classLink = (isVisibleClass(classDoc)) ?
getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, classDoc) getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, classDoc)
.label(configuration.getClassName(classDoc))) : .label(configuration.getClassName(classDoc))) :
new StringContent(classDoc.qualifiedName()); new StringContent(classDoc.qualifiedName());

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,7 +26,7 @@ import java.io.*;
/* /*
* @test * @test
* @bug 4341304 4485668 4966728 * @bug 4341304 4485668 4966728 8032066
* @summary Test that methods readResolve and writeReplace show * @summary Test that methods readResolve and writeReplace show
* up in serialized-form.html the same way that readObject and writeObject do. * up in serialized-form.html the same way that readObject and writeObject do.
* If the doclet includes readResolve and writeReplace in the serialized-form * If the doclet includes readResolve and writeReplace in the serialized-form
@ -54,12 +54,70 @@ public class TestSerializedForm extends JavadocTester implements Serializable {
"protected&nbsp;java.lang.Object&nbsp;readObjectNoData()"}, "protected&nbsp;java.lang.Object&nbsp;readObjectNoData()"},
{BUG_ID + FS + "serialized-form.html", {BUG_ID + FS + "serialized-form.html",
"See Also"}, "See Also"},
{BUG_ID + "/serialized-form.html",
"<h3>Class pkg1.NestedInnerClass.InnerClass.ProNestedInnerClass " +
"extends java.lang.Object implements Serializable</h3>"},
{BUG_ID + "/serialized-form.html",
"<h3>Class pkg1.PrivateIncludeInnerClass.PriInnerClass extends " +
"java.lang.Object implements Serializable</h3>"},
{BUG_ID + "/serialized-form.html",
"<h3>Class pkg1.ProtectedInnerClass.ProInnerClass extends " +
"java.lang.Object implements Serializable</h3>"}
};
private static final String[][] TEST_PRIVATE = {
{BUG_ID + "-1/serialized-form.html",
"<h3>Class <a href=\"pkg1/NestedInnerClass.InnerClass.ProNestedInnerClass.html\" " +
"title=\"class in pkg1\">pkg1.NestedInnerClass.InnerClass.ProNestedInnerClass</a> " +
"extends java.lang.Object implements Serializable</h3>"},
{BUG_ID + "-1/serialized-form.html",
"<h3>Class <a href=\"pkg1/PrivateIncludeInnerClass.PriInnerClass.html\" title=\"class in pkg1\">" +
"pkg1.PrivateIncludeInnerClass.PriInnerClass</a> extends java.lang.Object implements Serializable</h3>"},
{BUG_ID + "-1/serialized-form.html",
"<h3>Class <a href=\"pkg1/ProtectedInnerClass.ProInnerClass.html\" title=\"class in pkg1\">" +
"pkg1.ProtectedInnerClass.ProInnerClass</a> extends java.lang.Object implements Serializable</h3>"}
};
private static final String[][] NEGATED_TEST = {
{BUG_ID + "/serialized-form.html",
"<h3>Class <a href=\"pkg1/NestedInnerClass.InnerClass.ProNestedInnerClass.html\" " +
"title=\"class in pkg1\">pkg1.NestedInnerClass.InnerClass.ProNestedInnerClass</a> " +
"extends java.lang.Object implements Serializable</h3>"},
{BUG_ID + "/serialized-form.html",
"<h3>Class <a href=\"pkg1/PrivateInnerClass.PriInnerClass.html\" title=\"class in pkg1\">" +
"pkg1.PrivateInnerClass.PriInnerClass</a> extends java.lang.Object implements Serializable</h3>"},
{BUG_ID + "/serialized-form.html",
"<h3>Class <a href=\"pkg1/ProtectedInnerClass.ProInnerClass.html\" title=\"class in pkg1\">" +
"pkg1.ProtectedInnerClass.ProInnerClass</a> extends java.lang.Object implements Serializable</h3>"},
{BUG_ID + "/serialized-form.html",
"<h3>Class pkg1.PublicExcludeInnerClass.PubInnerClass extends java.lang.Object implements " +
"Serializable</h3>"}
};
private static final String[][] NEGATED_TEST_PRIVATE = {
{BUG_ID + "-1/serialized-form.html",
"<h3>Class pkg1.NestedInnerClass.InnerClass.ProNestedInnerClass " +
"extends java.lang.Object implements Serializable</h3>"},
{BUG_ID + "-1/serialized-form.html",
"<h3>Class pkg1.PrivateInnerClass.PriInnerClass extends " +
"java.lang.Object implements Serializable</h3>"},
{BUG_ID + "-1/serialized-form.html",
"<h3>Class pkg1.ProtectedInnerClass.ProInnerClass extends " +
"java.lang.Object implements Serializable</h3>"},
{BUG_ID + "-1/serialized-form.html",
"<h3>Class <a href=\"pkg1/PublicExcludeInnerClass.PubInnerClass.html\" " +
"title=\"class in pkg1\">pkg1.PublicExcludeInnerClass.PubInnerClass</a> " +
"extends java.lang.Object implements Serializable</h3>"}
}; };
private static final String[][] NEGATED_TEST = NO_TEST;
private static final String[] ARGS = new String[] { private static final String[] ARGS = new String[] {
"-d", BUG_ID, "-sourcepath", SRC_DIR, "-d", BUG_ID, "-sourcepath", SRC_DIR,
SRC_DIR + FS + "TestSerializedForm.java" SRC_DIR + "/TestSerializedForm.java", "pkg1"
};
private static final String[] ARGS_PRIVATE = new String[] {
"-private", "-d", BUG_ID + "-1", "-sourcepath", SRC_DIR,
SRC_DIR + "/TestSerializedForm.java", "pkg1"
}; };
/** /**
@ -74,7 +132,8 @@ public class TestSerializedForm extends JavadocTester implements Serializable {
*/ */
public static void main(String[] args) { public static void main(String[] args) {
TestSerializedForm tester = new TestSerializedForm(); TestSerializedForm tester = new TestSerializedForm();
int actualExitCode = run(tester, ARGS, TEST, NEGATED_TEST); run(tester, ARGS, TEST, NEGATED_TEST);
run(tester, ARGS_PRIVATE, TEST_PRIVATE, NEGATED_TEST_PRIVATE);
tester.printSummary(); tester.printSummary();
} }
@ -93,34 +152,39 @@ public class TestSerializedForm extends JavadocTester implements Serializable {
} }
/** /**
* @param s ObjectInputStream.
* @throws IOException when there is an I/O error. * @throws IOException when there is an I/O error.
* @serial * @serial
*/ */
private void readObject(ObjectInputStream s) {} private void readObject(ObjectInputStream s) throws IOException {}
/** /**
* @param s ObjectOutputStream.
* @throws IOException when there is an I/O error. * @throws IOException when there is an I/O error.
* @serial * @serial
*/ */
private void writeObject(ObjectOutputStream s) {} private void writeObject(ObjectOutputStream s) throws IOException {}
/** /**
* @throws IOException when there is an I/O error. * @throws IOException when there is an I/O error.
* @serialData This is a serial data comment. * @serialData This is a serial data comment.
* @return an object.
*/ */
protected Object readResolve(){return null;} protected Object readResolve() throws IOException {return null;}
/** /**
* @throws IOException when there is an I/O error. * @throws IOException when there is an I/O error.
* @serialData This is a serial data comment. * @serialData This is a serial data comment.
* @return an object.
*/ */
protected Object writeReplace(){return null;} protected Object writeReplace() throws IOException {return null;}
/** /**
* @throws IOException when there is an I/O error. * @throws IOException when there is an I/O error.
* @serialData This is a serial data comment. * @serialData This is a serial data comment.
* @return an object.
*/ */
protected Object readObjectNoData() { protected Object readObjectNoData() throws IOException {
return null; return null;
} }

View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package pkg1;
import java.io.*;
/**
* A test class where the outer class is package private and the inner class is private
* and a nested inner class is protected.
*
* @author Bhavesh Patel
*/
class NestedInnerClass {
private static class InnerClass {
protected static class ProNestedInnerClass implements java.io.Serializable {
public final int SERIALIZABLE_CONSTANT = 1;
/**
* @param s ObjectInputStream.
* @throws IOException when there is an I/O error.
* @serial
*/
private void readObject(ObjectInputStream s) throws IOException {
}
/**
* @param s ObjectOutputStream.
* @throws IOException when there is an I/O error.
* @serial
*/
private void writeObject(ObjectOutputStream s) throws IOException {
}
}
}
}

View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package pkg1;
import java.io.*;
/**
* A test class where the outer class is package private and inner class
* is private which is included using the tag.
*
* @author Bhavesh Patel
*/
class PrivateIncludeInnerClass {
/**
* @serial include
*/
private static class PriInnerClass implements java.io.Serializable {
public final int SERIALIZABLE_CONSTANT = 1;
/**
* @param s ObjectInputStream.
* @throws IOException when there is an I/O error.
* @serial
*/
private void readObject(ObjectInputStream s) throws IOException {
}
/**
* @param s ObjectOutputStream.
* @throws IOException when there is an I/O error.
* @serial
*/
private void writeObject(ObjectOutputStream s) throws IOException {
}
}
}

View file

@ -0,0 +1,59 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package pkg1;
import java.io.*;
/**
* A test class where outer class is package private and the inner class is
* protected.
*
* @author Bhavesh Patel
*/
class ProtectedInnerClass {
protected static class ProInnerClass implements java.io.Serializable {
public final int SERIALIZABLE_CONSTANT = 1;
/**
* @param s ObjectInputStream.
* @throws IOException when there is an I/O error.
* @serial
*/
private void readObject(ObjectInputStream s) throws IOException {
}
/**
* @param s ObjectOutputStream.
* @throws IOException when there is an I/O error.
* @serial
*/
private void writeObject(ObjectOutputStream s) throws IOException {
}
}
}

View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package pkg1;
import java.io.*;
/**
* A test class where the outer class is package private and inner class
* is public which is excluded using the tag.
*
* @author Bhavesh Patel
*/
class PublicExcludeInnerClass {
/**
* @serial exclude
*/
public static class PubInnerClass implements java.io.Serializable {
public final int SERIALIZABLE_CONSTANT = 1;
/**
* @param s ObjectInputStream.
* @throws IOException when there is an I/O error.
* @serial
*/
private void readObject(ObjectInputStream s) throws IOException {
}
/**
* @param s ObjectOutputStream.
* @throws IOException when there is an I/O error.
* @serial
*/
private void writeObject(ObjectOutputStream s) throws IOException {
}
}
}