Skip to content

Commit

Permalink
Add a reflective workaround for a return type that changed in JDK 10
Browse files Browse the repository at this point in the history
Fixes #1529

PiperOrigin-RevId: 350615883
  • Loading branch information
cushon authored and Error Prone Team committed Jan 7, 2021
1 parent b4ec650 commit eba1108
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,23 @@ public void finished(TaskEvent taskEvent) {
// symbol's supertypes. If javac didn't need to check the symbol's assignability
// then a normal compilation would have succeeded, and no diagnostics will have been
// reported yet, but we don't want to crash javac.
log.error("proc.cant.access", e.sym, e.getDetailValue(), getStackTraceAsString(e));
log.error("proc.cant.access", e.sym, getDetailValue(e), getStackTraceAsString(e));
} finally {
log.useSource(originalSource);
}
}

private static Object getDetailValue(CompletionFailure completionFailure) {
try {
// The return type of getDetailValue() changed from Object to JCDiagnostic in JDK 10,
// but the rest of the signature is unchanged between the two versions,
// see https://bugs.openjdk.java.net/browse/JDK-817032,
return CompletionFailure.class.getMethod("getDetailValue").invoke(completionFailure);
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
}
}

/** Returns true if the given source file should be excluded from analysis. */
private boolean shouldExcludeSourceFile(CompilationUnitTree tree) {
Pattern excludedPattern = errorProneOptions.getExcludedPattern();
Expand Down

0 comments on commit eba1108

Please sign in to comment.