Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10068

Cannot compile when set short value to annotation by already defined short variable since version 2.5.4

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.4
    • 4.0.4
    • None

    Description

      1. Summary

      Case

      @TestAnnotation(shortProp2 = TestCode.SHORT_1)
      class TestAnnotationValue_Groovy {
          //...
      }

      Error

      \\some\\project\\TestAnnotationValue_Groovy.groovy: -1: Attribute 'shortProp2' should have type 'java.lang.Short'; but found type 'java.lang.Integer' in @test.bug.annotation.TestAnnotation

       

      Works.

      • On Groovy between 2.1.3 and 2.5.3 (tested by 2.1.3 / 2.4.13 / 2.5.3)

       

      Not works. (Compile Error ocurred)

      • Since Groovy 2.5.4. (tested by 2.5.4 / 2.5.14 / 3.0.8)

       

       

      2. Test Code

      /**
       * 1. Create some annotation.
       */
      @Retention(RetentionPolicy.RUNTIME)
      public @interface TestAnnotation {
          short shortProp1() default (short) -1;
          short shortProp2() default (short) -1;
          int intProp1() default -1;
          int intProp2() default -1;
          long longProp1() default -1L;
          long longProp2() default -1L;
          boolean booleanProp() default false;
      }
      

       

      /**
       * 2. Create code values for annotation.
       */
      public interface TestCode {
          public final static short SHORT_0 = 0;
          public final static short SHORT_1 = 0;
          public final static int INT_0 = 0;
          public final static int INT_1 = 1;
          public final static long LONG_0 = 0L;
          public final static long LONG_1 = 1L;
      }
      

       

      /**
       * 3-1. It all works on Java class
       */
      @TestAnnotation(
          intProp1 = 1,
          intProp2 = TestCode.INT_1,
          longProp1 = 1L,
          longProp2 = TestCode.LONG_1,
          shortProp1 = 1,
          shortProp2 = TestCode.SHORT_1
      )
      class TestAnnotationValue_Java {
          Integer objectId;
      }
      

       

      /**
       * 3-2. 'int' and 'long' works on all version of groovy
       * But 'short' does not works on some groovy version.
       */
      @TestAnnotation(
          intProp1 = 1,
          intProp2 = TestCode.INT_1,
          longProp1 = 1L,
          longProp2 = TestCode.LONG_1,
      
          /**
           * [Defining directly] It always does not works on groovy class
           **/
          // shortProp1 = 1,
      
          /**
           * [Defining as an already defined variable] It works on Groovy between 2.1.3 and 2.5.3 (tested by 2.1.3 / 2.4.13 / 2.5.3)
           * But, It does not works since Groovy 2.5.4. (tested by 2.5.4 / 2.5.14 / 3.0.8)
           **/
          shortProp2 = TestCode.SHORT_1
      )
      class TestAnnotationValue_Groovy {
          Integer objectId
      }
      

       

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              souljungkim Sujung Kim
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: