From 3d0cfd587799dc4420617486fded3b49b7e54a3a Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sat, 13 Jan 2024 17:47:44 +0100 Subject: [PATCH] Fix JDK 11 compatibility --- .../bugpatterns/util/ThirdPartyLibrary.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java index 995f1537707..e5fb961677e 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java @@ -6,11 +6,13 @@ import com.google.errorprone.suppliers.Supplier; import com.sun.tools.javac.code.ClassFinder; import com.sun.tools.javac.code.Source; +import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol.CompletionFailure; import com.sun.tools.javac.code.Symbol.ModuleSymbol; import com.sun.tools.javac.code.Symtab; import com.sun.tools.javac.code.Type; import com.sun.tools.javac.util.Name; +import javax.lang.model.element.Modifier; /** * Utility class that helps decide whether it is appropriate to introduce references to (well-known) @@ -91,7 +93,7 @@ private static boolean isKnownClass(String typeName, VisitorState state) { private static boolean isPublicClassInSymbolTable(String typeName, VisitorState state) { Type type = state.getTypeFromString(typeName); - return type != null && type.tsym.isPublic(); + return type != null && isPublic(type.tsym); } private static boolean canLoadPublicClass(String typeName, VisitorState state) { @@ -104,7 +106,7 @@ private static boolean canLoadPublicClass(String typeName, VisitorState state) { : symtab.unnamedModule; Name binaryName = state.binaryNameFromClassname(typeName); try { - return classFinder.loadClass(module, binaryName).isPublic(); + return isPublic(classFinder.loadClass(module, binaryName)); } catch ( @SuppressWarnings("java:S1166" /* Not exceptional. */) CompletionFailure e) { @@ -112,6 +114,11 @@ private static boolean canLoadPublicClass(String typeName, VisitorState state) { } } + // XXX: Once we target JDK 14+, drop this method in favour of `Symbol#isPublic()`. + private static boolean isPublic(Symbol symbol) { + return symbol.getModifiers().contains(Modifier.PUBLIC); + } + private static boolean shouldIgnoreClasspath(VisitorState state) { return state .errorProneOptions()