JDK-8067733 : annotations on parameters are not visible when processing class files
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u5
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2014-06-18
  • Updated: 2014-12-17
  • Resolved: 2014-12-17
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) Server VM (build 25.5-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux 2.6.18-308.8.2.el5.028stab101.1 #1 SMP Sun Jun 24 20:25:35 MSD 2012 x86_64 x86_64 x86_64 GNU/Linux

Also 

Darwin 13.2.0 Darwin Kernel Version 13.2.0: Thu Apr 17 23:03:13 PDT 2014; root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
Annotation processor works on fields but not parameters. This has been testing on the jdk's listed below:

@java.lang.annotation.Retention (java.lang.annotation.RetentionPolicy.RUNTIME)
public @interface MarkMe {
    String value() default "";
}

public class TestProcessor {
    @MarkMe String testField;
    public TestProcessor(@MarkMe String testParameterInConstructor) { }
    public void anotherMethod(@MarkMe String testParameterInMethod) { }
}


@javax.annotation.processing.SupportedAnnotationTypes(value= {"MarkMe"})
public class MarkMeProcessor extends javax.annotation.processing.AbstractProcessor {

    public MarkMeProcessor() {
        System.out.println("Construct MarkMeProcessor");
    }

    @Override
    public boolean process(final java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, 
                           final javax.annotation.processing.RoundEnvironment roundEnv) {
        System.out.println("Process MarkMeProcessor");
        for (javax.lang.model.element.TypeElement element : annotations){
            System.out.printf("Annotation=%s\n",element.getQualifiedName());
            printElements(roundEnv.getElementsAnnotatedWith(element));
        }
        return true;
    }

    private static void printElements(java.util.Set<? extends javax.lang.model.element.Element> elementList) {
        for(javax.lang.model.element.Element element : elementList) {
            System.out.println(element.getSimpleName());
        }
    }

}

javac MarkMe.java MarkMeProcessor.java
javac -processor MarkMeProcessor TestProcessor.java

------------------------
EXPECTED:
------------------------
Construct MarkMeProcessor
Process MarkMeProcessor
Annotation=MarkMe
testField
testParameterInConstructor
testParameterInMethod
warning: No SupportedSourceVersion annotation found on MarkMeProcessor, returning RELEASE_6.
warning: Supported source version 'RELEASE_6' from annotation processor 'MarkMeProcessor' less than -source '1.8'
Process MarkMeProcessor
2 warnings


------------------------
RESULT:
------------------------
Construct MarkMeProcessor
Process MarkMeProcessor
Annotation=MarkMe
testField
warning: No SupportedSourceVersion annotation found on MarkMeProcessor, returning RELEASE_6.
warning: Supported source version 'RELEASE_6' from annotation processor 'MarkMeProcessor' less than -source '1.8'
Process MarkMeProcessor
2 warnings

------------------------
SUCCESS JDKS
------------------------
java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
Java HotSpot(TM) Server VM (build 23.3-b01, mixed mode)

java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) Server VM (build 24.55-b03, mixed mode)

java version "1.6.0_39"
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) Server VM (build 20.14-b01, mixed mode)

openjdk version "1.8.0-internal"
OpenJDK Runtime Environment (build 1.8.0-internal-xx_2014_06_17_15_33-b00)
OpenJDK 64-Bit Server VM (build 25.20-b18, mixed mode)
(built on my mac)

------------------------
FAILED JDKS
------------------------
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b129)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b69, mixed mode)

java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b129)
Java HotSpot(TM) Server VM (build 25.0-b69, mixed mode)

java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) Server VM (build 25.5-b02, mixed mode)

REGRESSION.  Last worked in version 7u60

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) Server VM (build 24.55-b03, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
see "Source code for an executable test case:"
1) Create simple Annotation class
2) Create Annotation Processor 
3) Create Test class and apply annotation on parameter
4) Compile Annotation class (1) and Annotation Processor (2)
javac MarkMe.java MarkMeProcessor.java
5) Compile Test class (3) with Annotation Processor (2)
javac -processor MarkMeProcessor TestProcessor.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Construct MarkMeProcessor
Process MarkMeProcessor
Annotation=MarkMe
testField
testParameterInConstructor
testParameterInMethod
warning: No SupportedSourceVersion annotation found on MarkMeProcessor, returning RELEASE_6.
warning: Supported source version 'RELEASE_6' from annotation processor 'MarkMeProcessor' less than -source '1.8'
Process MarkMeProcessor
2 warnings
ACTUAL -
Construct MarkMeProcessor
Process MarkMeProcessor
Annotation=MarkMe
testField
warning: No SupportedSourceVersion annotation found on MarkMeProcessor, returning RELEASE_6.
warning: Supported source version 'RELEASE_6' from annotation processor 'MarkMeProcessor' less than -source '1.8'
Process MarkMeProcessor
2 warnings

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
@java.lang.annotation.Retention (java.lang.annotation.RetentionPolicy.RUNTIME)
public @interface MarkMe {
    String value() default "";
}

public class TestProcessor {
    @MarkMe String testField;
    public TestProcessor(@MarkMe String testParameterInConstructor) { }
    public void anotherMethod(@MarkMe String testParameterInMethod) { }
}


@javax.annotation.processing.SupportedAnnotationTypes(value= {"MarkMe"})
public class MarkMeProcessor extends javax.annotation.processing.AbstractProcessor {

    public MarkMeProcessor() {
        System.out.println("Construct MarkMeProcessor");
    }

    @Override
    public boolean process(final java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, 
                           final javax.annotation.processing.RoundEnvironment roundEnv) {
        System.out.println("Process MarkMeProcessor");
        for (javax.lang.model.element.TypeElement element : annotations){
            System.out.printf("Annotation=%s\n",element.getQualifiedName());
            printElements(roundEnv.getElementsAnnotatedWith(element));
        }
        return true;
    }

    private static void printElements(java.util.Set<? extends javax.lang.model.element.Element> elementList) {
        for(javax.lang.model.element.Element element : elementList) {
            System.out.println(element.getSimpleName());
        }
    }

}

javac MarkMe.java MarkMeProcessor.java
javac -processor MarkMeProcessor TestProcessor.java
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use OpenJDK 
javac full version "1.8.0" (OpenJDK)


Comments
Duplicate of JDK-8038080.
17-12-2014

reproduce able with 8u5: $ cat mark1.sh /java/re/jdk/8u5/promoted/latest/binaries/solaris-sparcv9/bin/javac MarkMe.java MarkMeProcessor.java /java/re/jdk/8u5/promoted/latest/binaries/solaris-sparcv9/bin/javac -processor MarkMeProcessor TestProcessor.java $ sh mark1.sh Construct MarkMeProcessor Process MarkMeProcessor Annotation=MarkMe testField warning: No SupportedSourceVersion annotation found on MarkMeProcessor, returning RELEASE_6. warning: Supported source version 'RELEASE_6' from annotation processor 'MarkMeProcessor' less than -source '1.8' Process MarkMeProcessor 2 warnings 8u25 resolved the issue
16-12-2014

Cannot reproduce with 8u25
19-06-2014

I am unable to reproduce this with 8u25 : $ cat mark.sh /java/re/jdk/8u25/promoted/all/b03/binaries/solaris-sparcv9/bin/javac MarkMe.java MarkMeProcessor.java /java/re/jdk/8u25/promoted/all/b03/binaries/solaris-sparcv9/bin/javac -processor MarkMeProcessor TestProcessor.java $ sh mark.sh Construct MarkMeProcessor Process MarkMeProcessor Annotation=MarkMe testField testParameterInConstructor testParameterInMethod warning: No SupportedSourceVersion annotation found on MarkMeProcessor, returning RELEASE_6. warning: Supported source version 'RELEASE_6' from annotation processor 'MarkMeProcessor' less than -source '1.8' Process MarkMeProcessor 2 warnings Guess it got addressed in 8u25 ? Please reopen/raise a new issue if you can reproduce it.
19-06-2014