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

JsonSlurper in 2.3 returns LazyMap which is not thread safe for multiple reads

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Information Provided
    • 2.3.4
    • None
    • JSON
    • None
    • Linux

    Description

      We recently upgraded one of our systems from Groovy 2.1 to Groovy 2.3. This went mostly without any issues which was great. We did have one issue which caused us a bit of grief. It seems that groovy 2.3 changed the type of map that the JsonSlurper returns from the default HashMap to a LazyMap. Looking at the implementation of LazyMap, it's not thread safe for multiple reads. We are seeing multiple null pointer exceptions in our logs, which result from the fact that the map is lazily constructed by multiple threads, and the first thread to finish nulls the keys and values. (There are also other concurrency bugs there).

      I am attaching a test case that demonstrates this. It works fine in groovy 2.2 and 2.1, but gets a null pointer in 2.3.

      I'd consider this a very serious breaking change. Only reference of this change I can find is here:

      http://marc.info/?t=139063532100001&r=1&w=2

      While we can about concurrency semantics, I would expect data that was read of the wire to be readable by multiple threads, and groovy up to version 2.2 did offer this behaviour.

      Thank you,

      Stefanos Zachariadis

      LMAX

      Attachments

        1. MapBug.groovy
          1 kB
          Stefanos Zachariadis

        Issue Links

          Activity

            People

              Unassigned Unassigned
              rohirrim Stefanos Zachariadis
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: