JDK-8017490 : ContextClassLoader is not JNLPClassLoader
  • Type: Bug
  • Component: deploy
  • Sub-Component: webstart
  • Affected Version: 7u25
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_7
  • Submitted: 2013-06-21
  • Updated: 2013-07-26
  • Resolved: 2013-07-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7u40Resolved
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_25 " 
Java(TM) SE Runtime Environment (build 1.7.0_25-b16)
Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

EXTRA RELEVANT SYSTEM CONFIGURATION :
does not matter

A DESCRIPTION OF THE PROBLEM :
launch of WebStart RIA fails because of ClassNotFoundException.

reason is that ContextClassLoader of EventThread (Thread for java.awt.EventQueue) is not a JNLPClassLoader (but sun.misc.Launcher$AppClassLoader).

using javax.naming.InitialContext in EventThread fails when using InitialContextFactory implementation from JNLP JAR resource, because AppClassLoader does not know about the resources.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
use Java WebStart.

define 2 JAR resources in JNLP File:
1st JAR: main-class with main method.
2nd JAR: implementation of InitialContextFactory.

in main-class create a Runnable and call SwingUtilities.invokeLater.
in the Runnable create new javax.naming.InitialContext.
use a class from 2nd JAR resource as Context.INITIAL_CONTEXT_FACTORY.

application will throw javax.naming.NoInitialContextException (cause is java.lang.ClassNotFoundException) in constructor of InitialContext, because ContextClassLoader of AWT EventThread is not a JNLPClassLoader.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
ContextClassLoader of AWT EventThread should be JNLPClassLoader.
JNLPClassLoader should find InitialContextFactory implementation in JNLP JAR resource.
application should not fail.
ACTUAL -
application fails with ClassNotFoundException while constructing InitialContext

ERROR MESSAGES/STACK TRACES THAT OCCUR :
javax.naming.NoInitialContextException:
Cannot instantiate class: org.jboss.naming.HttpNamingContextFactory
java.lang.ClassNotFoundException:
org.jboss.naming.HttpNamingContextFactory


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
// main-class of Java WebStart RIA
public class JwsBug {
  public static void main(String[] args) {
    Runnable runnable = new Runnable() {
      @Override
      public void run() {
        System.out.println();

        Properties properties = new Properties();
        // org.jnp.interfaces.NamingContextFactory packaged in another JAR resource!
        properties.put(Context.INITIAL_CONTEXT_FACTORY,  " org.jnp.interfaces.NamingContextFactory " );
        properties.put(Context.PROVIDER_URL,  " localhost:1099 " );
        properties.put(Context.URL_PKG_PREFIXES,  " org.jnp.interfaces " );

        try {
          Context context = new InitialContext(properties);
          System.out.println( " context created:  "  + context.toString());
        }
        catch (NamingException e) {
          System.out.println( " context failed. " );
          e.printStackTrace();
        }
      }
    };

    // run Runnable in EventThread
    SwingUtilities.invokeLater(runnable);
  }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
pick up ContextClassLoader while in main Thread (main method of main-class) and set that ClassLoader as ContextClassLoader while executing in AWT EventThread.
Comments
Please remove the critical-watch label if this is closed as a dup.
24-07-2013

Will be fixed by changes for JDK-8017776. Closing as duplicate.
08-07-2013

we need to make sure that the patch for 8017776 will fix this test case.
05-07-2013