Skip to content

Commit dc9faca

Browse files
committed
BTRACE-95: JavacTask may not return failure even though errors are present
Contributed-by: Pavel Nejedly
1 parent 5e90d3b commit dc9faca

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/share/classes/com/sun/btrace/compiler/Compiler.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.List;
4040
import java.util.Map;
4141
import javax.tools.Diagnostic;
42+
import javax.tools.Diagnostic.Kind;
4243
import javax.tools.DiagnosticCollector;
4344
import javax.tools.JavaCompiler;
4445
import javax.tools.JavaFileObject;
@@ -259,7 +260,7 @@ private Map<String, byte[]> compile(MemoryJavaFileManager manager,
259260
}
260261

261262
// print dignostics messages in case of failures.
262-
if (task.call() == false) {
263+
if (task.call() == false || containsErrors(diagnostics)) {
263264
for (Diagnostic diagnostic : diagnostics.getDiagnostics()) {
264265
perr.println(diagnostic.getMessage(null));
265266
}
@@ -291,6 +292,18 @@ private Map<String, byte[]> compile(MemoryJavaFileManager manager,
291292
}
292293
}
293294

295+
/** Checks if the list of diagnostic messages contains at least one error. Certain
296+
* {@link JavacTask} implementations may return success error code even though errors were
297+
* reported. */
298+
private boolean containsErrors(DiagnosticCollector<?> diagnostics) {
299+
for (Diagnostic<?> diagnostic : diagnostics.getDiagnostics()) {
300+
if (diagnostic.getKind() == Kind.ERROR) {
301+
return true;
302+
}
303+
}
304+
return false;
305+
}
306+
294307
private void dump(String name, byte[] code) {
295308
// OutputStream os = null;
296309
// try {

0 commit comments

Comments
 (0)