JDK-8237450 : JDK13 annotation processors not run when a supported annotation type specifies a module
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 13
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-01-16
  • Updated: 2020-02-25
  • Resolved: 2020-02-19
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 15
15 b11Fixed
Related Reports
Relates :  
Description
From compiler-dev:

Hi,

I've just ran into this issue while testing annotation processors with JDK13. It happens when you specify a @SupportedAnnotationTypes annotation with annotation names prefixed with composite module names like the following:

@SupportedAnnotationTypes({"com.example.moda/com.example.moda.annotation.SomeAnnotation"})
public class ModuleAnnotationProcessor extends AbstractProcessor {
   ...
}

This is perfectly valid according to the documentation and was working just fine until JDK13

"the name of the annotation type can be optionally preceded by a module name followed by a "/" character. For example, if a processor supports "a.B", this can include multiple annotation types named a.B which reside in different modules. To only support a.B in the Foo module, instead use "Foo/a.B". If a module name is included, only an annotation in that module is matched. In particular, if a module name is given in an environment where modules are not supported, such as an annotation processing environment configured for a source version without modules, then the annotation types with a module name do not match." -- https://docs.oracle.com/en/java/javase/11/docs/api/java.compiler/javax/annotation/processing/Processor.html#getSupportedAnnotationTypes()

I've track down the issue in JavacProcessingEnvironment.java to the following commit: https://hg.openjdk.java.net/jdk/jdk/diff/d84176dd57b0/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java

Some checks have been added to make sure supported annotation strings are valid and proper warning reported, unfortunately there's an error in the module's name check:

private static Pattern importStringToPattern(boolean allowModules, String s, Processor p, Log log, boolean lint) {
    ....
    else {
            String moduleName = s.substring(0, slash);
            if (!SourceVersion.isIdentifier(moduleName)) {
                return warnAndNoMatches(s, p, log, lint);
            }
    ....
}

A module name is not a simple identifier like "moda", "com.example.moda" is also a valid module name as stated in the Java Language Specification (7.7). This results in always returning a no match pattern when such module name is used and the processor basically ignored.

If we do not prefix the annotation with a module name, so there is a workaround but that doesn't match the API doc.

Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/46bb1175b837 User: darcy Date: 2020-02-19 01:05:06 +0000
19-02-2020

Review thread: http://mail.openjdk.java.net/pipermail/compiler-dev/2020-February/014304.html
15-02-2020

Suspect the issue was introduced by JDK-8224177.
15-02-2020

Looks like SourceVersion.isIdentifier should be replaced with SourceVersion.isName.
17-01-2020