Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6882559

new JEditorPane("text/plain","") fails for null context class loader

    Details

    • Subcomponent:
    • Resolved In Build:
      b124
    • CPU:
      x86
    • OS:
      solaris

      Backports

        Description

        At least with Java 6u13 (and apparently regardless of platform), executing
          public final class EditorTest {
            public static void main(String[] arguments) {
              Thread.currentThread().setContextClassLoader(null);
              new javax.swing.JEditorPane("text/plain", "");
            }
          }
        fails with
          Exception in thread "main" java.lang.NullPointerException
          at java.util.Hashtable.put(Hashtable.java:394)
          at javax.swing.JEditorPane.registerEditorKitForContentType(JEditorPane.java:1329)
          at javax.swing.JEditorPane.registerEditorKitForContentType(JEditorPane.java:1311)
          at javax.swing.JEditorPane.loadDefaultKitsIfNecessary(JEditorPane.java:1389)
          at javax.swing.JEditorPane.getKitTypeRegistry(JEditorPane.java:1346)
          at javax.swing.JEditorPane.createEditorKitForContentType(JEditorPane.java:1271)
          at javax.swing.JEditorPane.getEditorKitForContentType(JEditorPane.java:1128)
          at javax.swing.JEditorPane.setContentType(JEditorPane.java:1019)
          at javax.swing.JEditorPane.<init>(JEditorPane.java:274)
          at EditorTest.main(EditorTest.java:4)

        The problem appears to be that the null context class loader shall be put as a value into a Hashtable, which fails with a NullPointerException. The documentation of JEditorPane does not directly state any requirements on the context class loader, and esp. for using the default "text/plain" it is not obvious why there should be any.

        That a thread's context class loader is null does indeed happen "in real life," namely when a thread that was spawned outside the JVM is attached to the JVM via JNI; according to <http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/invocation.html#attach_current_thread> "[w]hen a thread is attached to the VM, the context class loader is the bootstrap loader," and in turn "[s]ome implementations may use null to represent the bootstrap class loader," according to <http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html#getParent()&gt;).

        OpenOffice.org is having a problem with this, see <http://qa.openoffice.org/issues/show_bug.cgi?id=102164#desc8>.

          Issue Links

            Activity

            Hide
            mcherkas Mikhail Cherkasov added a comment - - edited
            The problem is that JTextPane during initialization saves
            Thread.contextClassloader which is null, it saves it for lazy
            initialization(later it will init some other data), but class loader is a
            null and Hashtable, which is used to store class loader, doesn't support a
            null value as result we get an exception. However JTextPane doesn't need to save
            Thread.contextClassloader, it's optional:
            http://hg.openjdk.java.net/jdk9/client/jdk/file/fb38b0925915/src/java.desktop/share/classes/javax/swing/JEditorPane.java#l1192
            so it will work fine even if ClassLoader is null.
            To fix this I wrapped a classloader into Optional before to put it into Hashtable.
            Show
            mcherkas Mikhail Cherkasov added a comment - - edited The problem is that JTextPane during initialization saves Thread.contextClassloader which is null, it saves it for lazy initialization(later it will init some other data), but class loader is a null and Hashtable, which is used to store class loader, doesn't support a null value as result we get an exception. However JTextPane doesn't need to save Thread.contextClassloader, it's optional: http://hg.openjdk.java.net/jdk9/client/jdk/file/fb38b0925915/src/java.desktop/share/classes/javax/swing/JEditorPane.java#l1192 so it will work fine even if ClassLoader is null. To fix this I wrapped a classloader into Optional before to put it into Hashtable.
            Show
            mcherkas Mikhail Cherkasov added a comment - Review: http://mail.openjdk.java.net/pipermail/swing-dev/2016-May/005916.html
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/client/jdk/rev/a82e6b2bea00
            User: mcherkas
            Date: 2016-05-18 15:36:23 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/client/jdk/rev/a82e6b2bea00 User: mcherkas Date: 2016-05-18 15:36:23 +0000
            Hide
            scfitch Stephen Fitch added a comment -
            If there's a clear reason, for addressing this on JDK 6 then we can consider a backport, but at this time there are no plans to address for JDK 6.
            Show
            scfitch Stephen Fitch added a comment - If there's a clear reason, for addressing this on JDK 6 then we can consider a backport, but at this time there are no plans to address for JDK 6.
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/a82e6b2bea00
            User: lana
            Date: 2016-06-22 19:53:10 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/a82e6b2bea00 User: lana Date: 2016-06-22 19:53:10 +0000

              People

              • Assignee:
                mcherkas Mikhail Cherkasov
                Reporter:
                duke J. Duke (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: