From eba1108b4f91114de3032601e34c70cda3f872ac Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Thu, 7 Jan 2021 12:28:25 -0800 Subject: [PATCH] Add a reflective workaround for a return type that changed in JDK 10 Fixes https://github.com/google/error-prone/issues/1529 PiperOrigin-RevId: 350615883 --- .../com/google/errorprone/ErrorProneAnalyzer.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java b/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java index fe171cbf1aa8..b6bdff7f6d13 100644 --- a/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java +++ b/check_api/src/main/java/com/google/errorprone/ErrorProneAnalyzer.java @@ -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();