10 Replies Latest reply on Mar 9, 2005 3:27 PM by Bela Ban

    Using JBossCache within Eclipse

    Karl Koster Newbie

      I am trying to use JBossCache within an Eclipse plugin. The cache is instantiating just fine, but as soon as I try to put an object in the cache, I get an NPE with the following stack trace.

      org.jboss.util.NestedRuntimeException: - nested throwable: (java.lang.NullPointerException)
      at org.jboss.cache.TreeCache.invokeMethod(TreeCache.java:3083)
      at org.jboss.cache.TreeCache.put(TreeCache.java:1758)
      at org.jboss.cache.TreeCache.put(TreeCache.java:1741)
      at com.amaranth.unit.factory.SimpleUnitFactory.init(SimpleUnitFactory.java:58)
      at com.amaranth.unit.factory.SimpleUnitFactory.(SimpleUnitFactory.java:46)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at java.lang.Class.newInstance0(Unknown Source)
      at java.lang.Class.newInstance(Unknown Source)
      at org.apache.commons.discovery.tools.ClassUtils.newInstance(ClassUtils.java:157)
      at org.apache.commons.discovery.tools.SPInterface.newInstance(SPInterface.java:197)
      at org.apache.commons.discovery.tools.DiscoverClass.newInstance(DiscoverClass.java:579)
      at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:418)
      at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:272)
      at com.amaranth.quantity.DefaultQuantity.(DefaultQuantity.java:59)
      at com.amaranth.commodity.factory.SimpleCommodityFactory.init(SimpleCommodityFactory.java:53)
      at com.amaranth.commodity.factory.SimpleCommodityFactory.(SimpleCommodityFactory.java:44)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at java.lang.Class.newInstance0(Unknown Source)
      at java.lang.Class.newInstance(Unknown Source)
      at org.apache.commons.discovery.tools.ClassUtils.newInstance(ClassUtils.java:157)
      at org.apache.commons.discovery.tools.SPInterface.newInstance(SPInterface.java:197)
      at org.apache.commons.discovery.tools.DiscoverClass.newInstance(DiscoverClass.java:579)
      at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:418)
      at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:272)
      at com.amaranth.energy.workbench.rcp.CommodityView$ViewContentProvider.getElements(CommodityView.java:45)
      at org.eclipse.jface.viewers.StructuredViewer.getRawChildren(StructuredViewer.java:766)
      at org.eclipse.jface.viewers.AbstractTreeViewer.getRawChildren(AbstractTreeViewer.java:747)
      at org.eclipse.jface.viewers.StructuredViewer.getFilteredChildren(StructuredViewer.java:708)
      at org.eclipse.jface.viewers.StructuredViewer.getSortedChildren(StructuredViewer.java:823)
      at org.eclipse.jface.viewers.AbstractTreeViewer$1.run(AbstractTreeViewer.java:381)
      at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
      at org.eclipse.jface.viewers.AbstractTreeViewer.createChildren(AbstractTreeViewer.java:363)
      at org.eclipse.jface.viewers.AbstractTreeViewer$5.run(AbstractTreeViewer.java:834)
      at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1109)
      at org.eclipse.jface.viewers.AbstractTreeViewer.inputChanged(AbstractTreeViewer.java:824)
      at org.eclipse.jface.viewers.ContentViewer.setInput(ContentViewer.java:248)
      at org.eclipse.jface.viewers.StructuredViewer.setInput(StructuredViewer.java:1323)
      at com.amaranth.energy.workbench.rcp.CommodityView.createPartControl(CommodityView.java:98)
      at org.eclipse.ui.internal.PartPane$2.run(PartPane.java:148)
      at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1015)
      at org.eclipse.core.runtime.Platform.run(Platform.java:757)
      at org.eclipse.ui.internal.PartPane.doCreateChildControl(PartPane.java:144)
      at org.eclipse.ui.internal.ViewPane.doCreateChildControl(ViewPane.java:135)
      at org.eclipse.ui.internal.PartPane.createChildControl(PartPane.java:349)
      at org.eclipse.ui.internal.ViewFactory$1.run(ViewFactory.java:405)
      at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1015)
      at org.eclipse.core.runtime.Platform.run(Platform.java:757)
      at org.eclipse.ui.internal.ViewFactory.busyRestoreView(ViewFactory.java:289)
      at org.eclipse.ui.internal.ViewFactory$2.run(ViewFactory.java:589)
      at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
      at org.eclipse.ui.internal.ViewFactory.restoreView(ViewFactory.java:586)
      at org.eclipse.ui.internal.ViewFactory$ViewReference.getPart(ViewFactory.java:108)
      at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:329)
      at org.eclipse.ui.internal.ViewPane.setVisible(ViewPane.java:607)
      at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:126)
      at org.eclipse.ui.internal.presentations.newapi.PresentablePartFolder.select(PresentablePartFolder.java:266)
      at org.eclipse.ui.internal.presentations.newapi.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
      at org.eclipse.ui.internal.presentations.newapi.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:381)
      at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1051)
      at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1009)
      at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1200)
      at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:521)
      at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:473)
      at org.eclipse.ui.internal.PartSashContainer.createControl(PartSashContainer.java:485)
      at org.eclipse.ui.internal.PerspectiveHelper.activate(PerspectiveHelper.java:230)
      at org.eclipse.ui.internal.Perspective.onActivate(Perspective.java:777)
      at org.eclipse.ui.internal.WorkbenchPage.onActivate(WorkbenchPage.java:2133)
      at org.eclipse.ui.internal.WorkbenchWindow$4.run(WorkbenchWindow.java:2235)
      at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
      at org.eclipse.ui.internal.WorkbenchWindow.setActivePage(WorkbenchWindow.java:2221)
      at org.eclipse.ui.internal.WorkbenchWindow.busyOpenPage(WorkbenchWindow.java:572)
      at org.eclipse.ui.internal.Workbench.busyOpenWorkbenchWindow(Workbench.java:587)
      at org.eclipse.ui.internal.Workbench.openFirstTimeWindow(Workbench.java:1209)
      at org.eclipse.ui.internal.WorkbenchConfigurer.openFirstTimeWindow(WorkbenchConfigurer.java:178)
      at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:717)
      at org.eclipse.ui.internal.Workbench.init(Workbench.java:918)
      at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1554)
      at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:293)
      at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:144)
      at com.amaranth.energy.workbench.rcp.WorkbenchApplication.run(WorkbenchApplication.java:21)
      at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:228)
      at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:333)
      at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:150)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.eclipse.core.launcher.Main.invokeFramework(Main.java:268)
      at org.eclipse.core.launcher.Main.basicRun(Main.java:260)
      at org.eclipse.core.launcher.Main.run(Main.java:887)
      at org.eclipse.core.launcher.Main.main(Main.java:871)
      Caused by: java.lang.NullPointerException
      at org.jboss.cache.TreeCache.invokeMethod(TreeCache.java:3078)
      ... 96 more

      When I run the component that uses the cache outside of Eclipse I have no problems. I am guessing it has to do with Eclipse's classloading mechanism. However, the source for JBossCache does not accompany the download and I don't see a tag in CVS for JBossCache 1.2, the version I am using. So, I can't even tell what the content of the line is that is causing the NPE.

      Any help/direction in this matter would be appreciated.

      Thanks,
      Karl

        • 1. Re: Using JBossCache within Eclipse
          Bela Ban Master

          The missing tag is my fault: I simply forgot to tag the CVS when I released 1.2. But you can use the date 2004-12-09 and cvs -D to get the correct version based on the date.
          I'm interested in knowing what the problem is, doesn't look like a classloading issue to me though...

          • 2. Re: Using JBossCache within Eclipse
            Ben Wang Master

            I have a feeling that your problem with Eclipse is the library jar files.

            -Ben

            • 3. Re: Using JBossCache within Eclipse
              Karl Koster Newbie

              Ben, could you elaborate on that.

              It only seems to be a problem when bundling JBossCache jars with an Eclipse application. Simply using the JBossCache in "normal" development doesn't seem to be a problem. It is difficult to tell what is happening. The debugger within Eclipse doesn't seem to like tracing into the source of jboss-cache.jar. I keep getting error dialogs with no information when stepping into the code.

              • 4. Re: Using JBossCache within Eclipse
                Karl Koster Newbie

                I have managed to trace it to the invokeMethod method of org.jboss.cache.TreeCache. It seems that the interceptor_chain variable is null. I am using exactly the same method to initialize the TreeCache instance (i.e. constructing an InputStream from a the XML resource for the configuration and passing it and the TreeCache instance to an instance of PropertyConfigurator)

                When using the TreeCache outside of the Eclipse application, the interceptor_chain variable is initialized to an instance of org.jboss.cache.interceptors.CreateIfNotExistsInterceptor. When using it inside of an Eclipse application this initialization is not occuring.

                I enabled some additional logging trapped the following exception when starting the TreeCache service.

                Mar 9, 2005 8:00:03 AM com.amaranth.cache.DefaultCacheFactory
                SEVERE: org.jboss.cache.DummyTransactionManagerLookup
                java.lang.ClassNotFoundException: org.jboss.cache.DummyTransactionManagerLookup
                at java.net.URLClassLoader$1.run(Unknown Source)
                at java.security.AccessController.doPrivileged(Native Method)
                at java.net.URLClassLoader.findClass(Unknown Source)
                at java.lang.ClassLoader.loadClass(Unknown Source)
                at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
                at java.lang.ClassLoader.loadClass(Unknown Source)
                at org.jboss.cache.TreeCache.startService(TreeCache.java:1040)
                at com.amaranth.cache.DefaultCacheFactory.(DefaultCacheFactory.java:51)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
                at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
                at java.lang.reflect.Constructor.newInstance(Unknown Source)
                at java.lang.Class.newInstance0(Unknown Source)
                at java.lang.Class.newInstance(Unknown Source)
                at org.apache.commons.discovery.tools.ClassUtils.newInstance(ClassUtils.java:157)
                at org.apache.commons.discovery.tools.SPInterface.newInstance(SPInterface.java:197)
                at org.apache.commons.discovery.tools.DiscoverClass.newInstance(DiscoverClass.java:579)
                at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:418)
                at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:272)
                at com.amaranth.commodity.factory.SimpleCommodityFactory.getCacheFactory(SimpleCommodityFactory.java:202)
                at com.amaranth.commodity.factory.SimpleCommodityFactory.init(SimpleCommodityFactory.java:48)
                at com.amaranth.commodity.factory.SimpleCommodityFactory.(SimpleCommodityFactory.java:44)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
                at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
                at java.lang.reflect.Constructor.newInstance(Unknown Source)
                at java.lang.Class.newInstance0(Unknown Source)
                at java.lang.Class.newInstance(Unknown Source)
                at org.apache.commons.discovery.tools.ClassUtils.newInstance(ClassUtils.java:157)
                at org.apache.commons.discovery.tools.SPInterface.newInstance(SPInterface.java:197)
                at org.apache.commons.discovery.tools.DiscoverClass.newInstance(DiscoverClass.java:579)
                at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:418)
                at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:272)
                at com.amaranth.energy.workbench.rcp.CommodityView$ViewContentProvider.getElements(CommodityView.java:45)
                at org.eclipse.jface.viewers.StructuredViewer.getRawChildren(StructuredViewer.java:766)
                at org.eclipse.jface.viewers.AbstractTreeViewer.getRawChildren(AbstractTreeViewer.java:747)
                at org.eclipse.jface.viewers.StructuredViewer.getFilteredChildren(StructuredViewer.java:708)
                at org.eclipse.jface.viewers.StructuredViewer.getSortedChildren(StructuredViewer.java:823)
                at org.eclipse.jface.viewers.AbstractTreeViewer$1.run(AbstractTreeViewer.java:381)
                at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
                at org.eclipse.jface.viewers.AbstractTreeViewer.createChildren(AbstractTreeViewer.java:363)
                at org.eclipse.jface.viewers.AbstractTreeViewer$5.run(AbstractTreeViewer.java:834)
                at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1109)
                at org.eclipse.jface.viewers.AbstractTreeViewer.inputChanged(AbstractTreeViewer.java:824)
                at org.eclipse.jface.viewers.ContentViewer.setInput(ContentViewer.java:248)
                at org.eclipse.jface.viewers.StructuredViewer.setInput(StructuredViewer.java:1323)
                at com.amaranth.energy.workbench.rcp.CommodityView.createPartControl(CommodityView.java:98)
                at org.eclipse.ui.internal.PartPane$2.run(PartPane.java:148)
                at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1015)
                at org.eclipse.core.runtime.Platform.run(Platform.java:757)
                at org.eclipse.ui.internal.PartPane.doCreateChildControl(PartPane.java:144)
                at org.eclipse.ui.internal.ViewPane.doCreateChildControl(ViewPane.java:135)
                at org.eclipse.ui.internal.PartPane.createChildControl(PartPane.java:349)
                at org.eclipse.ui.internal.ViewFactory$1.run(ViewFactory.java:405)
                at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1015)
                at org.eclipse.core.runtime.Platform.run(Platform.java:757)
                at org.eclipse.ui.internal.ViewFactory.busyRestoreView(ViewFactory.java:289)
                at org.eclipse.ui.internal.ViewFactory$2.run(ViewFactory.java:589)
                at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
                at org.eclipse.ui.internal.ViewFactory.restoreView(ViewFactory.java:586)
                at org.eclipse.ui.internal.ViewFactory$ViewReference.getPart(ViewFactory.java:108)
                at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:329)
                at org.eclipse.ui.internal.ViewPane.setVisible(ViewPane.java:607)
                at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:126)
                at org.eclipse.ui.internal.presentations.newapi.PresentablePartFolder.select(PresentablePartFolder.java:266)
                at org.eclipse.ui.internal.presentations.newapi.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
                at org.eclipse.ui.internal.presentations.newapi.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:381)
                at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1051)
                at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1009)
                at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1200)
                at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:521)
                at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:473)
                at org.eclipse.ui.internal.PartSashContainer.createControl(PartSashContainer.java:485)
                at org.eclipse.ui.internal.PerspectiveHelper.activate(PerspectiveHelper.java:230)
                at org.eclipse.ui.internal.Perspective.onActivate(Perspective.java:777)
                at org.eclipse.ui.internal.WorkbenchPage.onActivate(WorkbenchPage.java:2133)
                at org.eclipse.ui.internal.WorkbenchWindow$4.run(WorkbenchWindow.java:2235)
                at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
                at org.eclipse.ui.internal.WorkbenchWindow.setActivePage(WorkbenchWindow.java:2221)
                at org.eclipse.ui.internal.WorkbenchWindow.busyOpenPage(WorkbenchWindow.java:572)
                at org.eclipse.ui.internal.Workbench.busyOpenWorkbenchWindow(Workbench.java:587)
                at org.eclipse.ui.internal.Workbench.openFirstTimeWindow(Workbench.java:1209)
                at org.eclipse.ui.internal.WorkbenchConfigurer.openFirstTimeWindow(WorkbenchConfigurer.java:178)
                at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:717)
                at org.eclipse.ui.internal.Workbench.init(Workbench.java:918)
                at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1554)
                at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:293)
                at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:144)
                at com.amaranth.energy.workbench.rcp.WorkbenchApplication.run(WorkbenchApplication.java:21)
                at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:228)
                at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:333)
                at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:150)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                at java.lang.reflect.Method.invoke(Unknown Source)
                at org.eclipse.core.launcher.Main.invokeFramework(Main.java:268)
                at org.eclipse.core.launcher.Main.basicRun(Main.java:260)
                at org.eclipse.core.launcher.Main.run(Main.java:887)
                at org.eclipse.core.launcher.Main.main(Main.java:871)

                The Thread.currentThread().getContextClassLoader() is an instance of sun.misc.Launcher$AppClassLoader which is just contains the Eclipse launcher's jar (eclipse/startup.jar)

                The class loader that should be associated with classes, and is associated with both the TreeCache and PropertyConfigurator instance, is an instance of org.eclipse.core.runtime.adaptor.EclipseClassLoader that contains the classpath of all of the jars in the bundled application.

                I guess I'll have to dig a bit deeper into Eclipse to determine classloading dependencies during start-up.

                In the meantime, the following code snippet around seems to work around the problem.

                ClassLoader cl = Thread.currentThread().getContextClassLoader();
                Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
                this.tc.startService();
                Thread.currentThread().setContextClassLoader(cl);

                Where this.tc is the TreeCache instance.

                • 5. Re: Using JBossCache within Eclipse
                  Bela Ban Master

                  You forgot to call startService() on the freshly created instance

                  • 6. Re: Using JBossCache within Eclipse
                    Bela Ban Master

                    Oops, should have read the entire thread.
                    So you are saying the CL should be the one with which the TreeCache class is associated, not the current thread ?
                    Hmm, makes sense, I don't know why I took the thread context CL...
                    I'll change this

                    • 7. Re: Using JBossCache within Eclipse
                      Bela Ban Master

                      This is even more stupid, as in some cases we are using the CL of TreeCache, in others the context CL...

                      • 9. Re: Using JBossCache within Eclipse
                        Karl Koster Newbie

                        Bela,

                        Will this change be backported to 1.2 and put out into Sourceforge or will it just be in HEAD on CVS.

                        • 10. Re: Using JBossCache within Eclipse
                          Bela Ban Master

                          - No backport to 1.2
                          - Possibly a backport to 3.2.x and 4.x

                          After 1.2.1, I'm going to extract JBossCache from JBossAS and create its own CVS module. It will be fully standalone, including all necessary unit tests. Therefore it will be much easier to just check out JBossCache from the CVS and build it; you don't need to check out and build all of jboss-head.
                          JBossAS will then simply use jboss-cache.jar as a library, and there will be some integration code in jboss-head providing for example a JMX adapter to the JBossCache POJO.