Repository navigation
Description
I had a Java class using a builder pattern to put together a lookup table. There was another class which chained together 600+ method calls on a single line on this builder, assembling the table. Understandably, as the number of entries in the lookup table grew, we eventually ran into a StackOverflowError from javac while compiling the class. javac does not handle this gracefully; the SOE stacktrace is written to stderr with no surrounding context clues, and then the compiler exits.
The project is built using Maven, which of course uses plexus-compiler-javac. We run the build in forked mode.
Unfortunately, the Plexus compiler recognizes the forked build as failed, but does not capture the cause. There are no messages on the CompilerResult, and nothing is printed to stdout/stderr. It was therefore quite difficult for me to diagnose the cause of the compilation failure. By enabling verbose mode, I was able to see the compiler's progress, and through process of elimination I identified the problematic class. One look at the class led me to suspect an SOE, which I was able to verify by compiling the class manually at the command line. From there, it was a simple matter of splitting up the line of code into multiple lines.
I have created an MVCE here: https://github.com/jakerobb/plexus-javac-compiler-bug. It's a small Maven project. Just clone it and run mvn test to reproduce the issue.
I think that #39 would have been helpful here, but I also think that some other improvements are called for:
- If compilation fails and there are no messages, add a custom message indicating that there is a likely compiler issue, and then proxy the entire output through, regardless of whether any "debug flag" is set.
- Capture and recognize exception stacktraces on javac's stderr. Treat them similarly to number 1 above, but with a different message.
- If possible, include the name of the problematic file in the output. I know javac isn't returning this, but it seems like it might be possible to determine; I don't want to assume.
Of course, ideally, javac should be fixed to not throw an SOE in this scenario, probably by replacing recursion with iteration, and also to write out the file it was working on when compilation fails. I'm now off to figure out how to report an improvement request in javac....
Activity
urld commentedon Dec 15, 2021
I encountered a similar problem where valuable information from stderr is ignored:
So its not just about potential stackoverflow bugs in javac. There are also error cases where erroneous input data can cause javac to detect actual errors that should be recognized be the plexus-compiler.
Marcono1234 commentedon Mar 5, 2023
Would also be great if in addition to that there was a opt-in setting (which would then also be propagated to the Maven Compiler Plugin) which always prints the complete process output on error, regardless of whether some diagnostics were found in the output or not. That would help in case plexus-compiler only detected some but not all diagnostics in the output.
I would be much happier about overly verbose output on error than compiler output being omitted because it was erroneously deemed unimportant.
For example for the following warnings about missing annotation classes (JDK-6365854), plexus-compiler did not detect any warnings or errors:
Or maybe
org.codehaus.plexus.compiler.javac.JavacCompiler#parseModernStreamshould be changed to not silently ignore unrecognized lines and instead report them as diagnostic ofKind.OTHER? Would affect the followingplexus-compiler/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java
Lines 761 to 762 in 67ecb40
Emit a diagnostic if
bufferis non-empty before reassigning it?plexus-compiler/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java
Lines 773 to 774 in 67ecb40
Emit a diagnostic if
bufferis non-empty and clear / reassignbufferafterwards?plexus-compiler/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java
Lines 751 to 755 in 67ecb40
Add
elseblock and don't silently discardbuffercontent (maybe that is also what the comment in line 739 there means)Or is there output which should be ignored from the compiler?
wilx commentedon Jul 29, 2026
This can now be diagnosed via Maven's
-Xoutput. #296Report javac output that no classifier recognised