Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0-JSR-1
-
None
-
None
Description
Say you have a Java Class like
public class SomeClass {
public Object[] anArrayOfStringArraysWorkaround(){
return new Object[]{ new String[]{"whatever",null}};
}
}
then the following Groovy code fails with NPE
public class MultiDimArraysTest extends GroovyTestCase {
void testCallTwoDimStringArrayWorkaroundWithNull(){
def someArrayOfStringArrays = new SomeClass().anArrayOfStringArraysWorkaround()
assert 1 == someArrayOfStringArrays.size()
assert "whatever" == someArrayOfStringArrays[0][0]
someArrayOfStringArrays.each()
// throws NPE !!
}
}
while the iteration with "for" works:
public class MultiDimArraysTest extends GroovyTestCase {
void testCallTwoDimStringArrayWorkaround(){
def someArrayOfStringArrays = new SomeClass().anArrayOfStringArraysWorkaround()
assert 1 == someArrayOfStringArrays.size()
assert "whatever" == someArrayOfStringArrays[0][0]
for (i in 0..<someArrayOfStringArrays.size())
}
}
The above TestCase will be committed.
Attachments
Issue Links
- duplicates
-
GROOVY-584 Exception passing array into Closure
- Closed
- is depended upon by
-
GROOVY-764 closures
- Closed
- is duplicated by
-
GROOVY-888 Object[] vs int[]
- Closed