|
28 | 28 | import java.io.StringReader;
|
29 | 29 | import java.util.ArrayList;
|
30 | 30 | import java.util.List;
|
| 31 | +import java.util.stream.Stream; |
31 | 32 |
|
32 | 33 | import org.codehaus.plexus.compiler.CompilerMessage;
|
33 | 34 | import org.codehaus.plexus.util.Os;
|
34 | 35 | import org.junit.jupiter.api.Test;
|
| 36 | +import org.junit.jupiter.params.ParameterizedTest; |
| 37 | +import org.junit.jupiter.params.provider.Arguments; |
| 38 | +import org.junit.jupiter.params.provider.MethodSource; |
35 | 39 |
|
| 40 | +import static org.hamcrest.CoreMatchers.endsWith; |
| 41 | +import static org.hamcrest.CoreMatchers.startsWith; |
36 | 42 | import static org.hamcrest.MatcherAssert.assertThat;
|
37 | 43 | import static org.hamcrest.Matchers.hasSize;
|
38 | 44 | import static org.hamcrest.Matchers.is;
|
39 | 45 | import static org.hamcrest.Matchers.notNullValue;
|
40 |
| -import static org.hamcrest.core.StringEndsWith.endsWith; |
41 |
| -import static org.hamcrest.core.StringStartsWith.startsWith; |
42 | 46 |
|
43 | 47 | /**
|
44 | 48 | * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
|
| 49 | + * @author Alexander Kriegisch |
45 | 50 | */
|
46 | 51 | public class ErrorMessageParserTest {
|
47 | 52 | private static final String EOL = System.getProperty("line.separator");
|
@@ -775,19 +780,79 @@ public void testJava7Error() throws Exception {
|
775 | 780 | assertThat(message2.getEndLine(), is(3));
|
776 | 781 | }
|
777 | 782 |
|
778 |
| - @Test |
779 |
| - public void testBugParade() throws Exception { |
780 |
| - String out = "An exception has occurred in the compiler (1.7.0_80). " |
781 |
| - + "Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. " |
782 |
| - + "Include your program and the following diagnostic in your report. Thank you." + EOL |
783 |
| - + "com.sun.tools.javac.code.Symbol$CompletionFailure: class file for java.util.Optional not found"; |
| 783 | + @ParameterizedTest(name = "{0}") |
| 784 | + @MethodSource("testBugParade_args") |
| 785 | + public void testBugParade(String jdkAndLocale, String stackTraceHeader) throws Exception { |
| 786 | + String stackTraceWithHeader = stackTraceHeader + stackTraceInternalCompilerError; |
784 | 787 |
|
785 |
| - List<CompilerMessage> compilerErrors = |
786 |
| - JavacCompiler.parseModernStream(4, new BufferedReader(new StringReader(out))); |
| 788 | + List<CompilerMessage> compilerMessages = |
| 789 | + JavacCompiler.parseModernStream(4, new BufferedReader(new StringReader(stackTraceWithHeader))); |
787 | 790 |
|
788 |
| - assertThat(compilerErrors, notNullValue()); |
| 791 | + assertThat(compilerMessages, notNullValue()); |
| 792 | + assertThat(compilerMessages, hasSize(1)); |
789 | 793 |
|
790 |
| - assertThat(compilerErrors.size(), is(1)); |
| 794 | + String message = compilerMessages.get(0).getMessage().replaceAll(EOL, "\n"); |
| 795 | + // Parser retains stack trace header |
| 796 | + assertThat(message, startsWith(stackTraceHeader)); |
| 797 | + assertThat(message, endsWith(stackTraceInternalCompilerError)); |
| 798 | + } |
| 799 | + |
| 800 | + private static final String stackTraceInternalCompilerError = |
| 801 | + "\tat com.sun.tools.javac.comp.MemberEnter.baseEnv(MemberEnter.java:1388)\n" |
| 802 | + + "\tat com.sun.tools.javac.comp.MemberEnter.complete(MemberEnter.java:1046)\n" |
| 803 | + + "\tat com.sun.tools.javac.code.Symbol.complete(Symbol.java:574)\n" |
| 804 | + + "\tat com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1037)\n" |
| 805 | + + "\tat com.sun.tools.javac.code.Symbol$ClassSymbol.flags(Symbol.java:973)\n" |
| 806 | + + "\tat com.sun.tools.javac.code.Symbol$ClassSymbol.getKind(Symbol.java:1101)\n" |
| 807 | + + "\tat com.sun.tools.javac.code.Kinds.kindName(Kinds.java:162)\n" |
| 808 | + + "\tat com.sun.tools.javac.comp.Check.duplicateError(Check.java:329)\n" |
| 809 | + + "\tat com.sun.tools.javac.comp.Check.checkUnique(Check.java:3435)\n" |
| 810 | + + "\tat com.sun.tools.javac.comp.Enter.visitTypeParameter(Enter.java:454)\n" |
| 811 | + + "\tat com.sun.tools.javac.tree.JCTree$JCTypeParameter.accept(JCTree.java:2224)\n" |
| 812 | + + "\tat com.sun.tools.javac.comp.Enter.classEnter(Enter.java:258)\n" |
| 813 | + + "\tat com.sun.tools.javac.comp.Enter.classEnter(Enter.java:272)\n" |
| 814 | + + "\tat com.sun.tools.javac.comp.Enter.visitClassDef(Enter.java:418)\n" |
| 815 | + + "\tat com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:693)\n" |
| 816 | + + "\tat com.sun.tools.javac.comp.Enter.classEnter(Enter.java:258)\n" |
| 817 | + + "\tat com.sun.tools.javac.comp.Enter.classEnter(Enter.java:272)\n" |
| 818 | + + "\tat com.sun.tools.javac.comp.Enter.visitTopLevel(Enter.java:334)\n" |
| 819 | + + "\tat com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:518)\n" |
| 820 | + + "\tat com.sun.tools.javac.comp.Enter.classEnter(Enter.java:258)\n" |
| 821 | + + "\tat com.sun.tools.javac.comp.Enter.classEnter(Enter.java:272)\n" |
| 822 | + + "\tat com.sun.tools.javac.comp.Enter.complete(Enter.java:486)\n" |
| 823 | + + "\tat com.sun.tools.javac.comp.Enter.main(Enter.java:471)\n" |
| 824 | + + "\tat com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:982)\n" |
| 825 | + + "\tat com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:857)\n" |
| 826 | + + "\tat com.sun.tools.javac.main.Main.compile(Main.java:523)\n" |
| 827 | + + "\tat com.sun.tools.javac.main.Main.compile(Main.java:381)\n" |
| 828 | + + "\tat com.sun.tools.javac.main.Main.compile(Main.java:370)\n" |
| 829 | + + "\tat com.sun.tools.javac.main.Main.compile(Main.java:361)\n" |
| 830 | + + "\tat com.sun.tools.javac.Main.compile(Main.java:56)\n" |
| 831 | + + "\tat com.sun.tools.javac.Main.main(Main.java:42)\n"; |
| 832 | + |
| 833 | + private static Stream<Arguments> testBugParade_args() { |
| 834 | + return Stream.of( |
| 835 | + Arguments.of( |
| 836 | + "JDK 8 English", |
| 837 | + "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"), |
| 838 | + Arguments.of( |
| 839 | + "JDK 8 Japanese", |
| 840 | + "コンパイラで例外が発生しました({0})。Bug Paradeで重複がないかをご確認のうえ、Java Developer Connection (http://java.sun.com/webapps/bugreport)でbugの登録をお願いいたします。レポートには、そのプログラムと下記の診断内容を含めてください。ご協力ありがとうございます。\n"), |
| 841 | + Arguments.of( |
| 842 | + "JDK 8 Chinese", |
| 843 | + "编译器 ({0}) 中出现异常错误。 如果在 Bug Parade 中没有找到该错误, 请在 Java Developer Connection (http://java.sun.com/webapps/bugreport) 中建立 Bug。请在报告中附上您的程序和以下诊断信息。谢谢。\n"), |
| 844 | + Arguments.of( |
| 845 | + "JDK 21 English", |
| 846 | + "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"), |
| 847 | + Arguments.of( |
| 848 | + "JDK 21 Japanese", |
| 849 | + "コンパイラで例外が発生しました({0})。バグ・データベース(https://bugs.java.com)で重複がないかをご確認のうえ、Javaのバグ・レポート・ページ(https://bugreport.java.com)から、Javaコンパイラに対するバグの登録をお願いいたします。レポートには、該当のプログラム、次の診断内容、およびJavaコンパイラに渡されたパラメータをご入力ください。ご協力ありがとうございます。\n"), |
| 850 | + Arguments.of( |
| 851 | + "JDK 21 Chinese", |
| 852 | + "编译器 ({0}) 中出现异常错误。如果在 Bug Database (https://bugs.java.com) 中没有找到有关该错误的 Java 编译器 Bug,请通过 Java Bug 报告页 (https://bugreport.java.com) 提交 Java 编译器 Bug。请在报告中附上您的程序、以下诊断信息以及传递到 Java 编译器的参数。谢谢。\n"), |
| 853 | + Arguments.of( |
| 854 | + "JDK 21 German", |
| 855 | + "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")); |
791 | 856 | }
|
792 | 857 |
|
793 | 858 | @Test
|
|
0 commit comments