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

ContextClassLoader is not JNLPClassLoader

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 7u25
    • Fix Version/s: 7u40
    • Component/s: deploy
    • Labels:

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dmarkov Dmitry Markov
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: