JDK-8226216 : parameter modifiers are not visible to javac plugins across compilation boundaries
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-06-17
  • Updated: 2025-01-24
  • Resolved: 2021-05-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17
17 b23Fixed
Related Reports
Relates :  
Description
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 []
Comments
Changeset: accbfeaf Author: Guoxiong Li <gli@openjdk.org> Committer: Jan Lahoda <jlahoda@openjdk.org> Date: 2021-05-12 14:32:57 +0000 URL: https://git.openjdk.java.net/jdk/commit/accbfeaf22ea5374292a657ddabb67b22eada6bc
12-05-2021