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

Annotations on a local variable crash GroovyC

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.3
    • 1.5.5, 1.6-beta-1
    • ast builder
    • None

    Description

      Java allows annotations on local variables, as well as the Groovy Grammer, but the compiler crashes with a NPE.

      this class is fine in Java, craashes Groovy
      class Test {
      public void testMe()

      { @SuppressWarnings("None") String s = ""; }

      }

      With the following (1.5.3) stack trace...
      BUG! exception in phase 'conversion' in source unit 'script1203044831759.groovy' null
      at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:776)
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:438)
      at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:277)
      at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:248)
      at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:243)
      at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:205)
      at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:215)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:226)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:899)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:740)
      at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:765)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:753)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:167)
      at groovy.grape.GrapeClassLoaderTest.testScriptFieldAnnotation(GrapeClassLoaderTest.groovy:75)
      Caused by: java.lang.NullPointerException
      at org.codehaus.groovy.antlr.AntlrParserPlugin.modifiers(AntlrParserPlugin.java:783)
      at org.codehaus.groovy.antlr.AntlrParserPlugin.declarationExpression(AntlrParserPlugin.java:1077)
      at org.codehaus.groovy.antlr.AntlrParserPlugin.variableDef(AntlrParserPlugin.java:1108)
      at org.codehaus.groovy.antlr.AntlrParserPlugin.statement(AntlrParserPlugin.java:900)
      at org.codehaus.groovy.antlr.AntlrParserPlugin.convertGroovy(AntlrParserPlugin.java:225)
      at org.codehaus.groovy.antlr.AntlrParserPlugin.buildAST(AntlrParserPlugin.java:183)
      at org.codehaus.groovy.control.SourceUnit.convert(SourceUnit.java:282)
      at org.codehaus.groovy.control.CompilationUnit$7.call(CompilationUnit.java:547)
      at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:772)

      The error appears to be the call to modifiers in declerationExpression that passes a null for the List of annotations. Providing a list is only half the battle, as the bytecode (likely an attribute or section in the class file, don't ask me I'm not the JVM expert) for the annotation must also be generated.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            shemnon Daniel Ferrin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: