Skip to content

Commit

Permalink
Report "Error occurred during initialization of VM" as error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kriegaex authored and olamy committed Dec 25, 2023
1 parent 9ba766d commit a74853c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,10 @@ private static CompilerResult compileInProcess0(Class<?> javacClass, String[] ar
private static final Pattern STACK_TRACE_OTHER_LINE =
Pattern.compile("^(?:Caused by:\\s.*|\\s*at .*|\\s*\\.\\.\\.\\s\\d+\\smore)$");

// Match generic javac errors with 'javac:' prefix, JMV init and boot layer init errors
private static final Pattern JAVAC_OR_JVM_ERROR =
Pattern.compile("^(?:javac:|Error occurred during initialization of (?:boot layer|VM)).*", Pattern.DOTALL);

/**
* Parse the output from the compiler into a list of CompilerMessage objects
*
Expand All @@ -664,10 +668,8 @@ static List<CompilerMessage> parseModernStream(int exitCode, BufferedReader inpu
// maybe better to ignore only the summary and mark the rest as error
String bufferAsString = buffer.toString();
if (buffer.length() > 0) {
if (bufferAsString.startsWith("javac:")) {
if (JAVAC_OR_JVM_ERROR.matcher(bufferAsString).matches()) {
errors.add(new CompilerMessage(bufferAsString, CompilerMessage.Kind.ERROR));
} else if (bufferAsString.startsWith("Error occurred during initialization of boot layer")) {
errors.add(new CompilerMessage(bufferAsString, CompilerMessage.Kind.OTHER));
} else if (hasPointer) {
// A compiler message remains in buffer at end of parse stream
errors.add(parseModernError(exitCode, bufferAsString));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1010,16 +1010,29 @@ public void testIssue37() throws IOException {
}

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

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

assertThat(compilerErrors, notNullValue());
assertThat(compilerErrors.size(), is(1));
assertThat(compilerErrors.get(0).getKind(), is(CompilerMessage.Kind.ERROR));
}

@Test
public void testJvmInitializationError() throws Exception {
String out = "Error occurred during initialization of VM" + EOL
+ "Initial heap size set to a larger value than the maximum heap size";

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

assertThat(compilerErrors, notNullValue());
assertThat(compilerErrors.size(), is(1));
assertThat(compilerErrors.get(0).getKind(), is(CompilerMessage.Kind.ERROR));
}

@Test
Expand Down

0 comments on commit a74853c

Please sign in to comment.