-
Bug
-
Resolution: Fixed
-
P4
-
19, 20
-
b04
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8297615 | 17.0.7-oracle | Vicente Arturo Romero Zaldivar | P4 | Resolved | Fixed | b01 |
JDK-8299364 | 17.0.7 | Goetz Lindenmaier | P4 | Resolved | Fixed | b01 |
In summary, an explicitly declared accessor method for a record component whose type is a type parameter of the record fails to compile only when an annotation processor is present during compilation. Removal of the explicit accessor or the annotation processor(s) makes the class compile as expected.
We've assembled a small reproducible case for this issue:
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.TypeElement;
import java.util.Set;
public class EmptyProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
return false;
}
}
public record TestRecord<T>(T someValue) {
public T someValue() {
return this.someValue;
}
}
Put each snippet into the source files `EmptyProcessor.java` and `TestRecord.java` respectively, compile the AP class using `javac EmptyProcessor.java`, and try to compile the record class with the AP present using `javac -processor EmptyProcessor TestRecord.java`. The warnings about the processor's lack of source version and supported annotations can be safely ignored (we used them to confirm that the annotation processor is present). Here is the output from running the above on Java 17:
D:\Dev\Sandbox\javacbug> javac -processor EmptyProcessor TestRecord.java
warning: No SupportedSourceVersion annotation found on EmptyProcessor, returning RELEASE_6.
warning: Supported source version 'RELEASE_6' from annotation processor 'EmptyProcessor' less than -source '17'
warning: No SupportedAnnotationTypes annotation found on EmptyProcessor, returning an empty set.
TestRecord.java:3: error: invalid accessor method in record TestRecord
public T someValue() {
^
(return type of accessor method someValue() must match the type of record component someValue)
where T is a type-variable:
T extends Object declared in record TestRecord
1 error
3 warnings
We've tested this on Windows against Java 16, 17, 18, as well as the 19 EA (build 25, 2022/6/2), all reference implementations from jdk.java.net, as well as the latest Java 17 for Eclipse Temurin (17.0.3_7) and the test case fails on all those versions. We've also tested this against the Eclipse Compiler for Java, and it compiles successfully both with and without the presence of the AP.
as reported in compiler-dev: https://mail.openjdk.java.net/pipermail/compiler-dev/2022-June/019956.html
- backported by
-
JDK-8297615 compiler error with AP and explicit record accessor
-
- Resolved
-
-
JDK-8299364 compiler error with AP and explicit record accessor
-
- Resolved
-
- duplicates
-
JDK-8300403 Generated Builder for Record used as Generic Parameter of another Record fails
-
- Closed
-
-
JDK-8284255 AssertionError: typeSig ERROR on record property with generated class type arg
-
- Closed
-
- relates to
-
JDK-8289647 AssertionError during annotation processing of record related tests
-
- Closed
-
-
JDK-8300403 Generated Builder for Record used as Generic Parameter of another Record fails
-
- Closed
-
- links to
-
Commit openjdk/jdk17u-dev/e770114a
-
Commit openjdk/jdk/53b37fe1
-
Review openjdk/jdk17u-dev/971
-
Review openjdk/jdk/9160