Groovy
  1. Groovy
  2. GROOVY-4732

Java5 configureClassNode does not take care of parameter annotations

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.8.1, 1.7.11
    • Component/s: Compiler
    • Labels:
      None
    • Flags:
      Patch

      Description

      whenever annotation parameters are specified in byte-code, the Java5 vm-plugin does not include those annotations as AnnotationNode instances when configuring a ClassNode for that particular class.

      the following code is from a local test-case:

      void testParameterAnnotation() { 
      
              GroovyClassLoader gcl = new GroovyClassLoader() 
      
              gcl.parseClass """ 
                  import java.lang.annotation.* 
      
                  @Target(ElementType.METHOD) 
                  @Retention(RetentionPolicy.RUNTIME) 
                  @interface MethodAnnotation {} 
      
                  @Target(ElementType.PARAMETER) 
                  @Retention(RetentionPolicy.RUNTIME) 
                  @interface ParameterAnnotation {} 
      
                  interface MyInterface { 
                      @MethodAnnotation 
                      def method(@ParameterAnnotation def param) 
                  } 
              """ 
      
              GroovyCodeSource codeSource = new GroovyCodeSource(""" 
                  class MyInterfaceImpl implements MyInterface { 
                      def method(def param) {} 
                  } 
              """, "script" + System.currentTimeMillis() + ".groovy", "/groovy/script") 
      
              CompilationUnit cu = new CompilationUnit(CompilerConfiguration.DEFAULT, codeSource.codeSource, gcl) 
              cu.addSource(codeSource.getName(), codeSource.scriptText); 
              cu.compile(CompilePhase.FINALIZATION.phaseNumber) 
      
              def classNode = cu.getClassNode("MyInterfaceImpl") 
              def interfaceClassNode = classNode.getInterfaces().find { it.nameWithoutPackage == 'MyInterface' } 
      
              def methodNode = interfaceClassNode.getDeclaredMethods("method")[0] 
      
              // check if the AnnotationNode for 'MethodAnnotation' has been created 
              assert methodNode.getAnnotations().any { AnnotationNode an -> an.classNode.nameWithoutPackage == 'MethodAnnotation' } 
              
              // this one will fail, since parameter annotations are ignored by Java5Plugin (and above) 
              assert methodNode.getParameters()[0].getAnnotations().any { AnnotationNode an -> an.classNode.nameWithoutPackage == 'ParameterAnnotation' } 
      }
      

        Activity

        Andre Steingress created issue -
        Jochen Theodorou made changes -
        Field Original Value New Value
        Assignee Jochen Theodorou [ blackdrag ]
        Fix Version/s 1.7.11 [ 17244 ]
        Fix Version/s 1.8.1 [ 17223 ]
        Hide
        Jochen Theodorou added a comment -

        I make this blocker only because I want to ensure it gets in the next release, not because the issue is fatal

        Show
        Jochen Theodorou added a comment - I make this blocker only because I want to ensure it gets in the next release, not because the issue is fatal
        Jochen Theodorou made changes -
        Priority Major [ 3 ] Blocker [ 1 ]
        Jochen Theodorou made changes -
        Priority Blocker [ 1 ] Major [ 3 ]
        Hide
        Jochen Theodorou added a comment -

        patch applied, thanks for providing it

        Show
        Jochen Theodorou added a comment - patch applied, thanks for providing it
        Jochen Theodorou made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12733662 ] Default workflow, editable Closed status [ 12745475 ]
        Mark Thomas made changes -
        Flags Patch [ 10430 ]
        Patch Submitted Yes [ 10763 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12973524 ] Default workflow, editable Closed status [ 12980709 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Closed Closed
        119d 8m 1 Jochen Theodorou 14/Jul/11 11:34

          People

          • Assignee:
            Jochen Theodorou
            Reporter:
            Andre Steingress
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development