Skip to content

Commit 6ae79d7

Browse files
kriegaexolamy
authored andcommitted
Report "Error occurred during initialization of VM" as error
Until now, this error message was just swallowed silently. Along the way, also report "Error occurred during initialization of boot layer" as ERROR, because probably OTHER was never the right category to begin with. With OTHER, Maven Compiler logs both error messages on INFO, which I believe to be wrong. Now, Maven Compiler logs them on ERROR with "COMPILATION ERROR" header, which fits the behaviour that the build fails. Besides, javadoc for CompilerMessage.Kind.ERROR says "Problem which prevents the tool's normal completion", which also is a good description of what is actually happening for both the boot layer and VM init errors.
1 parent 9ba766d commit 6ae79d7

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,10 @@ private static CompilerResult compileInProcess0(Class<?> javacClass, String[] ar
638638
private static final Pattern STACK_TRACE_OTHER_LINE =
639639
Pattern.compile("^(?:Caused by:\\s.*|\\s*at .*|\\s*\\.\\.\\.\\s\\d+\\smore)$");
640640

641+
// Match generic javac errors with 'javac:' prefix, JMV init and boot layer init errors
642+
private static final Pattern JAVAC_OR_JVM_ERROR =
643+
Pattern.compile("^(?:javac:|Error occurred during initialization of (?:boot layer|VM)).*", Pattern.DOTALL);
644+
641645
/**
642646
* Parse the output from the compiler into a list of CompilerMessage objects
643647
*
@@ -664,10 +668,8 @@ static List<CompilerMessage> parseModernStream(int exitCode, BufferedReader inpu
664668
// maybe better to ignore only the summary and mark the rest as error
665669
String bufferAsString = buffer.toString();
666670
if (buffer.length() > 0) {
667-
if (bufferAsString.startsWith("javac:")) {
671+
if (JAVAC_OR_JVM_ERROR.matcher(bufferAsString).matches()) {
668672
errors.add(new CompilerMessage(bufferAsString, CompilerMessage.Kind.ERROR));
669-
} else if (bufferAsString.startsWith("Error occurred during initialization of boot layer")) {
670-
errors.add(new CompilerMessage(bufferAsString, CompilerMessage.Kind.OTHER));
671673
} else if (hasPointer) {
672674
// A compiler message remains in buffer at end of parse stream
673675
errors.add(parseModernError(exitCode, bufferAsString));

plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -1010,16 +1010,29 @@ public void testIssue37() throws IOException {
10101010
}
10111011

10121012
@Test
1013-
public void testJvmError() throws Exception {
1013+
public void testJvmBootLayerInitializationError() throws Exception {
10141014
String out = "Error occurred during initialization of boot layer" + EOL
10151015
+ "java.lang.module.FindException: Module java.xml.bind not found";
10161016

10171017
List<CompilerMessage> compilerErrors =
10181018
JavacCompiler.parseModernStream(1, new BufferedReader(new StringReader(out)));
10191019

10201020
assertThat(compilerErrors, notNullValue());
1021+
assertThat(compilerErrors.size(), is(1));
1022+
assertThat(compilerErrors.get(0).getKind(), is(CompilerMessage.Kind.ERROR));
1023+
}
1024+
1025+
@Test
1026+
public void testJvmInitializationError() throws Exception {
1027+
String out = "Error occurred during initialization of VM" + EOL
1028+
+ "Initial heap size set to a larger value than the maximum heap size";
10211029

1030+
List<CompilerMessage> compilerErrors =
1031+
JavacCompiler.parseModernStream(1, new BufferedReader(new StringReader(out)));
1032+
1033+
assertThat(compilerErrors, notNullValue());
10221034
assertThat(compilerErrors.size(), is(1));
1035+
assertThat(compilerErrors.get(0).getKind(), is(CompilerMessage.Kind.ERROR));
10231036
}
10241037

10251038
@Test

0 commit comments

Comments
 (0)