groovy

NPE executing Collection.toArray( new String[ foo.size() ] )

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0-JSR-5
  • Fix Version/s: 1.0-JSR-6
  • Component/s: None
  • Labels:
    None
  • Environment:
    Sun j2se 1.4.2_04 on Microsoft Windows XP Pro and BEA WebLogic Server 8.1SP3
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

The following script blows up with a NPE:

def foo = [ 'aa', 'bb', 'cc' ]
def goo = foo.toArray( new String[ foo.size() ] )

Here is a stack trace:

java.lang.NullPointerException
at java.util.ArrayList.toArray(ArrayList.java:301)
at gjdk.java.util.ArrayList_GroovyReflector.invoke(Unknown Source)
at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassH
elper.java:636)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:345)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:144)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.
java:104)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(Script
BytecodeAdapter.java:85)
at Script1.run(Script1.groovy:2)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:521)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:496)

This NPE does not show up with Groovy 1.0-jsr-04.

It appears to be a regression in 1.0-jsr-05 for sure.

Here is the junit test.
import groovy.lang.Binding;
import groovy.lang.GroovyShell;

public void testGroovyArray()

{ Binding binding = new Binding(); GroovyShell shell = new GroovyShell( binding ); binding.setVariable( "goo", new String[0] ); StringBuffer script = new StringBuffer(); script.append( "def foo = [ 'aa', 'bb', 'cc' ]\n" ); script.append( "def goo = foo.toArray( new String[ foo.size() ] )\n" ); Object value = shell.evaluate( script.toString() ); assertTrue( value instanceof String[] ); assertTrue( ((String[])value).length == 3 ); }

Activity

Hide
Ben Eng added a comment -

Oops, I missed a "return goo" in the script for the test case, of course.

Show
Ben Eng added a comment - Oops, I missed a "return goo" in the script for the test case, of course.
Hide
blackdrag blackdrag added a comment -

this is fixed for the next release

Show
blackdrag blackdrag added a comment - this is fixed for the next release

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: