Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Spotless XML formatting failing with parallel build #828

Closed
aaime opened this issue Apr 5, 2021 · 7 comments
Closed

Spotless XML formatting failing with parallel build #828

aaime opened this issue Apr 5, 2021 · 7 comments
Assignees

Comments

@aaime
Copy link

aaime commented Apr 5, 2021

Using Maven 3.6.3, Spotless maven plugin 2.9.0, Eclipse WTP 4.7.3a.

I'm trying out the Spotless/WTP combo for format XML files in the GeoServer project, it's failing with parallel builds with error messages like this one (due to parallel build, some other message is in the mix, sorry about it):

mar 20, 2021 5:31:46 PM com.diffplug.spotless.FormatExceptionPolicyLegacy error
GRAVE: Step 'eclipse wtp formatters - XML' found problem in 'src/main/java/applicationContext.xml':
null
[ava.lang.reflect.InvocationTargetException
34mINFO] Installing /home	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
/aaime/devel/git-gs-cle	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
an/src/ows/target/gs-ows-	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
2.20-SNAPSHOT.jar	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
 to /home/aaime/.m2/reposi	at com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.applyWithFile(EclipseWtpFormatterStep.java:75)
tory/org/geoserver/gs-ows/2	at com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.lambda$createBuilder$0(EclipseWtpFormatterStep.java:51)
.20-SNAPSHOT/gs-ows-2.	at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:76)
20-SNAPSHOT.jar
	at com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:76)
	at com.diffplug.spotless.Formatter.compute(Formatter.java:230)
	at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:201)
	at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:188)
	at com.diffplug.spotless.maven.SpotlessApplyMojo.process(SpotlessApplyMojo.java:45)
	at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute(AbstractSpotlessMojo.java:146)
	at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute(AbstractSpotlessMojo.java:137)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
	at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:190)
	at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:186)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
[Caused by: java.lang.NullPointerException
	at com.diffplug.spotless.extra.eclipse.wtp.EclipseXmlFormatterStepImpl.<init>(EclipseXmlFormatterStepImpl.java:62)
I	... 27 more
N
FO] Installing /home/aaime/devel/git-gs-clean/src/ows/pom.xml to /home/aaime/.m2/repository/org/geoserver/gs-ows/2.20-SNAPSHOT/gs-ows-2.20-SNAPSHOTmar 20, 2021 5:31:46 PM com.diffplug.spotless.FormatExceptionPolicyLegacy error
.poGRAVE: Step 'eclipse wtp formatters - XML' found problem in 'src/main/resources/applicationContext.xml':
null
mjava.lang.reflect.InvocationTargetException

	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.applyWithFile(EclipseWtpFormatterStep.java:75)
	at com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.lambda$createBuilder$0(EclipseWtpFormatterStep.java:51)
	at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:76)
	at com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:76)
	at com.diffplug.spotless.Formatter.compute(Formatter.java:230)
	at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:201)
	at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:188)
	at com.diffplug.spotless.maven.SpotlessApplyMojo.process(SpotlessApplyMojo.java:45)
	at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute(AbstractSpotlessMojo.java:146)
	at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute(AbstractSpotlessMojo.java:137)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
	at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:190)
	at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:186)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
	at com.diffplug.spotless.extra.eclipse.wtp.EclipseXmlFormatterStepImpl.<init>(EclipseXmlFormatterStepImpl.java:62)
	... 27 more

A testable branch with full configuration is here:
https://github.com/aaime/geoserver/tree/spotless-wtp

Runining the pluging directly won't work, as the "initialize" phase does not seem to be invoked, we use it to set a property
containing the location of the config files (including spotless one). I don't have the same problem with other plugins, such as PMD, checkstyle and the like, not sure what's different about spotless.

Forcing maven to run the process-sources phase seems to do the trick, it goes through initialize first, and then :

mvn process-sources -nsu -T6 -fae -Prelease,communityRelease

The extra profiles bring into the build all optional modules, totalling 200+ Maven modules, on my machine it won't fail with less than that. The -T6 makes maven use 6 out of the 8 available cores (Ryzen 1700+, 8 actual phisical cores). Found it fails with -T4 though.

@fvgh
Copy link
Member

fvgh commented Apr 5, 2021

@aaime Sorry, for causing the effort of opening a new PR. Since you addressed this directly in #492, I thought you are aware that the patch was applied with Eclipse WTP 4.13.0.
That's why I wrote in my previous comment on this issue, that I am so surprised about the code line in the backtrace (since it should not be possible to raise a NullPointerException there).

It is of course possible to provide back-ports for this fix. But since Eclipse WTP 4.7.3a the interfaces changed quite a bit. So I really need a good reason to spend the effort. What's the benefit of 4.7.3a over 4.13.0?

@fvgh fvgh self-assigned this Apr 5, 2021
@nedtwigg
Copy link
Member

nedtwigg commented Apr 5, 2021

On the issue of backport, Java 11 is required from 4.17.0 onward. Maintenance of old versions is going to get harder and harder as Java 11 uptake grows. I'd heavily recommend updating to latest Eclipse WTP.

@aaime
Copy link
Author

aaime commented Apr 6, 2021

@fvgh I simply copied it from the documentation:
https://github.com/diffplug/spotless/tree/main/plugin-maven#eclipse-web-tools-platform

No particular WTP version is required for us, the project is IDE agnostic. But needs to work with both Java 8 and Java 11 (the two versions of Java supported by GeoTools and GeoServer).

Tried with 4.16.0, seems to work fine.

Do you have any feeback about running the plugin directly? I can open a seprate ticket for that:

Runining the pluging directly won't work, as the "initialize" phase does not seem to be invoked, we use it to set a property
containing the location of the config files (including spotless one). I don't have the same problem with other plugins, such as PMD, checkstyle and the like, not sure what's different about spotless.

Other formatters I've been playing with (e.g., the revelc one) also do not seems to be affected by the above (but each have issues of their own).

@fvgh
Copy link
Member

fvgh commented Apr 7, 2021

@aaime , I will updated the documentation.

About the direct plugin call:
Sorry, but this is really a separate issue.
By your current description I am guessing that you are referring to the apply mojo and not the check mojo.
Could you clarify this in the new issue?
The apply mojo has currently no phase assigned. I think it should, together with the requiresDirectInvocation flag. But I am no Maven expert.

@fvgh fvgh added the duplicate label Apr 7, 2021
@fvgh
Copy link
Member

fvgh commented Apr 7, 2021

Issue basically a duplicate of #492.
Eclipse WTP version in ReadMe updated in 00ba710, referring to version in which #492 is fixed.
About Java 11: Only Eclipse CDT requires Java 11 from 4.17.0 onward. Rest works fine with Java 8.

@fvgh fvgh closed this as completed Apr 7, 2021
@aaime
Copy link
Author

aaime commented Feb 19, 2022

@fvgh I've tried again today, with Spotless 2.20, still getting the NPE. I guess it was not a duplicate after all?
Or maybe it just regressed again?

INFO] Building Chart external graphics support 2.21-SNAPSHOT  feb 19, 2022 10:35:25 AM com.diffplug.spotless.FormatExceptionPolicyLegacy error
 GRAVE: Step 'eclipse wtp formatter - XML' found problem in 'src/main/resources/applicationContext.xml':
 null
      java.lang.reflect.InvocationTargetException
[34/	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
212]	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[	at com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.applyWithFile(EclipseWtpFormatterStep.java:79)
	t com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.lambda$createBuilder$0(EclipseWtpFormatterStep.java:53)
mINF	at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:76)
O	t com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:88)
	at com.diffplug.spotless.Formatter.compute(Formatter.java:230)
	at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:203)
m] 	t com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:190)
[1m--	at com.diffplug.spotless.maven.SpotlessApplyMojo.process(SpotlessApplyMojo.java:45)
----	at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute(AbstractSpotlessMojo.java:191)
----	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
-----	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
------	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
----	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
-----	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
--[ po	at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:190)
m ]-----	at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:186)
----	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
---	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
---	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
-----	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
-----	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
--	at java.lang.Thread.run(Thread.java:748)
---Caused by: java.lang.NullPointerException
---
	at com.diffplug.spotless.extra.eclipse.wtp.EclipseXmlFormatterStepImpl.<init>(EclipseXmlFormatterStepImpl.java:62)

Ah, here is how I'm invoking Spotless (forcing the initialize phase so that a property with the location of a config file for WTP can be set up):

mvn initialize spotless:apply -T6 -nsu -fae -Prelease,communityRelease

@aaime
Copy link
Author

aaime commented Feb 19, 2022

Never mind, forgot to upgrade the WTP version, sorry for the noise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants