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

Java stub generator does not set correct value for annotations that expect a Class as a value

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.6
    • 1.7.6, 1.8-beta-3
    • Compiler
    • None
    • Patch

    Description

      This issue is related to http://jira.codehaus.org/browse/GROOVY-4434.

      If an annotation expects a class (not a classname, but a class) as its value, the java stub compiler does not seem to write out the java stub annotation value correctly. Here is some groovy code that shows an example:

      <code>
      import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
      @RunWith(SpringJUnit4ClassRunner.class)
      class someClass{
      ...
      }
      </code>

      The @RunWith annotation expects an actual class (not a class name) as its parameter.

      In the above mentioned issue, the annotation value is at least expanded to a fully qualified class name. Using the 1.7.6-SNAPSHOT (which includes the patch from GROOVY-4434), I can confirm the classname is expanded. However, this is the output of the java file the stub compiler creates:

      <code>
      @org.junit.runner.RunWith(value=org.springframework.test.context.junit4.SpringJUnit4ClassRunner)
      class someClass{
      ...
      }
      </code>

      The trouble is that then javac chokes since org.springframework.test.context.junit4.SpringJUnit4ClassRunner is not an actual class reference. Interestingly, groovyc handles this same code just fine, but javac expects the .class suffix to make the class reference explicit. Thus, the generated code does not compile.

      I have attached a very simple patch which seems to address this issue. I do not know, however if this might break something else.

      Attachments

        1. classannotation.diff
          0.6 kB
          Yoel Spotts

        Issue Links

          Activity

            People

              roshandawrani Roshan Dawrani
              yoelspotts Yoel Spotts
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: