Compile-time constant generated through annotation processor is not usable in repeated annotation but fails compilation

XMLWordPrintable

    • generic

      A DESCRIPTION OF THE PROBLEM :
      If you have an annotation processor that generates a compile-time constant and you try to use that constant as a value for a repeated annotation, compilation fails.

      As long as the annotation is not repeated, it compiles fine.

      If you manually wrap the repeated annotation into its container annotation, it also compiles fine.

      Just when the container annotation is created implicitly, compilation fails with error "expression not allowed as annotation value".

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      - Store the given sourcecode into `Foo.java`
      - Get the 5 used jars
      - Execute `javac -J-Duser.language=en -processorpath 'hibernate-processor-7.2.4.Final.jar;hibernate-core-7.2.4.Final.jar;jakarta.persistence-api-3.2.0.jar;jakarta.xml.bind-api-4.0.4.jar;antlr4-runtime-4.13.2.jar' -classpath 'jakarta.persistence-api-3.2.0.jar' Foo.java`

      => Compilation fails with "expression not allowed as annotation value"

      - Comment out the first `@NamedNativeQuery` line
      - Rerun the compiler command

      => Compilation is successful

      - Comment in all commented lines (including the just outcommented one)
      - Rerun the compiler command

      => Compilation is successful

      ---------- BEGIN SOURCE ----------
      ```java
      import jakarta.persistence.NamedNativeQueries;
      import jakarta.persistence.NamedNativeQuery;
      import jakarta.persistence.SqlResultSetMapping;

      //@NamedNativeQueries({
      @NamedNativeQuery(name = "foo", query = "")
      //,
      @NamedNativeQuery(name = "foo", query = "", resultSetMapping = Foo_.MAPPING_MAPPING)
      //})
      @SqlResultSetMapping(name = "mapping")
      public class Foo {
      }
      ```
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Manually wrap the repeated annotation into its container annotation, or do not use annotation generator generated constants as annotation attribute values.

      FREQUENCY :
      ALWAYS

            Assignee:
            Jan Lahoda
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: