Skip to content

Commit

Permalink
Recognise javac.msg.plugin.uncaught.exception error header
Browse files Browse the repository at this point in the history
"A plugin threw an uncaught exception.
Consult the following stack trace for details."
  • Loading branch information
kriegaex committed Dec 26, 2023
1 parent d684c56 commit 518fc05
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@ protected static class Messages {
"\n\nEin Eingabe-/Ausgabefehler ist aufgetreten.\nDetails finden Sie im folgenden Stacktrace.\n"
};

// javac.properties-> javac.msg.plugin.uncaught.exception
// (en JDK-8, ja JDK-8, zh_CN JDK-8, en JDK-21, ja JDK-21, zh_CN JDK-21, de JDK-21)
protected static final String[] PLUGIN_ERROR_HEADERS = {
"\n\nA plugin threw an uncaught exception.\nConsult the following stack trace for details.\n",
"\n\nプラグインで捕捉されない例外がスローされました。\n詳細は次のスタック・トレースで調査してください。\n",
"\n\n插件抛出未捕获的异常错误。\n有关详细信息, 请参阅以下堆栈跟踪。\n",
"\n\nA plugin threw an uncaught exception.\nConsult the following stack trace for details.\n",
"\n\nプラグインで捕捉されない例外がスローされました。\n詳細は次のスタック・トレースで調査してください。\n",
"\n\n插件抛出未捕获的异常错误。\n有关详细信息, 请参阅以下堆栈跟踪。\n",
"\n\nEin Plug-in hat eine nicht abgefangene Ausnahme ausgel\u00F6st.\nDetails finden Sie im folgenden Stacktrace.\n"
};
}

private static final Object LOCK = new Object();
Expand Down Expand Up @@ -782,7 +793,8 @@ static List<CompilerMessage> parseModernStream(int exitCode, BufferedReader inpu
|| (cleanedUpMessage = getFileABugError(bufferContent)) != null
|| (cleanedUpMessage = getAnnotationProcessingError(bufferContent)) != null
|| (cleanedUpMessage = getSystemOutOfResourcesError(bufferContent)) != null
|| (cleanedUpMessage = getIOError(bufferContent)) != null) {
|| (cleanedUpMessage = getIOError(bufferContent)) != null
|| (cleanedUpMessage = getPluginError(bufferContent)) != null) {
errors.add(new CompilerMessage(cleanedUpMessage, ERROR));
} else if (hasPointer) {
// A compiler message remains in buffer at end of parse stream
Expand Down Expand Up @@ -851,6 +863,10 @@ private static String getIOError(String message) {
return getTextStartingWithPrefix(message, IO_ERROR_HEADERS);
}

private static String getPluginError(String message) {
return getTextStartingWithPrefix(message, PLUGIN_ERROR_HEADERS);
}

private static boolean startsWithPrefix(String text, String[] prefixes) {
for (String prefix : prefixes) {
if (text.startsWith(prefix)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,9 @@ private static Stream<Arguments> testStackTraceWithUnknownHeader_args() {
Arguments.of(
"modified out of resources error header",
SYSTEM_OUT_OF_RESOURCES_ERROR_HEADERS[0].replaceAll("resources", "memory")),
Arguments.of("modified I/O error header", IO_ERROR_HEADERS[0].replaceAll("input/output", "I/O")));
Arguments.of("modified I/O error header", IO_ERROR_HEADERS[0].replaceAll("input/output", "I/O")),
Arguments.of(
"modified plugin error header", PLUGIN_ERROR_HEADERS[0].replaceAll("uncaught", "unhandled")));
}

@ParameterizedTest(name = "{0}")
Expand Down Expand Up @@ -977,6 +979,46 @@ private static Stream<Arguments> testIOError_args() {
Arguments.of("JDK 21 German", IO_ERROR_HEADERS[6]));
}

@ParameterizedTest(name = "{0}")
@MethodSource("testPluginError_args")
public void testPluginError(String jdkAndLocale, String stackTraceHeader) throws Exception {
String stackTraceWithHeader = UNIDENTIFIED_LOG_LINES + stackTraceHeader + stackTracePluginError;

List<CompilerMessage> compilerMessages =
JavacCompiler.parseModernStream(4, new BufferedReader(new StringReader(stackTraceWithHeader)));

assertThat(compilerMessages, notNullValue());
assertThat(compilerMessages, hasSize(1));

String message = compilerMessages.get(0).getMessage().replaceAll(EOL, "\n");
// Parser retains stack trace header
assertThat(message, startsWith(stackTraceHeader));
assertThat(message, endsWith(stackTracePluginError));
}

private static final String stackTracePluginError =
"A plugin threw an uncaught exception.\n" + "Consult the following stack trace for details.\n"
+ "java.lang.NoSuchMethodError: com.sun.tools.javac.util.JavacMessages.add(Lcom/sun/tools/javac/util/JavacMessages$ResourceBundleHelper;)V\n"
+ "\tat com.google.errorprone.BaseErrorProneJavaCompiler.setupMessageBundle(BaseErrorProneJavaCompiler.java:202)\n"
+ "\tat com.google.errorprone.ErrorProneJavacPlugin.init(ErrorProneJavacPlugin.java:40)\n"
+ "\tat com.sun.tools.javac.main.Main.compile(Main.java:470)\n"
+ "\tat com.sun.tools.javac.main.Main.compile(Main.java:381)\n"
+ "\tat com.sun.tools.javac.main.Main.compile(Main.java:370)\n"
+ "\tat com.sun.tools.javac.main.Main.compile(Main.java:361)\n"
+ "\tat com.sun.tools.javac.Main.compile(Main.java:56)\n"
+ "\tat com.sun.tools.javac.Main.main(Main.java:42)\n";

private static Stream<Arguments> testPluginError_args() {
return Stream.of(
Arguments.of("JDK 8 English", PLUGIN_ERROR_HEADERS[0]),
Arguments.of("JDK 8 Japanese", PLUGIN_ERROR_HEADERS[1]),
Arguments.of("JDK 8 Chinese", PLUGIN_ERROR_HEADERS[2]),
Arguments.of("JDK 21 English", PLUGIN_ERROR_HEADERS[3]),
Arguments.of("JDK 21 Japanese", PLUGIN_ERROR_HEADERS[4]),
Arguments.of("JDK 21 Chinese", PLUGIN_ERROR_HEADERS[5]),
Arguments.of("JDK 21 German", PLUGIN_ERROR_HEADERS[6]));
}

@Test
public void testNonAnchoredWarning() throws IOException {
final String error = "warning: [options] bootstrap class path not set in conjunction with -source 1.6" + EOL
Expand Down

0 comments on commit 518fc05

Please sign in to comment.