Skip to content

Commit f0d5306

Browse files
committed
GROOVY-11789: do not re-add fatal javac error to ErrorCollector
1 parent 089590d commit f0d5306

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,16 @@ public void compile(List<String> files, CompilationUnit cu) {
6262
StringBuilderWriter javacOutput = new StringBuilderWriter();
6363
int javacReturnValue = 0;
6464
try {
65-
try {
66-
boolean successful = doCompileWithSystemJavaCompiler(cu, files, javacParameters, javacOutput);
67-
if (!successful) {
68-
javacReturnValue = 1;
69-
}
70-
} catch (IllegalArgumentException e) {
71-
javacReturnValue = 2; // any of the options are invalid
72-
cu.getErrorCollector().addFatalError(new ExceptionMessage(e, true, cu));
73-
} catch (IOException e) {
65+
boolean successful = doCompileWithSystemJavaCompiler(cu, files, javacParameters, javacOutput);
66+
if (!successful) {
7467
javacReturnValue = 1;
75-
cu.getErrorCollector().addFatalError(new ExceptionMessage(e, true, cu));
7668
}
69+
} catch (IllegalArgumentException e) {
70+
javacReturnValue = 2; // any of the options are invalid
71+
cu.getErrorCollector().addFatalError(new ExceptionMessage(e, true, cu));
72+
} catch (IOException e) {
73+
javacReturnValue = 1;
74+
cu.getErrorCollector().addFatalError(new ExceptionMessage(e, true, cu));
7775
} catch (Exception e) {
7876
cu.getErrorCollector().addFatalError(new ExceptionMessage(e, true, cu));
7977
}

subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@
200200
<java classname="org.codehaus.groovy.ant.GroovycTest1"/>
201201
</target>
202202

203+
<!-- GROOVY-11789 -->
204+
<target name="badJavacArgument">
205+
<compile-joint includes="**/GroovycTest2.java">
206+
<javac>
207+
<compilerarg value="-Xlint:xxx"/>
208+
</javac>
209+
</compile-joint>
210+
</target>
211+
203212
<target name="clean">
204213
<delete quiet="true">
205214
<fileset dir="${destPath}/org/codehaus/groovy/ant">

subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,4 +319,14 @@ public void testPlainForkedCompilation_NestingSrcElementCheck() {
319319
ensureExecutes("plainForkedCompilation_NestingSrcElementCheck");
320320
ensureNotPresent("GroovycTest2"); // excluded from src > fileset
321321
}
322+
323+
// GROOVY-11789
324+
public void testBadJavacArgument() {
325+
try {
326+
project.executeTarget("badJavacArgument");
327+
fail("BuildException expected");
328+
} catch (BuildException e) {
329+
assertTrue(e.getCause().getMessage().contains("invalid flag: -Xlint:xxx"));
330+
}
331+
}
322332
}

0 commit comments

Comments
 (0)