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

JsonSlurper throws exception if reader does not fill complete char buffer

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.7
    • Fix Version/s: 2.3.8, 2.4.0-beta-4
    • Component/s: JSON
    • Labels:
      None
    • Flags:
      Patch

      Description

      The method JsonSlurper.parse(Reader) throws the following exception:

      groovy.json.JsonException: expecting '}' or ',' but got current char '' with an int value of 0
      
      The current character read is '' with an int value of 0
      

      if the reader does not always fill the complete char buffer at the method:

      public int read(char[] cbuf, int off, int len) throws IOException
      

      but returns a value < len on certain points.

      I have provided a test case at
      https://github.com/effrafax/jsonslurp

      A standard use case where this exception occurs:
      if you use a http-builder with JSON contentType where the server returns the response chunked (Transfer-Encoding: chunked). The InputStreamReader of the apache http client does not fill the complete char buffer at chunk borders.

        Attachments

        1. IO.diff
          0.6 kB
          Martin Stockhammer
        2. IOTest.groovy
          2 kB
          Martin Stockhammer

          Issue Links

            Activity

              People

              • Assignee:
                melix C├ędric Champeau
                Reporter:
                martin_s Martin Stockhammer
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: