How can I safely solve this Java context classloader problem? -


The

The one and only problem in starting my Java desktop app users find me only when about one third of its begins to

  formula exception "AWT-EventQueue-java.lang.NullPointerException (Hashtable at 0" java.util.Hashtable.put: time is thrown at a NullPointerException startup Other two-thirds .java: 394) javax.swing.JEditorPane.registerEditorKitForContentType (JEditorPane.java:1327) javax.swing.JEditorPane.registerEditorKitForContentType (JEditorPane.java:1309) javax.swing.JEditorPane.loadDefaultKitsIf required (JE ditorPane.java:1387 javax.swing.JEditorPane.getEditorKitClassNameForContentType (jEditorPane.java:1340) at) Javax.swing.JEditorPane.getKitTypeRegistry (jEditorPane.java:1344) on javax.swing.JTextPane. & Lt; Init & gt; (JTextPane.java:76) on java.awt.event.InvocationEvent.dispatch (InvocationEvent.java:209) on .Launcher $ 1.run java.awt.EventQueue.dispatchEvent (EventQueue.java:633) on myapp (Launcher. Java: 13) java.awt.EventDispatchThread on .pumpOneEventForFilters (EventDispatchThread.java:296) java.awt.EventDispatchThread.pu on Java.awt.EventDispatchThread.pumpEventsForHierarchy at mpEventsForFilter (EventDispatchThread.java Month 11) java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java.19)  

I Stack trace is the reason that is followed to find that

  Thread.currentThread (). GetContextClassLoader ()  

Returning the null in JEditorPane.

Googling suggests that this is a sporadic, very sparse, and mysterious problem that affects some people.

My question is, what can I do as a work? If I call it before creating an EditorPane, then it can work:

  Thread.currentThread (). SetContextClassLoader (MyClass.class.getClassLoader ());  

But I do not really understand classloaders and I would like to (and I have tried to understand them better). I think contextClassLoader in EDT may have a bad effect in return.

Any thoughts that I can do?

EDIT: I had some correspondence with the person who understands java classloaders well. It seems that this is a vague classloader race situation. That's a bug in Java.

  thread. CurrentThread (). GetContextClassLoader ()  

If the code JEditorPane.registerEditorKitForContentType a bug does not check for a null return value in the above code, it is JEditorPane . Note that MyClass.class.getClassLoader () . Only one can trust you.

WrenchTrad (); Classododer old = thread .getContextClassLoader (); Thread.setContextClassLoader (fooClassLoader); Try {// call which is class class loader} based on {threads.setContextClassLoader (old); }

The value that should be set by setContextClassLoader will depend on the intent of the code that gives it the user and the ClassLoader framework You are walking in

In a standalone application, you might just be away from using the ClassLoader (in the context of the current class):

  private Classloader findClassLoaderForContext (class  C). {Classloader reference = Thread.currentThread () getContextClassLoader (); Classloader me = C Gate Classloader (); Classloader System = Classloader .getSystemClassLoader (); Return (reference == zero)? (Me == tap)? System: Me: Reference; }  

In the Classloader-sensitive plug-in framework (a Java EE server will be a prime example), it will pay to understand the nature and usage of the loading scheme.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -