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

NullPointer Exception introduced in 2.3.1 and greater with JsonSlurper

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.1, 2.3.2, 2.3.3, 2.3.4, 2.3.5, 2.3.6, 2.3.7, 2.3.8, 2.3.9, 2.4.0-rc-1
    • None
    • JSON
    • None
    • OS: Ubuntu 14.04 LTS
      Java: JDK 1.7.0_65, vendor: Oracle Corporation 24.65-b04
      Gradle 2.2.1

      OS: Ubuntu 12.04 LTS
      Java version: JDK 1.7.0_72, vendor: Oracle Corporation
      Gradle 2.2.1

    Description

      When traversing a HashMap that was created from a parsed JSON file my unit tests start failing on Groovy versions 2.3.1 and later. There seems to be some sort of regression introduced.

      To explore and debug this problem you may view my travis builds testing the latest versions of Groovy from 1.8.9 through 2.3.9.

      https://travis-ci.org/samrocketman/jervis/builds/45526838

      If you would like to check out and debug the problem yourself you can do the following:

      git clone https://github.com/samrocketman/jervis.git
      cd jervis
      git checkout 2590bf2be5f8f2aaa1a25bcd63912506059da8c7
      #passing build
      GROOVY_VERSION="2.3.0" ./gradlew check
      #first failing build
      GROOVY_VERSION="2.3.1" ./gradlew check

      gradlew check will automatically download Gradle 2.2.1, download the version of Groovy requested, assemble dependencies, compile, and execute unit tests.

      [EDIT by blackdrag]
      the issue can be reduced to this test

      import groovy.json.JsonSlurper
      def jsonSlurper = new JsonSlurper() 
      def object = jsonSlurper.parseText('{ "o": {"name":"John Doe" }}')
      assert object instanceof Map
      assert object.o instanceof Map
      assert object.o.name == "John Doe"
      assert object.o[null] == null
      

      the code is confirmed to work on 1.8.9 and in several versions of 2.0, 2.1 and 2.2. It seems to start failing in 2.3 (first tested version was 2.3.1)

      Attachments

        Activity

          People

            Unassigned Unassigned
            samrocketman Sam Gleske
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: