-
Bug
-
Resolution: Fixed
-
P4
-
None
-
b24
javac does not initialize receiver types of methods read from class files, which results in ExecutableElement.getReceiverType incorrectly reporting that methods don't have a receiver type.
Repro:
=== P.java
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
@SupportedAnnotationTypes("*")
public class P extends AbstractProcessor {
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
boolean first = true;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (first) {
for (Element e :
processingEnv.getElementUtils().getTypeElement("Test").getEnclosedElements()) {
if (e.getSimpleName().contentEquals("f")) {
ExecutableElement f = (ExecutableElement) e;
processingEnv
.getMessager()
.printMessage(Diagnostic.Kind.NOTE, f.getReceiverType().toString(), f);
}
}
first = false;
}
return false;
}
}
=== Test.java
class Test {
void f(Test this) {}
}
===
The receiver type is available if 'Test' is compiled from source:
$ javac -processor P -implicit:none Test.java
Test.java:2: Note: Test
void f(Test this) {}
^
The receiver type is incorrectly reported as 'none' if 'Test' is loaded from the classpath:
$ javac -processor P -implicit:none Test
Note: none
Repro:
=== P.java
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
@SupportedAnnotationTypes("*")
public class P extends AbstractProcessor {
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
boolean first = true;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (first) {
for (Element e :
processingEnv.getElementUtils().getTypeElement("Test").getEnclosedElements()) {
if (e.getSimpleName().contentEquals("f")) {
ExecutableElement f = (ExecutableElement) e;
processingEnv
.getMessager()
.printMessage(Diagnostic.Kind.NOTE, f.getReceiverType().toString(), f);
}
}
first = false;
}
return false;
}
}
=== Test.java
class Test {
void f(Test this) {}
}
===
The receiver type is available if 'Test' is compiled from source:
$ javac -processor P -implicit:none Test.java
Test.java:2: Note: Test
void f(Test this) {}
^
The receiver type is incorrectly reported as 'none' if 'Test' is loaded from the classpath:
$ javac -processor P -implicit:none Test
Note: none
- csr for
-
JDK-8319330 ExecutableElement.getReceiverType doesn't return receiver types for methods loaded from bytecode
- Closed
- relates to
-
JDK-8222369 ExecutableElement.getReceiverType returns null instead of NOTYPE
- Resolved
-
JDK-8225488 Examine ExecutableType.getReceiverType behavior when source receiver parameter is absent
- Resolved
-
JDK-8320941 Discuss receiver type handling
- Resolved
(1 links to)
There are no Sub-Tasks for this issue.