Issue Details (XML | Word | Printable)

Key: JAXB-991
Type: Improvement Improvement
Status: Open Open
Priority: Minor Minor
Assignee: Iaroslav Savytskyi
Reporter: hdelfs
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
jaxb

Handle loading errors of XJC plugins gracefully to ignore dependencies from unnecessary plugins

Created: 29/Nov/13 12:13 PM   Updated: 29/Nov/13 12:13 PM
Component/s: xjc
Affects Version/s: 2.2.7
Fix Version/s: None

Time Tracking:
Not Specified

Tags:
Participants: hdelfs and Iaroslav Savytskyi


 Description  « Hide

When loading additional XJC plugins with the service discovery mechanism, java.util.ServiceLoader throws a ServiceConfigurationError (introduced in Java 6) if a plugin class cannot be loaded or instantiated. I suggest to output a warning in this case and continue the discovery process with further plugins.

Also consider the remark from the ServerceLoader's iterator() Javadoc description:

To write robust code it is only necessary to catch ServiceConfigurationError when using a service iterator.

In my case I wanted to use the ToString plugin from JAXB2 Basics, which is bundled with other plugins. Of these namely the Inheritance plugin requires the JavParser library as dependency. Currently I have to include the library in my classpath (though I don't use it) just to avoid the following Error:

java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin: Provider 
org.jvnet.jaxb2_commons.plugin.inheritance.InheritancePlugin could not be instantiated: 
java.lang.NoClassDefFoundError: japa/parser/ParseException
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:116)
	at org.apache.tools.ant.Task.perform(Task.java:348)
	at org.apache.tools.ant.Target.execute(Target.java:390)
	at org.apache.tools.ant.Target.performTasks(Target.java:411)
	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
	at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
	at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
	at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
	at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:423)
	at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:137)
Caused by: java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin: Provider 
org.jvnet.jaxb2_commons.plugin.inheritance.InheritancePlugin could not be instantiated: 
java.lang.NoClassDefFoundError: japa/parser/ParseException
	at java.util.ServiceLoader.fail(ServiceLoader.java:207)
	at java.util.ServiceLoader.access$100(ServiceLoader.java:164)
	at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:353)
	at java.util.ServiceLoader$1.next(ServiceLoader.java:421)
	at com.sun.tools.xjc.Options.findServices(Options.java:957)
	at com.sun.tools.xjc.Options.getAllPlugins(Options.java:374)
	at com.sun.tools.xjc.Options.parseArgument(Options.java:688)
	at com.sun.tools.xjc.Options.parseArguments(Options.java:809)
	at com.sun.tools.xjc.XJC2Task._doXJC(XJC2Task.java:474)
	at com.sun.tools.xjc.XJC2Task.doXJC(XJC2Task.java:457)
	at com.sun.tools.xjc.XJC2Task.execute(XJC2Task.java:380)
	at com.sun.istack.tools.ProtectedTask.execute(ProtectedTask.java:103)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
	... 10 more
Caused by: java.lang.NoClassDefFoundError: japa/parser/ParseException
	at org.jvnet.jaxb2_commons.plugin.inheritance.InheritancePlugin.<init>(InheritancePlugin.java:219)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at java.lang.Class.newInstance0(Class.java:355)
	at java.lang.Class.newInstance(Class.java:308)
	at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:345)
	... 25 more
Caused by: java.lang.ClassNotFoundException: japa.parser.ParseException
	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
	... 33 more


There are no comments yet on this issue.