Skip to content

Commit

Permalink
Recognise javac.msg.io error header
Browse files Browse the repository at this point in the history
"An input/output error occurred.
Consult the following stack trace for details."
  • Loading branch information
kriegaex committed Dec 26, 2023
1 parent 2a1fb0f commit ef87d75
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ protected static class Messages {
"\n\n系统资源不足。\n有关详细信息, 请参阅以下堆栈跟踪。\n",
"\n\nDas System hat keine Ressourcen mehr.\nDetails finden Sie im folgenden Stacktrace.\n"
};

// javac.properties-> javac.msg.io
// (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[] IO_ERROR_HEADERS = {
"\n\nAn input/output error occurred.\nConsult the following stack trace for details.\n",
"\n\n入出力エラーが発生しました。\n詳細は次のスタック・トレースで調査してください。\n",
"\n\n发生输入/输出错误。\n有关详细信息, 请参阅以下堆栈跟踪。\n",
"\n\nAn input/output error occurred.\nConsult the following stack trace for details.\n",
"\n\n入出力エラーが発生しました。\n詳細は次のスタックトレースで調査してください。\n",
"\n\n发生输入/输出错误。\n有关详细信息, 请参阅以下堆栈跟踪。\n",
"\n\nEin Eingabe-/Ausgabefehler ist aufgetreten.\nDetails finden Sie im folgenden Stacktrace.\n"
};

}

private static final Object LOCK = new Object();
Expand Down Expand Up @@ -768,7 +781,8 @@ static List<CompilerMessage> parseModernStream(int exitCode, BufferedReader inpu
|| (cleanedUpMessage = getVMInitError(bufferContent)) != null
|| (cleanedUpMessage = getFileABugError(bufferContent)) != null
|| (cleanedUpMessage = getAnnotationProcessingError(bufferContent)) != null
|| (cleanedUpMessage = getSystemOutOfResourcesError(bufferContent)) != null) {
|| (cleanedUpMessage = getSystemOutOfResourcesError(bufferContent)) != null
|| (cleanedUpMessage = getIOError(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 @@ -833,6 +847,10 @@ private static String getSystemOutOfResourcesError(String message) {
return getTextStartingWithPrefix(message, SYSTEM_OUT_OF_RESOURCES_ERROR_HEADERS);
}

private static String getIOError(String message) {
return getTextStartingWithPrefix(message, IO_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 @@ -811,7 +811,8 @@ private static Stream<Arguments> testStackTraceWithUnknownHeader_args() {
ANNOTATION_PROCESSING_ERROR_HEADERS[0].replaceAll("uncaught", "undandled")),
Arguments.of(
"modified out of resources error header",
SYSTEM_OUT_OF_RESOURCES_ERROR_HEADERS[0].replaceAll("resources", "memory")));
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")));
}

@ParameterizedTest(name = "{0}")
Expand Down Expand Up @@ -929,6 +930,53 @@ private static Stream<Arguments> testSystemOutOfResourcesError_args() {
Arguments.of("JDK 21 German", SYSTEM_OUT_OF_RESOURCES_ERROR_HEADERS[6]));
}

@ParameterizedTest(name = "{0}")
@MethodSource("testIOError_args")
public void testIOError(String jdkAndLocale, String stackTraceHeader) throws Exception {
String stackTraceWithHeader = UNIDENTIFIED_LOG_LINES + stackTraceHeader + stackTraceIOError;

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(stackTraceIOError));
}

private static final String stackTraceIOError =
"An input/output error occurred.\n" + "Consult the following stack trace for details.\n"
+ "java.nio.charset.MalformedInputException: Input length = 1\n"
+ "\tat java.base/java.nio.charset.CoderResult.throwException(CoderResult.java:274)\n"
+ "\tat java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339)\n"
+ "\tat java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)\n"
+ "\tat java.base/java.io.InputStreamReader.read(InputStreamReader.java:185)\n"
+ "\tat java.base/java.io.BufferedReader.fill(BufferedReader.java:161)\n"
+ "\tat java.base/java.io.BufferedReader.read(BufferedReader.java:182)\n"
+ "\tat jdk.compiler/com.sun.tools.javac.main.CommandLine$Tokenizer.<init>(CommandLine.java:143)\n"
+ "\tat jdk.compiler/com.sun.tools.javac.main.CommandLine.loadCmdFile(CommandLine.java:129)\n"
+ "\tat jdk.compiler/com.sun.tools.javac.main.CommandLine.appendParsedCommandArgs(CommandLine.java:71)\n"
+ "\tat jdk.compiler/com.sun.tools.javac.main.CommandLine.parse(CommandLine.java:102)\n"
+ "\tat jdk.compiler/com.sun.tools.javac.main.CommandLine.parse(CommandLine.java:123)\n"
+ "\tat jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:215)\n"
+ "\tat jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)\n"
+ "\tat jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)\n"
+ "\tat jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)\n";

private static Stream<Arguments> testIOError_args() {
return Stream.of(
Arguments.of("JDK 8 English", IO_ERROR_HEADERS[0]),
Arguments.of("JDK 8 Japanese", IO_ERROR_HEADERS[1]),
Arguments.of("JDK 8 Chinese", IO_ERROR_HEADERS[2]),
Arguments.of("JDK 21 English", IO_ERROR_HEADERS[3]),
Arguments.of("JDK 21 Japanese", IO_ERROR_HEADERS[4]),
Arguments.of("JDK 21 Chinese", IO_ERROR_HEADERS[5]),
Arguments.of("JDK 21 German", IO_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 ef87d75

Please sign in to comment.