-
Notifications
You must be signed in to change notification settings - Fork 61
Improve javac error output parsing - Fix #336 #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
slawekjaranowski
merged 3 commits into
codehaus-plexus:master
from
dev-aspectj:github-336
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.