Uploaded image for project: 'JBoss Enterprise Application Platform 4 and 5'
  1. JBoss Enterprise Application Platform 4 and 5
  2. JBPAPP-4395

Thread Context Classloader not set correctly on MBean notification callback

XMLWordPrintable

    • Not Required

      Unable to do new InitialContext() inside of a notification handler. Testing shows that the Thread.currentThread.getContextClassLoader is not set correctly. See attached example. Note the example works fine in EAP 4.3 (with the mbean annotation packages changed)

      I have created a simple Annotated MBean that prints some classloader info when it starts and then registers itself to get notifications for jboss.system:type=Server. When it gets a notification, I have it print the classloader info again and the Thread CL info is not the same. Then I do a new InitialContext and it fails to find "org.jnp.interfaces.NamingContextFactory".

      When the MBean starts:

      Thread.currentThread().getContextClassLoader()
      BaseClassLoader@ef22c9

      {vfszip:/NotBackedUp/bmaxwell/server/jboss-eap-5.0.1-debug/server/active/deploy/mbean-notification-handler.jar/}

      Thread.currentThread().getContextClassLoader(): vfsfile:/NotBackedUp/bmaxwell/server/jboss-eap-5.0.1-debug/server/active/conf/jndi.properties
      (no exception doing Thread.currentThread().getContextClassLoader().loadClass("org.jnp.interfaces.NamingContextFactory")

      When the notification is fired and the callback is invoked on the MBean:

      Thread.currentThread().getContextClassLoader()
      org.jboss.bootstrap.NoAnnotationURLClassLoader@1d99a4d
      Thread.currentThread().getContextClassLoader(): null
      16:46:44,830 ERROR [STDERR] java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
      16:46:44,830 ERROR [STDERR] at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
      16:46:44,830 ERROR [STDERR] at java.security.AccessController.doPrivileged(Native Method)
      16:46:44,830 ERROR [STDERR] at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      16:46:44,830 ERROR [STDERR] at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      16:46:44,830 ERROR [STDERR] at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
      16:46:44,830 ERROR [STDERR] at com.jboss.examples.mbean.NotificationHandler.printCLs(NotificationHandler.java:173)
      16:46:44,831 ERROR [STDERR] at com.jboss.examples.mbean.NotificationHandler.onJBossStarted(NotificationHandler.java:183)
      16:46:44,831 ERROR [STDERR] at com.jboss.examples.mbean.NotificationHandler.handleNotification(NotificationHandler.java:145)
      16:46:44,831 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor196.invoke(Unknown Source)
      16:46:44,831 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      16:46:44,831 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597)
      16:46:44,831 ERROR [STDERR] at org.jboss.mx.notification.NotificationListenerProxy.invoke(NotificationListenerProxy.java:153)
      16:46:44,831 ERROR [STDERR] at $Proxy137.handleNotification(Unknown Source)
      16:46:44,831 ERROR [STDERR] at javax.management.NotificationBroadcasterSupport.handleNotification(NotificationBroadcasterSupport.java:257)
      16:46:44,831 ERROR [STDERR] at javax.management.NotificationBroadcasterSupport$SendNotifJob.run(NotificationBroadcasterSupport.java:322)
      16:46:44,831 ERROR [STDERR] at javax.management.NotificationBroadcasterSupport$1.execute(NotificationBroadcasterSupport.java:307)
      16:46:44,831 ERROR [STDERR] at javax.management.NotificationBroadcasterSupport.sendNotification(NotificationBroadcasterSupport.java:229)
      16:46:44,832 ERROR [STDERR] at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:484)
      16:46:44,832 ERROR [STDERR] at org.jboss.Main.boot(Main.java:221)
      16:46:44,832 ERROR [STDERR] at org.jboss.Main$1.run(Main.java:556)
      16:46:44,832 ERROR [STDERR] at java.lang.Thread.run(Thread.java:619)

      Then it hits the code where I do new InitialContext().lookup("java:DefaultDS");

      16:46:44,834 ERROR [NotificationHandler] Exception trying to start service polling: javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
      javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
      at javax.naming.InitialContext.init(InitialContext.java:223)
      at javax.naming.InitialContext.<init>(InitialContext.java:175)
      at com.jboss.examples.mbean.NotificationHandler.onJBossStarted(NotificationHandler.java:185)
      at com.jboss.examples.mbean.NotificationHandler.handleNotification(NotificationHandler.java:145)
      at sun.reflect.GeneratedMethodAccessor196.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.jboss.mx.notification.NotificationListenerProxy.invoke(NotificationListenerProxy.java:153)
      at $Proxy137.handleNotification(Unknown Source)
      at javax.management.NotificationBroadcasterSupport.handleNotification(NotificationBroadcasterSupport.java:257)
      at javax.management.NotificationBroadcasterSupport$SendNotifJob.run(NotificationBroadcasterSupport.java:322)
      at javax.management.NotificationBroadcasterSupport$1.execute(NotificationBroadcasterSupport.java:307)
      at javax.management.NotificationBroadcasterSupport.sendNotification(NotificationBroadcasterSupport.java:229)
      at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:484)
      at org.jboss.Main.boot(Main.java:221)
      at org.jboss.Main$1.run(Main.java:556)
      at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
      at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:247)
      at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
      ... 18 more

              arubinge@redhat.com Andrew Rubinger (Inactive)
              rhn-support-bmaxwell Brad Maxwell
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: