groovy

Annotations on a local variable crash GroovyC

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.5.3
  • Fix Version/s: 1.5.5, 1.6-beta-1
  • Component/s: ast builder
  • Labels:
    None
  • Testcase included:
    yes
  • Number of attachments :
    0

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.

Activity

Hide
blackdrag blackdrag added a comment -

I added a work around for this in 1.6, but the annotation will be lost.

Show
blackdrag blackdrag added a comment - I added a work around for this in 1.6, but the annotation will be lost.
Hide
blackdrag blackdrag added a comment -

done

Show
blackdrag blackdrag added a comment - done

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: