Maven Compilation Error without any errors from the compiler

Short version: javac was encountering a StackOverflowError (irony noted! 😄 ), caused by a 693-deep chained method call on a Builder.

To diagnose: we used Maven's -X output to extract the actual command to javac, then executed that separately. This gave us javac's full output, which does not appear to be available using Maven. The output told us which class it was working on and then spat out the stacktrace for the SOE. I then looked at the history of commits to that file and found that, coincident with the trivial change I committed, someone else had added a few calls to the builder chain.

To verify the diagnosis, we added -J-Xss256M to javac's args and ran it again; compilation succeeded. Rather than run the compiler with nonstandard args (and spending the time figuring out how to get Maven to invoke it that way), I then split the builder chain into two smaller chains. With that change committed, the build is now passing in Bamboo.

Note: in the question, I said that the compiler output contained all 35 expected class files; this was a coincidence. It contained 35 files, which matched up with the number of source files, but thanks to some inner classes, the 35 .java files should have generated 42 .class files.

We're using an old version of maven-compiler-plugin (v3.1, from 2013). I'm going to experiment with whether a newer version does a better job of exposing the failure.


It seems the error of the creator had a different error cause. But since my issue let me here and I had a different cause: Check if you fork the compiler plugin somewhere:

E.g. like this:

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <fork>true</fork> <meminitial>512m</meminitial> <maxmem>2048m</maxmem> <compilerArgs> <arg>-XX:MaxPermSize=256m</arg> </compilerArgs> <source>${java.version}</source> <target>${java.version}</target> </configuration> </plugin>

In this case the outcome can be ugly. It works on some machines where JAVA_HOME is set generally correct and will not where you just set it in a local window. And the error is not helpful at all as the forked compiler will not return helpful info.

Tags:

Java

Maven