8032066: Serialized form has broken links to non private inner classes of package private
authorbpatel
Tue, 01 Apr 2014 23:58:04 -0700
changeset 23805 3ef77c1ebf0b
parent 23804 b5632efbc768
child 23806 4fd49d097764
child 23807 a85a06f3b9d8
8032066: Serialized form has broken links to non private inner classes of package private Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/doclets/formats/html/SerializedFormWriterImpl.java
langtools/test/com/sun/javadoc/testSerializedForm/TestSerializedForm.java
langtools/test/com/sun/javadoc/testSerializedForm/pkg1/NestedInnerClass.java
langtools/test/com/sun/javadoc/testSerializedForm/pkg1/PrivateIncludeInnerClass.java
langtools/test/com/sun/javadoc/testSerializedForm/pkg1/ProtectedInnerClass.java
langtools/test/com/sun/javadoc/testSerializedForm/pkg1/PublicExcludeInnerClass.java
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/SerializedFormWriterImpl.java	Tue Apr 01 23:52:10 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/SerializedFormWriterImpl.java	Tue Apr 01 23:58:04 2014 -0700
@@ -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.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
 package com.sun.tools.doclets.formats.html;
 
 import java.io.*;
+import java.util.*;
 import com.sun.javadoc.*;
 import com.sun.tools.doclets.formats.html.markup.*;
 import com.sun.tools.doclets.internal.toolkit.*;
@@ -45,6 +46,8 @@
 public class SerializedFormWriterImpl extends SubWriterHolderWriter
     implements SerializedFormWriter {
 
+    List<ClassDoc> visibleClasses;
+
     /**
      * @param configuration the configuration data for the doclet
      * @throws IOException
@@ -53,6 +56,7 @@
     public SerializedFormWriterImpl(ConfigurationImpl configuration)
             throws IOException {
         super(configuration, DocPaths.SERIALIZED_FORM);
+        visibleClasses = Arrays.asList(configuration.root.classes());
     }
 
     /**
@@ -121,13 +125,23 @@
     }
 
     /**
+     * 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.
      *
      * @param classDoc the class being processed
      * @return a content tree for the class header
      */
     public Content getClassHeader(ClassDoc classDoc) {
-        Content classLink = (classDoc.isPublic() || classDoc.isProtected()) ?
+        Content classLink = (isVisibleClass(classDoc)) ?
             getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, classDoc)
             .label(configuration.getClassName(classDoc))) :
             new StringContent(classDoc.qualifiedName());
--- a/langtools/test/com/sun/javadoc/testSerializedForm/TestSerializedForm.java	Tue Apr 01 23:52:10 2014 -0700
+++ b/langtools/test/com/sun/javadoc/testSerializedForm/TestSerializedForm.java	Tue Apr 01 23:58:04 2014 -0700
@@ -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.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,7 @@
 
 /*
  * @test
- * @bug 4341304 4485668 4966728
+ * @bug 4341304 4485668 4966728 8032066
  * @summary Test that methods readResolve and writeReplace show
  * up in serialized-form.html the same way that readObject and writeObject do.
  * If the doclet includes readResolve and writeReplace in the serialized-form
@@ -54,12 +54,70 @@
             "protected&nbsp;java.lang.Object&nbsp;readObjectNoData()"},
         {BUG_ID + FS + "serialized-form.html",
             "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 = NO_TEST;
+    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[] ARGS = new String[] {
         "-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 static void main(String[] args) {
         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();
     }
 
@@ -93,34 +152,39 @@
     }
 
     /**
+     * @param s ObjectInputStream.
      * @throws IOException when there is an I/O error.
      * @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.
      * @serial
      */
-    private void writeObject(ObjectOutputStream s) {}
+    private void writeObject(ObjectOutputStream s) throws IOException {}
 
     /**
      * @throws IOException when there is an I/O error.
      * @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.
      * @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.
      * @serialData This is a serial data comment.
+     * @return an object.
      */
-    protected Object readObjectNoData() {
+    protected Object readObjectNoData() throws IOException {
         return null;
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/com/sun/javadoc/testSerializedForm/pkg1/NestedInnerClass.java	Tue Apr 01 23:58:04 2014 -0700
@@ -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 {
+            }
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/com/sun/javadoc/testSerializedForm/pkg1/PrivateIncludeInnerClass.java	Tue Apr 01 23:58:04 2014 -0700
@@ -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 {
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/com/sun/javadoc/testSerializedForm/pkg1/ProtectedInnerClass.java	Tue Apr 01 23:58:04 2014 -0700
@@ -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 {
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/com/sun/javadoc/testSerializedForm/pkg1/PublicExcludeInnerClass.java	Tue Apr 01 23:58:04 2014 -0700
@@ -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 {
+        }
+    }
+}