Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ConcurrentModificationException w/ jaxb2-basics 0.13.1 #48

Closed
mattrpav opened this issue Jul 27, 2016 · 7 comments
Closed

ConcurrentModificationException w/ jaxb2-basics 0.13.1 #48

mattrpav opened this issue Jul 27, 2016 · 7 comments
Assignees
Labels
need feedback Some more clarifications are needed

Comments

@mattrpav
Copy link

mattrpav commented Jul 27, 2016

While using jaxb-xew-plugin 1.7 and jaxb2-basics 0.13.1 a ConcurrentModificationException is thrown.

Downgrading jaxb-xew-plugin to 1.2 resolves the issue

Link to jaxb2-basics issue: highsource/jaxb2-basics#72

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.806 s
[INFO] Finished at: 2016-07-27T14:07:46-05:00
[INFO] Final Memory: 18M/310M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate (generate) on project aaa.bbb.ccc: Execution generate of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate failed. ConcurrentModificationException -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

Full stacktrace:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate (generate) on project aaa.bbb.ccc: Execution generate of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate failed.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
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.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution generate of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate failed.
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
Caused by: java.util.ConcurrentModificationException
at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:394)
at java.util.LinkedHashMap$ValueIterator.next(LinkedHashMap.java:409)
at org.jvnet.jaxb2_commons.plugin.codegenerator.AbstractCodeGeneratorPlugin.run(AbstractCodeGeneratorPlugin.java:72)
at com.sun.tools.xjc.model.Model.generateCode(Model.java:292)
at org.jvnet.mjiip.v_2_2.XJC22Mojo.generateCode(XJC22Mojo.java:66)
at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:41)
at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:28)
at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute(RawXJC2Mojo.java:505)
at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute(RawXJC2Mojo.java:328)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more

@dmak
Copy link
Owner

dmak commented Jul 27, 2016

It's difficult to say anything, as there is no com.sun.tools.xjc.addon.xew package in the stack trace. May you could create a minimalistic Maven-based project, that demonstrates the problem?

@mattrpav
Copy link
Author

mattrpav commented Jul 27, 2016

Thank you for the quick response =) I did create an issue with jaxb2-basics and linked it to this issue. I agree, the ST looks like it may be a jaxb2-basics issue.

Sample project:
jaxb2-xew-bug.zip

To recreate:

mvn generate-sources

To work around:

Edit pom.xml and set jaxb.xew.plugin = 1.2
mvn generate-sources

@dmak
Copy link
Owner

dmak commented Jul 27, 2016

The wind blows indeed to the direction of Xew plugin: irrespective of version it's activation has side effect on jaxb2_commons. I will have a closer look next week, but it seems like outline.getClasses() collection is modified during processClassOutline() call. Xew indeed removes classes from outline – that is it's purpose at the end of the day.

@dmak
Copy link
Owner

dmak commented Aug 24, 2016

As I supposed, the problem appears only when xew removes classes from outline. Hence it works fine with xew control file /.*/=keep which means don't remove any classes. The problem is rooted in the way how classes are generated by JAXB. In particular there are two levels of classes: (1) the outline and (2) the code model (see more detailed description here). xew actively modifiers (2) and a bit corrects (1), namely, removes not necessary classes. After these modifications model (2) is consistent, but (1) still has classes with field descriptions that refer types that have removed. In your case SampleData has field foos which is still SampleDataList and not List<String>. As the result, when this type on level (1) is dereferenced in FieldUtils.getPossibleTypes():204, it is created again and added to the model (1):

java.util.HashMap<K,V>.put(K, V) line: 508  
com.sun.codemodel.JPackage._class(int, java.lang.String, com.sun.codemodel.ClassType) line: 186 
com.sun.tools.xjc.util.CodeModelClassFactory.createClass(com.sun.codemodel.JClassContainer, int, java.lang.String, org.xml.sax.Locator, com.sun.codemodel.ClassType) line: 110  
com.sun.tools.xjc.util.CodeModelClassFactory.createClass(com.sun.codemodel.JClassContainer, int, java.lang.String, org.xml.sax.Locator) line: 82    
com.sun.tools.xjc.generator.bean.ImplStructureStrategy$1.createClasses(com.sun.tools.xjc.outline.Outline, com.sun.tools.xjc.model.CClassInfo) line: 82  
com.sun.tools.xjc.generator.bean.BeanGenerator.generateClassDef(com.sun.tools.xjc.model.CClassInfo) line: 440   
com.sun.tools.xjc.generator.bean.BeanGenerator.getClazz(com.sun.tools.xjc.model.CClassInfo) line: 472   
com.sun.tools.xjc.generator.bean.BeanGenerator.getClazz(com.sun.tools.xjc.model.CClassInfo) line: 125   
com.sun.tools.xjc.model.CClassInfo.toType(com.sun.tools.xjc.outline.Outline, com.sun.tools.xjc.model.Aspect) line: 502  
com.sun.tools.xjc.model.CClassInfo.toType(com.sun.tools.xjc.outline.Outline, com.sun.tools.xjc.model.Aspect) line: 81   
org.jvnet.jaxb2_commons.util.FieldUtils.getPossibleTypes(com.sun.tools.xjc.outline.Outline, com.sun.tools.xjc.model.Aspect, com.sun.tools.xjc.model.CTypeInfo) line: 204    
org.jvnet.jaxb2_commons.util.FieldUtils.getPossibleTypes(com.sun.tools.xjc.outline.FieldOutline, com.sun.tools.xjc.model.Aspect) line: 193  
org.jvnet.jaxb2_commons.plugin.simpleequals.SimpleEqualsPlugin.generate(com.sun.tools.xjc.outline.ClassOutline, com.sun.codemodel.JDefinedClass) line: 111  
org.jvnet.jaxb2_commons.plugin.simpleequals.SimpleEqualsPlugin(org.jvnet.jaxb2_commons.plugin.codegenerator.AbstractCodeGeneratorPlugin<A>).processClassOutline(com.sun.tools.xjc.outline.ClassOutline) line: 82    
org.jvnet.jaxb2_commons.plugin.simpleequals.SimpleEqualsPlugin(org.jvnet.jaxb2_commons.plugin.codegenerator.AbstractCodeGeneratorPlugin<A>).run(com.sun.tools.xjc.outline.Outline, com.sun.tools.xjc.Options, org.xml.sax.ErrorHandler) line: 74    
com.sun.tools.xjc.model.Model.generateCode(com.sun.tools.xjc.Options, com.sun.tools.xjc.ErrorReceiver) line: 292    

Only two plugins are conflicting: -XsimpleEquals and -XsimpleHashCode. If you remove those, everything works fine. Another observation is that -Xequals and -XhashCode from jaxb2-basics:0.9.1 work just fine (see here). Maybe you could try to build your solution based on that version?

What are my thoughts about that:

  1. Further improving xew that also keeps model (1) correct is time consuming. And that is also half of the problem, because from my experience the generated models are not suited for further modification/adaptation after they have been generated (see list of request for extensions at the end of this section), so that will possibly require hacking with reflection.
  2. After reading the code of SimpleEqualsPlugin I cannot explain to myself why such simple thing as generating equals() method is so virtuously implemented. Maybe I don't see the corner cases, but perhaps possibleTypes are not needed at all. I wonder what jaxb2-basics team thinks about that.

At the moment I don't see feasible and elegant solution to the problem, so I leave it opened… patches are welcomed.

@dmak
Copy link
Owner

dmak commented Aug 26, 2016

I have come to very ugly solution of the problem, the fix is available in jaxb-xew-plugin-1.8-SNAPSHOT.jar. Please test and let me know it it worked for you.

@dmak dmak self-assigned this Sep 1, 2016
@dmak dmak added the need feedback Some more clarifications are needed label Sep 5, 2016
@dmak dmak closed this as completed in 67be087 Oct 3, 2016
@mattrpav
Copy link
Author

mattrpav commented Oct 3, 2016

Thanks! I'm hoping to test it out this week and will look forward to the 1.8 release.

@mattrpav
Copy link
Author

mattrpav commented Jan 20, 2020

Works as off xew v1.11 (and possibly earlier)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
need feedback Some more clarifications are needed
Projects
None yet
Development

No branches or pull requests

2 participants