-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Instead of two separate 'while' loops, one inline and one in an extra method, parsing stack traces after finding error messages specific to the English locale of the JDK, now there is generic stack trace parsing, which works in these two cases independent of locale and also in others previously not covered. For backward compatibility, the Javac localized message 'javac.msg.bug' ("An exception has occurred in the compiler ... Please file a bug") is salvaged in a locale-independent way, matching on error reporting URLs always occurring in all JDK locales (English, Japanese, Chinese, German as of JDK 21). Fixes #336
- Loading branch information
Showing
4 changed files
with
188 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,20 +28,25 @@ | |
import java.io.StringReader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import org.codehaus.plexus.compiler.CompilerMessage; | ||
import org.codehaus.plexus.util.Os; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import static org.hamcrest.CoreMatchers.endsWith; | ||
import static org.hamcrest.CoreMatchers.startsWith; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
import static org.hamcrest.core.StringEndsWith.endsWith; | ||
import static org.hamcrest.core.StringStartsWith.startsWith; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Trygve Laugstøl</a> | ||
* @author Alexander Kriegisch | ||
*/ | ||
public class ErrorMessageParserTest { | ||
private static final String EOL = System.getProperty("line.separator"); | ||
|
@@ -775,19 +780,79 @@ public void testJava7Error() throws Exception { | |
assertThat(message2.getEndLine(), is(3)); | ||
} | ||
|
||
@Test | ||
public void testBugParade() throws Exception { | ||
String out = "An exception has occurred in the compiler (1.7.0_80). " | ||
+ "Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. " | ||
+ "Include your program and the following diagnostic in your report. Thank you." + EOL | ||
+ "com.sun.tools.javac.code.Symbol$CompletionFailure: class file for java.util.Optional not found"; | ||
@ParameterizedTest(name = "{0}") | ||
@MethodSource("testBugParade_args") | ||
public void testBugParade(String jdkAndLocale, String stackTraceHeader) throws Exception { | ||
String stackTraceWithHeader = stackTraceHeader + stackTraceInternalCompilerError; | ||
|
||
List<CompilerMessage> compilerErrors = | ||
JavacCompiler.parseModernStream(4, new BufferedReader(new StringReader(out))); | ||
List<CompilerMessage> compilerMessages = | ||
JavacCompiler.parseModernStream(4, new BufferedReader(new StringReader(stackTraceWithHeader))); | ||
|
||
assertThat(compilerErrors, notNullValue()); | ||
assertThat(compilerMessages, notNullValue()); | ||
assertThat(compilerMessages, hasSize(1)); | ||
|
||
assertThat(compilerErrors.size(), is(1)); | ||
String message = compilerMessages.get(0).getMessage().replaceAll(EOL, "\n"); | ||
// Parser retains stack trace header | ||
assertThat(message, startsWith(stackTraceHeader)); | ||
assertThat(message, endsWith(stackTraceInternalCompilerError)); | ||
} | ||
|
||
private static final String stackTraceInternalCompilerError = | ||
"\tat com.sun.tools.javac.comp.MemberEnter.baseEnv(MemberEnter.java:1388)\n" | ||
+ "\tat com.sun.tools.javac.comp.MemberEnter.complete(MemberEnter.java:1046)\n" | ||
+ "\tat com.sun.tools.javac.code.Symbol.complete(Symbol.java:574)\n" | ||
+ "\tat com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1037)\n" | ||
+ "\tat com.sun.tools.javac.code.Symbol$ClassSymbol.flags(Symbol.java:973)\n" | ||
+ "\tat com.sun.tools.javac.code.Symbol$ClassSymbol.getKind(Symbol.java:1101)\n" | ||
+ "\tat com.sun.tools.javac.code.Kinds.kindName(Kinds.java:162)\n" | ||
+ "\tat com.sun.tools.javac.comp.Check.duplicateError(Check.java:329)\n" | ||
+ "\tat com.sun.tools.javac.comp.Check.checkUnique(Check.java:3435)\n" | ||
+ "\tat com.sun.tools.javac.comp.Enter.visitTypeParameter(Enter.java:454)\n" | ||
+ "\tat com.sun.tools.javac.tree.JCTree$JCTypeParameter.accept(JCTree.java:2224)\n" | ||
+ "\tat com.sun.tools.javac.comp.Enter.classEnter(Enter.java:258)\n" | ||
+ "\tat com.sun.tools.javac.comp.Enter.classEnter(Enter.java:272)\n" | ||
+ "\tat com.sun.tools.javac.comp.Enter.visitClassDef(Enter.java:418)\n" | ||
+ "\tat com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:693)\n" | ||
+ "\tat com.sun.tools.javac.comp.Enter.classEnter(Enter.java:258)\n" | ||
+ "\tat com.sun.tools.javac.comp.Enter.classEnter(Enter.java:272)\n" | ||
+ "\tat com.sun.tools.javac.comp.Enter.visitTopLevel(Enter.java:334)\n" | ||
+ "\tat com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:518)\n" | ||
+ "\tat com.sun.tools.javac.comp.Enter.classEnter(Enter.java:258)\n" | ||
+ "\tat com.sun.tools.javac.comp.Enter.classEnter(Enter.java:272)\n" | ||
+ "\tat com.sun.tools.javac.comp.Enter.complete(Enter.java:486)\n" | ||
+ "\tat com.sun.tools.javac.comp.Enter.main(Enter.java:471)\n" | ||
+ "\tat com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:982)\n" | ||
+ "\tat com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:857)\n" | ||
+ "\tat com.sun.tools.javac.main.Main.compile(Main.java:523)\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> testBugParade_args() { | ||
return Stream.of( | ||
Arguments.of( | ||
"JDK 8 English", | ||
"An exception has occurred in the compiler ({0}). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.\n"), | ||
Arguments.of( | ||
"JDK 8 Japanese", | ||
"コンパイラで例外が発生しました({0})。Bug Paradeで重複がないかをご確認のうえ、Java Developer Connection (http://java.sun.com/webapps/bugreport)でbugの登録をお願いいたします。レポートには、そのプログラムと下記の診断内容を含めてください。ご協力ありがとうございます。\n"), | ||
Arguments.of( | ||
"JDK 8 Chinese", | ||
"编译器 ({0}) 中出现异常错误。 如果在 Bug Parade 中没有找到该错误, 请在 Java Developer Connection (http://java.sun.com/webapps/bugreport) 中建立 Bug。请在报告中附上您的程序和以下诊断信息。谢谢。\n"), | ||
Arguments.of( | ||
"JDK 21 English", | ||
"An exception has occurred in the compiler ({0}). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.\n"), | ||
Arguments.of( | ||
"JDK 21 Japanese", | ||
"コンパイラで例外が発生しました({0})。バグ・データベース(https://bugs.java.com)で重複がないかをご確認のうえ、Javaのバグ・レポート・ページ(https://bugreport.java.com)から、Javaコンパイラに対するバグの登録をお願いいたします。レポートには、該当のプログラム、次の診断内容、およびJavaコンパイラに渡されたパラメータをご入力ください。ご協力ありがとうございます。\n"), | ||
Arguments.of( | ||
"JDK 21 Chinese", | ||
"编译器 ({0}) 中出现异常错误。如果在 Bug Database (https://bugs.java.com) 中没有找到有关该错误的 Java 编译器 Bug,请通过 Java Bug 报告页 (https://bugreport.java.com) 提交 Java 编译器 Bug。请在报告中附上您的程序、以下诊断信息以及传递到 Java 编译器的参数。谢谢。\n"), | ||
Arguments.of( | ||
"JDK 21 German", | ||
"Im Compiler ({0}) ist eine Ausnahme aufgetreten. Erstellen Sie auf der Java-Seite zum Melden von Bugs (https://bugreport.java.com) einen Bugbericht, nachdem Sie die Bugdatenbank (https://bugs.java.com) auf Duplikate geprüft haben. Geben Sie in Ihrem Bericht Ihr Programm, die folgende Diagnose und die Parameter an, die Sie dem Java-Compiler übergeben haben. Vielen Dank.\n")); | ||
} | ||
|
||
@Test | ||
|
Oops, something went wrong.