Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Different behavior calling the same library from Java main() vs from a JFace part(Calling library worked when from Java main() but had ClassCastException when from JFace part)
Different behavior calling the same library from Java main() vs from a JFace part [message #1142711] Thu, 17 October 2013 20:17 Go to next message
Charles Li is currently offline Charles LiFriend
Messages: 16
Registered: December 2009
Junior Member
I created an Eclipse 4 RCP project with GUI. In one ViewPart I need to call a utility Java library I created (Apache Jena), but I experienced ClassCastException:

Caused by: java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory
at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:121)
at java.util.XMLUtils.getLoadingDoc(XMLUtils.java:92)
at java.util.XMLUtils.load(XMLUtils.java:74)
at java.util.Properties.loadFromXML(Properties.java:868)
at com.hp.hpl.jena.util.Metadata.read(Metadata.java:76)
at com.hp.hpl.jena.util.Metadata.addMetadata(Metadata.java:54)
at com.hp.hpl.jena.util.Metadata.<init>(Metadata.java:48)
at com.hp.hpl.jena.JenaRuntime.<clinit>(JenaRuntime.java:34)
... 81 more

If I create a pure main() Java program in the same Eclipse 4 RCP project and call the same utility Java program, it execute successfully.

In the viewPart, I didn't even import any Apache Jena packages. Apparently the class loading were different in the two cases.

So how should I approach to resolve this ClassCastException?

Thanks a lot!

[Updated on: Thu, 17 October 2013 20:26]

Report message to a moderator

Re: Different behavior calling the same library from Java main() vs from a JFace part [message #1143499 is a reply to message #1142711] Fri, 18 October 2013 08:16 Go to previous messageGo to next message
Eclipse UserFriend
What part of the eclipse framework causes the cast? The stack trace there shows nothing meaningful regarding the role of the eclipse infrastructure.
Re: Different behavior calling the same library from Java main() vs from a JFace part [message #1144023 is a reply to message #1143499] Fri, 18 October 2013 15:40 Go to previous messageGo to next message
Charles Li is currently offline Charles LiFriend
Messages: 16
Registered: December 2009
Junior Member
Sorry, I didn't paste the full stack trace. Here it is. Thanks a lot!

!SESSION 2013-10-18 10:32:55.475 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.7.0_25i
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments: -product my.ui.product -clearPersistedState
Command-line arguments: -product my.ui.product -data C:\workspace/../runtime-my.ui.product -dev file:C:/workspace/.metadata/.plugins/org.eclipse.pde.core/my.ui.product/dev.properties -os win32 -ws win32 -arch x86_64 -consoleLog -clearPersistedState

!ENTRY org.eclipse.equinox.event 4 0 2013-10-18 10:33:05.287
!MESSAGE Exception while dispatching event org.osgi.service.event.Event [topic=VIEWCOMMUNICATION/SELECTED/MODELROOT] to handler org.eclipse.e4.ui.internal.di.UIEventObjectSupplier$UIEventHandler@38b8ea59
!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.ExceptionInInitializerError
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
at org.eclipse.e4.ui.internal.di.UIEventObjectSupplier$UIEventHandler$1.run(UIEventObjectSupplier.java:49)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:180)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4688)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:205)
at org.eclipse.e4.ui.internal.di.UIEventObjectSupplier$UIEventHandler.handleEvent(UIEventObjectSupplier.java:47)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:80)
at my.ui.handlers.OpenHandler.execute(OpenHandler.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:243)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:224)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:167)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:213)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:850)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:743)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:727)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:662)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1057)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4170)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3759)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:138)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:162)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
Caused by: java.lang.ExceptionInInitializerError
at com.hp.hpl.jena.rdf.model.impl.RDFReaderFImpl.<clinit>(RDFReaderFImpl.java:73)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.<clinit>(ModelCom.java:54)
at com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel(ModelFactory.java:140)
at com.hp.hpl.jena.vocabulary.OWL.<clinit>(OWL.java:36)
at com.hp.hpl.jena.sparql.graph.NodeConst.<clinit>(NodeConst.java:43)
at com.hp.hpl.jena.sparql.engine.optimizer.reorder.ReorderFixed.<clinit>(ReorderFixed.java:35)
at com.hp.hpl.jena.sparql.engine.optimizer.reorder.ReorderLib.fixed(ReorderLib.java:67)
at com.hp.hpl.jena.tdb.sys.SystemTDB.<clinit>(SystemTDB.java:192)
at com.hp.hpl.jena.tdb.TDB.<clinit>(TDB.java:90)
at com.hp.hpl.jena.tdb.setup.DatasetBuilderStd.<clinit>(DatasetBuilderStd.java:49)
at com.hp.hpl.jena.tdb.StoreConnection.make(StoreConnection.java:217)
at com.hp.hpl.jena.tdb.transaction.DatasetGraphTransaction.<init>(DatasetGraphTransaction.java:75)
at com.hp.hpl.jena.tdb.sys.TDBMaker._create(TDBMaker.java:57)
at com.hp.hpl.jena.tdb.sys.TDBMaker.createDatasetGraphTransaction(TDBMaker.java:45)
at com.hp.hpl.jena.tdb.TDBFactory._createDatasetGraph(TDBFactory.java:104)
at com.hp.hpl.jena.tdb.TDBFactory.createDatasetGraph(TDBFactory.java:73)
at com.hp.hpl.jena.tdb.TDBFactory.createDataset(TDBFactory.java:52)
at com.hp.hpl.jena.tdb.TDBFactory.createDataset(TDBFactory.java:48)
at my.api.myDAO.init(MyDAO.java:44)
at my.api.myDAO.<init>(MyDAO.java:35)
at my.ui.util.Utils.getMyDAO(Utils.java:104)
at my.ui.util.Utils.getRootRecords(Utils.java:117)
at my.ui.parts.TreeViewPart.eventReceived(TreeViewPart.java:108)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
... 53 more
Caused by: java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory
at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:121)
at java.util.XMLUtils.getLoadingDoc(XMLUtils.java:92)
at java.util.XMLUtils.load(XMLUtils.java:74)
at java.util.Properties.loadFromXML(Properties.java:868)
at com.hp.hpl.jena.util.Metadata.read(Metadata.java:76)
at com.hp.hpl.jena.util.Metadata.addMetadata(Metadata.java:54)
at com.hp.hpl.jena.util.Metadata.<init>(Metadata.java:48)
at com.hp.hpl.jena.JenaRuntime.<clinit>(JenaRuntime.java:34)
... 81 more
Re: Different behavior calling the same library from Java main() vs from a JFace part [message #1144264 is a reply to message #1144023] Fri, 18 October 2013 19:16 Go to previous messageGo to next message
Charles Li is currently offline Charles LiFriend
Messages: 16
Registered: December 2009
Junior Member
Problem not resolved yet, but more findings:

Within the command-line execution and the RCP GUI execution, I used "System.getProperties()" to list all system properties, and I found the following system property was set in the former but not in the latter, although I didn't do anything in either cases.

javax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl

So I am trying to add the above system property to the latter, and I tried the following (each one by itself only) but none was successful (the ClassCastException still showed up):
- Run Configuration > Arguments: add "-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl" to "Program arguments.
- Run Configuration > Arguments: add "-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl" to "VM arguments.
- .product configuration > Configuration tab: add "javax.xml.parsers.DocumentBuilderFactory" and "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl" as name/value under "Properties.


Please help! Thanks!

[Updated on: Fri, 18 October 2013 19:18]

Report message to a moderator

Re: Different behavior calling the same library from Java main() vs from a JFace part [message #1144531 is a reply to message #1144264] Fri, 18 October 2013 23:38 Go to previous messageGo to next message
Charles Li is currently offline Charles LiFriend
Messages: 16
Registered: December 2009
Junior Member
More findings: whenever I call the utility Java library from within a method with dependency injection, the ClassCastException occurs; while the same call from any regular Java class/method without DI, it is successful.

It seems the call to the Java library uses a third-party open-source library, where it parses an XML config file - don't know if this helps with finding out what is wrong.

So my question is - is there anything unique about the Java execution environment with DI? Does it carry the XML parser that comes with the JDK? I am using Java 1.7.

Thanks a lot!
Re: Different behavior calling the same library from Java main() vs from a JFace part [message #1145293 is a reply to message #1144531] Sat, 19 October 2013 12:00 Go to previous messageGo to next message
Eclipse UserFriend
Are the java class imports the same in both the cases?
Re: Different behavior calling the same library from Java main() vs from a JFace part [message #1145299 is a reply to message #1144531] Sat, 19 October 2013 12:03 Go to previous messageGo to next message
Eclipse UserFriend
Charles Li wrote on Sat, 19 October 2013 01:38
More findings: whenever I call the utility Java library from within a method with dependency injection, the ClassCastException occurs; while the same call from any regular Java class/method without DI, it is successful.

It seems the call to the Java library uses a third-party open-source library, where it parses an XML config file - don't know if this helps with finding out what is wrong.

So my question is - is there anything unique about the Java execution environment with DI? Does it carry the XML parser that comes with the JDK? I am using Java 1.7.

Thanks a lot!


In the eclipse 4 case you should have javax.xml in your running config so it may get in your way of doing things.
Re: Different behavior calling the same library from Java main() vs from a JFace part [message #1145935 is a reply to message #1145293] Sat, 19 October 2013 22:13 Go to previous messageGo to next message
Charles Li is currently offline Charles LiFriend
Messages: 16
Registered: December 2009
Junior Member
Yes, Sopot, java class imports the same in both the cases.
Re: Different behavior calling the same library from Java main() vs from a JFace part [message #1145941 is a reply to message #1145299] Sat, 19 October 2013 22:16 Go to previous messageGo to next message
Charles Li is currently offline Charles LiFriend
Messages: 16
Registered: December 2009
Junior Member
So does this mean there is no work-around?
Re: Different behavior calling the same library from Java main() vs from a JFace part [message #1148324 is a reply to message #1145941] Mon, 21 October 2013 12:25 Go to previous message
Eclipse UserFriend
How are you supplying the apache xerces library to your RCP product?
Previous Topic:Running Eclipse 3.x and 4.x plugins together
Next Topic:Does anybody know how to use org.eclipse.ui.editors.text.TextEditor with E4
Goto Forum:
  


Current Time: Thu Apr 18 02:36:28 GMT 2024

Powered by FUDForum. Page generated in 0.02088 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top