Skip to content

Commit

Permalink
Update Dagger tests to support JDK 24.
Browse files Browse the repository at this point in the history
https://bugs.openjdk.org/browse/JDK-8338678 is fixed in JDK 24, which now gives more information than we had when reporting errors in previous JDKs. This CL updates our Dagger tests to support JDK 24.

RELNOTES=N/A
PiperOrigin-RevId: 678052093
  • Loading branch information
bcorso authored and Dagger Team committed Sep 24, 2024
1 parent 709e68d commit 3bffd33
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,17 @@ public void missingGenericReturnType() {
assertThrows(
ValidationException.KnownErrorType.class,
() -> superficialValidation.validateElement(testClassElement));
// TODO(b/248552462): Javac and KSP should match once this bug is fixed.
boolean isJavac = processingEnv.getBackend() == XProcessingEnv.Backend.JAVAC;
final String errorType;
if (processingEnv.getBackend() == XProcessingEnv.Backend.JAVAC) {
// JDK 24 improves error type information.
errorType =
Runtime.version().feature() >= 24
? isKAPT(processingEnv) ? "MissingType" : "MissingType<?>"
: "<any>";
} else {
// TODO(b/248552462): Javac and KSP should match once this bug is fixed.
errorType = "error.NonExistentClass";
}
assertThat(exception)
.hasMessageThat()
.contains(
Expand All @@ -135,7 +144,7 @@ public void missingGenericReturnType() {
" => element (CLASS): test.TestClass",
" => element (METHOD): blah()",
" => type (ERROR return type): %1$s"),
isJavac ? "<any>" : "error.NonExistentClass"));
errorType));
});
}

Expand Down Expand Up @@ -165,8 +174,14 @@ public void missingReturnTypeTypeParameter() {
assertThrows(
ValidationException.KnownErrorType.class,
() -> superficialValidation.validateElement(testClassElement));
// TODO(b/248552462): Javac and KSP should match once this bug is fixed.
boolean isJavac = processingEnv.getBackend() == XProcessingEnv.Backend.JAVAC;
final String errorType;
if (processingEnv.getBackend() == XProcessingEnv.Backend.JAVAC) {
// JDK 24 improves error type information.
errorType = Runtime.version().feature() >= 24 ? "MissingType<?>" : "<any>";
} else {
// TODO(b/248552462): Javac and KSP should match once this bug is fixed.
errorType = "error.NonExistentClass";
}
assertThat(exception)
.hasMessageThat()
.contains(
Expand All @@ -178,7 +193,7 @@ public void missingReturnTypeTypeParameter() {
" => type (DECLARED return type): "
+ "java.util.Map<java.util.Set<?>,%1$s>",
" => type (ERROR type argument): %1$s"),
isJavac ? "<any>" : "error.NonExistentClass"));
errorType));
});
}

Expand Down

0 comments on commit 3bffd33

Please sign in to comment.