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 995f153770..e5fb961677 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()