From a74853cedd5569971f5e9ed5f7c7b93d31365f01 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Fri, 22 Dec 2023 12:48:18 +0700 Subject: [PATCH] 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. --- .../plexus/compiler/javac/JavacCompiler.java | 8 +++++--- .../compiler/javac/ErrorMessageParserTest.java | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java index 1e97f8e7..0255c2a7 100644 --- a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java +++ b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java @@ -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 * @@ -664,10 +668,8 @@ static List 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)); diff --git a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java index d8f01590..5ab3c822 100644 --- a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java +++ b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java @@ -1010,7 +1010,7 @@ 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"; @@ -1018,8 +1018,21 @@ public void testJvmError() throws Exception { 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 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