Skip to content

Commit

Permalink
Fix JDK 11 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 authored and rickie committed Jan 29, 2024
1 parent c33dba4 commit 5994a5e
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Check warning on line 96 in error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java

View workflow job for this annotation

GitHub Actions / pitest

2 different changes can be made to line 96 without causing a test to fail

removed conditional - replaced equality check with false (covered by 17 tests RemoveConditionalMutator_EQUAL_ELSE) removed conditional - replaced equality check with false (covered by 6 tests RemoveConditionalMutator_EQUAL_ELSE)
}

private static boolean canLoadPublicClass(String typeName, VisitorState state) {
Expand All @@ -104,14 +106,19 @@ 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) {
return false;
}
}

// 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()
Expand Down

0 comments on commit 5994a5e

Please sign in to comment.