Skip to content

Commit 5da8e9a

Browse files
cushonError Prone Team
authored and
Error Prone Team
committed
Fix binary compatibility issues when building on JDK 17 and running on JDK 11, and prepare to add test coverage for that configuration
Thanks to Stephan202's suggestion in #3895 (comment) #3895 PiperOrigin-RevId: 530957571
1 parent 7335ba2 commit 5da8e9a

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,9 +1141,17 @@ public static List<MethodTree> getConstructors(ClassTree classTree) {
11411141
return constructors;
11421142
}
11431143

1144+
/**
1145+
* A wrapper for {@link Symbol#getEnclosedElements} to avoid binary compatibility issues for
1146+
* covariant overrides in subtypes of {@link Symbol}.
1147+
*/
1148+
public static List<Symbol> getEnclosedElements(Symbol symbol) {
1149+
return symbol.getEnclosedElements();
1150+
}
1151+
11441152
/** Returns the list of all constructors defined in the class. */
11451153
public static ImmutableList<MethodSymbol> getConstructors(ClassSymbol classSymbol) {
1146-
return classSymbol.getEnclosedElements().stream()
1154+
return getEnclosedElements(classSymbol).stream()
11471155
.filter(Symbol::isConstructor)
11481156
.map(e -> (MethodSymbol) e)
11491157
.collect(toImmutableList());

core/src/main/java/com/google/errorprone/bugpatterns/ChainedAssertionLosesContext.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static com.google.errorprone.matchers.Matchers.instanceMethod;
2626
import static com.google.errorprone.matchers.Matchers.staticMethod;
2727
import static com.google.errorprone.util.ASTHelpers.getDeclaredSymbol;
28+
import static com.google.errorprone.util.ASTHelpers.getEnclosedElements;
2829
import static com.google.errorprone.util.ASTHelpers.getSymbol;
2930
import static com.google.errorprone.util.ASTHelpers.isSubtype;
3031
import static com.sun.source.tree.Tree.Kind.CLASS;
@@ -212,9 +213,9 @@ private static FactoryMethodName tryFindFactory(
212213
ImmutableSet<MethodSymbol> factories =
213214
concat(
214215
// The class that assertThat is declared in:
215-
assertThatSymbol.owner.getEnclosedElements().stream(),
216+
getEnclosedElements(assertThatSymbol.owner).stream(),
216217
// The Subject class (possibly the same; if so, toImmutableSet() will deduplicate):
217-
assertThatSymbol.getReturnType().asElement().getEnclosedElements().stream())
218+
getEnclosedElements(assertThatSymbol.getReturnType().asElement()).stream())
218219
.filter(s -> s instanceof MethodSymbol)
219220
.map(s -> (MethodSymbol) s)
220221
.filter(

core/src/main/java/com/google/errorprone/bugpatterns/FuturesGetCheckedIllegalExceptionType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static com.google.errorprone.matchers.Matchers.argument;
2121
import static com.google.errorprone.matchers.Matchers.classLiteral;
2222
import static com.google.errorprone.matchers.method.MethodMatchers.staticMethod;
23+
import static com.google.errorprone.util.ASTHelpers.getEnclosedElements;
2324
import static com.google.errorprone.util.ASTHelpers.getSymbol;
2425
import static com.google.errorprone.util.ASTHelpers.getType;
2526
import static com.google.errorprone.util.ASTHelpers.isSameType;
@@ -123,7 +124,7 @@ public boolean matches(ExpressionTree tree, VisitorState state) {
123124
return true;
124125
}
125126

126-
for (Symbol enclosedSymbol : classSymbol.getEnclosedElements()) {
127+
for (Symbol enclosedSymbol : getEnclosedElements(classSymbol)) {
127128
if (!enclosedSymbol.isConstructor()) {
128129
continue;
129130
}

core/src/main/java/com/google/errorprone/bugpatterns/HidingField.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;
1919
import static com.google.errorprone.util.ASTHelpers.enclosingPackage;
20+
import static com.google.errorprone.util.ASTHelpers.getEnclosedElements;
2021
import static com.google.errorprone.util.ASTHelpers.getSymbol;
2122
import static java.util.stream.Collectors.toCollection;
2223

@@ -70,7 +71,7 @@ public Description matchClass(ClassTree classTree, VisitorState visitorState) {
7071

7172
while (!classSymbol.getSuperclass().getKind().equals(TypeKind.NONE)) {
7273
TypeSymbol parentSymbol = classSymbol.getSuperclass().asElement();
73-
List<Symbol> parentElements = parentSymbol.getEnclosedElements();
74+
List<Symbol> parentElements = getEnclosedElements(parentSymbol);
7475

7576
Map<Name, VarSymbol> parentMembers =
7677
parentElements.stream()

core/src/test/java/com/google/errorprone/bugpatterns/apidiff/CompilationBuilderHelpers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ CompilationResult compile() throws IOException {
131131
diagnosticCollector,
132132
javacopts,
133133
/* classes= */ Collections.<String>emptyList(),
134-
fileManager.getJavaFileObjectsFromPaths(sources))
134+
fileManager.getJavaFileObjects(sources.toArray(new Path[0])))
135135
.call();
136136

137137
return CompilationResult.create(

pom.xml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@
208208
<plugin>
209209
<groupId>org.apache.maven.plugins</groupId>
210210
<artifactId>maven-surefire-plugin</artifactId>
211-
<version>2.22.2</version>
211+
<version>3.1.0</version>
212212
<configuration>
213213
<argLine>
214214
-Xmx1g
@@ -303,5 +303,28 @@
303303
</plugins>
304304
</build>
305305
</profile>
306+
<profile>
307+
<id>custom-test-runtime-version</id>
308+
<activation>
309+
<property>
310+
<name>surefire.jdk-toolchain-version</name>
311+
</property>
312+
</activation>
313+
<build>
314+
<pluginManagement>
315+
<plugins>
316+
<plugin>
317+
<groupId>org.apache.maven.plugins</groupId>
318+
<artifactId>maven-surefire-plugin</artifactId>
319+
<configuration>
320+
<jdkToolchain>
321+
<version>${surefire.jdk-toolchain-version}</version>
322+
</jdkToolchain>
323+
</configuration>
324+
</plugin>
325+
</plugins>
326+
</pluginManagement>
327+
</build>
328+
</profile>
306329
</profiles>
307330
</project>

0 commit comments

Comments
 (0)