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

JsonSlurper throws exception if reader does not fill complete char buffer

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.7
    • 2.3.8, 2.4.0-beta-4
    • JSON
    • None
    • 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. IOTest.groovy
          2 kB
          Martin Schreier
        2. IO.diff
          0.6 kB
          Martin Schreier

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            melix Cédric Champeau
            martin_s Martin Schreier
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment