-
Bug
-
Resolution: Fixed
-
P3
-
None
-
b23
javac fails to read modifiers from the MethodParameters attribute in class files, which prevents plugins from accessing those modifiers across compilation boundaries. The modifiers are handled correctly if the same symbol is compiled from source in the compilation where the plugin runs.
=== ./plugin/module-info.java
module p {
requires transitive jdk.compiler;
provides com.sun.source.util.Plugin with p.P;
}
=== ./plugin/p/P.java
package p;
import com.sun.source.util.JavacTask;
import com.sun.source.util.Plugin;
import com.sun.source.util.TaskEvent;
import com.sun.source.util.TaskListener;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
public class P implements Plugin {
@Override
public String getName() {
return "P";
}
@Override
public void init(JavacTask javacTask, String... strings) {
javacTask.addTaskListener(
new TaskListener() {
@Override
public void finished(TaskEvent e) {
if (e.getKind() != TaskEvent.Kind.ENTER) {
return;
}
TypeElement b = javacTask.getElements().getTypeElement("B");
for (Element m : b.getEnclosedElements()) {
if (m instanceof ExecutableElement) {
for (VariableElement p : ((ExecutableElement) m).getParameters()) {
System.err.println(p.getSimpleName() + " " + p.getModifiers());
}
}
}
}
});
}
}
=== ./test/A.java
class A {}
=== ./test/B.java
class B {
void f(final int x) {}
}
===
$ javac $(find plugin -name '*.java')
# the final modifier is observable on parameters in the current compilation
$ javac --processor-module-path plugin -Xplugin:P -parameters test/A.java test/B.java
x [final]
x [final]
# the final modifier is not observable on parameters loaded from class files
$ javac --processor-module-path plugin -Xplugin:P -parameters -classpath test test/A.java
x []
=== ./plugin/module-info.java
module p {
requires transitive jdk.compiler;
provides com.sun.source.util.Plugin with p.P;
}
=== ./plugin/p/P.java
package p;
import com.sun.source.util.JavacTask;
import com.sun.source.util.Plugin;
import com.sun.source.util.TaskEvent;
import com.sun.source.util.TaskListener;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
public class P implements Plugin {
@Override
public String getName() {
return "P";
}
@Override
public void init(JavacTask javacTask, String... strings) {
javacTask.addTaskListener(
new TaskListener() {
@Override
public void finished(TaskEvent e) {
if (e.getKind() != TaskEvent.Kind.ENTER) {
return;
}
TypeElement b = javacTask.getElements().getTypeElement("B");
for (Element m : b.getEnclosedElements()) {
if (m instanceof ExecutableElement) {
for (VariableElement p : ((ExecutableElement) m).getParameters()) {
System.err.println(p.getSimpleName() + " " + p.getModifiers());
}
}
}
}
});
}
}
=== ./test/A.java
class A {}
=== ./test/B.java
class B {
void f(final int x) {}
}
===
$ javac $(find plugin -name '*.java')
# the final modifier is observable on parameters in the current compilation
$ javac --processor-module-path plugin -Xplugin:P -parameters test/A.java test/B.java
x [final]
x [final]
# the final modifier is not observable on parameters loaded from class files
$ javac --processor-module-path plugin -Xplugin:P -parameters -classpath test test/A.java
x []
- relates to
-
JDK-8225377 type annotations are not visible to javac plugins across compilation boundaries
- Resolved