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

each(){} throws NPE when called on a Java Object[], that contains String[]'s with null entries

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-JSR-1
    • 1.0-JSR-3
    • 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()

      { assert it}

      // 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())

      { assert someArrayOfStringArrays[i] }

      }
      }

      The above TestCase will be committed.

      Attachments

        Issue Links

          Activity

            People

              phkim Kim, Pilho
              codevise Dierk König
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: