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

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

    XMLWordPrintable

Details

    • b124
    • x86
    • 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>.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: