LANGUAGE/!$%!% ERROR NOTE 2021. 5. 2. 15:56

Groovy

Bug Report

1. Error - 오류

이전에는 Annotation Interface를 정의 할 때 문제가 발생했었는데 (https://issues.apache.org/jira/browse/GROOVY-6025)

이번 Error는 Annotation을 적용하고 short값을 정의 할 때 문제가 발생한다.

Test해 본 결과, 2.5.4 버전부터 발생하는 것으로 보인다. ㅠ_ㅠ

\\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
  • 동작하는 버전

    • Groovy between 2.1.3 and 2.5.3 (tested by 2.1.3 / 2.4.13 / 2.5.3)
  • 동작하지 않는 버전

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

2. Problem - 문제

버그 같다. 또는 지원하지 않을 것 같다.

3. Not Solved - 미해결

short을 사용하지 않고 int로 우회해서 사용해야 할 것 같다.

개인적으로 이건 꼭 개선되었으면 해서 Groovy Jira에 찾아가서 report를 남겼다.

Test Code

Groovy 개발자님들이 해결해주시길 간절하게 바라며..

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,
        intProp3 = 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,

        /**
         * [SOLUTION 2.1.3 ~ 2.5.3]  Defining as an already defined short 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,

        /**
         * [SOLUTION 2.5.4 ~ ..]  Defining as an already defined short variable
         *  - It works since Groovy 2.5.4
         *  - But, It does not works before Groovy 2.5.4.
         **/
        intProp3 = TestCode.SHORT_1
)
class TestAnnotationValue_Groovy {

    Integer objectId

}

4. Reference - 참조