groovy
  1. groovy
  2. GROOVY-4903

StackOverflowError when parsing JSON text with JsonSlurper().parseText()

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.0
    • Fix Version/s: 1.8.1, 1.9-beta-1
    • Component/s: JSON
    • Labels:
      None
    • Number of attachments :
      2

      Description

      The following code throws java.lang.StackOverflowError

      def jsonData = '{"messageId":1008,"messages":[{"id":"1005","urgency":"info","senderName":"Evgeny Goldin","date":"Saturday, June 25, 2011","time":"09:08","text":"aaaaaaaaaaa","sender":"evgenyg","timestamp":"1309003733376","longevity":168,"sendToAll":true,"sendToGroups":[],"sendToUsers":[],"usersDeleted":["evgenyg"]},{"id":"1006","urgency":"critical","senderName":"Evgeny Goldin","date":"Saturday, June 25, 2011","time":"09:11","text":"eeeeeeeeeeee","sender":"evgenyg","timestamp":"1309003888160","longevity":168,"sendToAll":true,"sendToGroups":[],"sendToUsers":[],"usersDeleted":["evgenyg"]},{"id":"1007","urgency":"warning","senderName":"Evgeny Goldin","date":"Saturday, June 25, 2011","time":"09:14","text":"<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>","sender":"evgenyg","timestamp":"1309004072795","longevity":168,"sendToAll":true,"sendToGroups":[],"sendToUsers":[],"usersDeleted":["evgenyg"]},{"id":"1008","urgency":"warning","senderName":"Evgeny Goldin","date":"Saturday, June 25, 2011","time":"09:16","text":"<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>","sender":"evgenyg","timestamp":"1309004197803","longevity":168,"sendToAll":true,"sendToGroups":[],"sendToUsers":[],"usersDeleted":["evgenyg"]}]}'
      
      new groovy.json.JsonSlurper().parseText( jsonData )
      
      
      Exception thrown
      Jun 26, 2011 3:18:23 PM org.codehaus.groovy.runtime.StackTraceUtils sanitize
      
      WARNING: Sanitizing stacktrace:
      
      java.lang.StackOverflowError
      
      	at java.util.regex.Pattern$8.isSatisfiedBy(Pattern.java:4783)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at jav
      a.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern
      $Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
      
      	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
      
      	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
      
      	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
      
      	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
      
      	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
      
      	at java.util.re
      
      1. messages-failed-to-load-1309112875059.json
        3 kB
        Evgeny Goldin
      2. search.json
        22 kB
        Kevin Shekleton

        Activity

        Hide
        Evgeny Goldin added a comment -

        For some reason I was only able to reproduce it once in GroovyConsole but I attached a file which I constantly fail to read by this code.

        Show
        Evgeny Goldin added a comment - For some reason I was only able to reproduce it once in GroovyConsole but I attached a file which I constantly fail to read by this code .
        Hide
        blackdrag blackdrag added a comment - - edited

        somehow I think this is not really a Groovy bug, but a bug in the JDK. This one here: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050507 sounds as it may be realted. In JBEHAVE-242 they have such a "bug" analyzed and worked around it. Maybe the same approach would work here as well. Basically we have to look for a (.|\s)* and replace it by .* - if that is the solution here as well

        Show
        blackdrag blackdrag added a comment - - edited somehow I think this is not really a Groovy bug, but a bug in the JDK. This one here: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050507 sounds as it may be realted. In JBEHAVE-242 they have such a "bug" analyzed and worked around it. Maybe the same approach would work here as well. Basically we have to look for a (.|\s)* and replace it by .* - if that is the solution here as well
        Hide
        Guillaume Laforge added a comment -

        By the way, which version of the JDK are you using?
        I tried to reproduce the problem, but it just worked for me on my Mac:

        java version "1.6.0_26"
        Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-9M3425)
        Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)
        
        Show
        Guillaume Laforge added a comment - By the way, which version of the JDK are you using? I tried to reproduce the problem, but it just worked for me on my Mac: java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-9M3425) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)
        Hide
        Guillaume Laforge added a comment -

        On Google App Engine, I had this JSON payload that was problematic:
        http://jfokus-schedule.appspot.com/json-backup/speakers.json
        But it's working on my laptop!

        Show
        Guillaume Laforge added a comment - On Google App Engine, I had this JSON payload that was problematic: http://jfokus-schedule.appspot.com/json-backup/speakers.json But it's working on my laptop!
        Hide
        Evgeny Goldin added a comment -

        It was 1.6.0_25, Windows x86 JDK. And I couldn't always reproduce it as well. It always failed when in application but hardly failed when in GroovyConsole.

        Show
        Evgeny Goldin added a comment - It was 1.6.0_25, Windows x86 JDK. And I couldn't always reproduce it as well. It always failed when in application but hardly failed when in GroovyConsole.
        Hide
        Evgeny Goldin added a comment -

        If nothing helps then I can try to provide you with an application where it happened to me, it's a TeamCity plugin so you may need to install and debug it.

        Show
        Evgeny Goldin added a comment - If nothing helps then I can try to provide you with an application where it happened to me, it's a TeamCity plugin so you may need to install and debug it.
        Hide
        Kevin Shekleton added a comment - - edited

        I'm attaching JSON that fails to be slurped on my machine.

        The following snippet demonstrates the issue (I ran this in GroovyConsole):

        def f = new File('search.json')
        def json = new groovy.json.JsonSlurper().parseText(f.text)
        

        The error this produces:

        Jul 19, 2011 9:04:35 AM org.codehaus.groovy.runtime.StackTraceUtils sanitize
        WARNING: Sanitizing stacktrace:
        java.lang.StackOverflowError
        	at java.util.regex.Pattern$CharProperty$1.isSatisfiedBy(Pattern.java:3337)
        	at java.util.regex.Pattern$8.isSatisfiedBy(Pattern.java:4783)
        	at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
        	at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
        	at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
        	at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
        	at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
        	at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
        ...this goes on for a long time
        

        My machine details:

        Mac OS X 10.6.8
        
        java -version
        java version "1.6.0_26"
        Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425)
        Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)
        

        edit: I should also note that I've moved off of use the classes in groovy.json.* as I cannot guarantee that any json I may receive from a web service can be parsed without error. I'm currently using json-lib and 'f.text as net.sf.json.JSON' which works every time.

        Show
        Kevin Shekleton added a comment - - edited I'm attaching JSON that fails to be slurped on my machine. The following snippet demonstrates the issue (I ran this in GroovyConsole): def f = new File('search.json') def json = new groovy.json.JsonSlurper().parseText(f.text) The error this produces: Jul 19, 2011 9:04:35 AM org.codehaus.groovy.runtime.StackTraceUtils sanitize WARNING: Sanitizing stacktrace: java.lang.StackOverflowError at java.util.regex.Pattern$CharProperty$1.isSatisfiedBy(Pattern.java:3337) at java.util.regex.Pattern$8.isSatisfiedBy(Pattern.java:4783) at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345) at java.util.regex.Pattern$Branch.match(Pattern.java:4114) at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168) at java.util.regex.Pattern$Loop.match(Pattern.java:4295) at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227) at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078) ...this goes on for a long time My machine details: Mac OS X 10.6.8 java -version java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode) edit: I should also note that I've moved off of use the classes in groovy.json.* as I cannot guarantee that any json I may receive from a web service can be parsed without error. I'm currently using json-lib and 'f.text as net.sf.json.JSON' which works every time.
        Hide
        Evgeny Goldin added a comment -

        Kevin's file fails for me as well.

        Windows 7 x64, Groovy 1.8.0 (GroovyConsole)

        java version "1.6.0_25"
        Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
        Java HotSpot(TM) Client VM (build 20.0-b11, mixed mode, sharing)
        
        Show
        Evgeny Goldin added a comment - Kevin's file fails for me as well. Windows 7 x64, Groovy 1.8.0 (GroovyConsole) java version "1.6.0_25" Java(TM) SE Runtime Environment (build 1.6.0_25-b06) Java HotSpot(TM) Client VM (build 20.0-b11, mixed mode, sharing)
        Hide
        Guillaume Laforge added a comment -

        I used the same approach as the issue JBehave had, by tweaking the regex and using DOTALL.

        It's weird the issue is not necessarily happening on all JDKs though.

        Show
        Guillaume Laforge added a comment - I used the same approach as the issue JBehave had, by tweaking the regex and using DOTALL. It's weird the issue is not necessarily happening on all JDKs though.
        Hide
        Sergey Bondarenko added a comment -

        I can still reproduce the issue. Please find real-world example (obfuscated unfortunately) for details:

        @Grab(group='net.sf.json-lib', module='json-lib', version='2.4', classifier="jdk15")
        import groovy.json.JsonSlurper
        import net.sf.json.JSONSerializer
        
        stackOverflowText = /{"a":[{"a":"{\"a\":[],\"a\":[],\"a\":[{\"a\":{\"a\":a,\"a\":a,\"a\":a,\"a\":a,\"a\":a,\"a\":a,\"a\":a,\"a\":a},\"a\":\"a\",\"a\":\"a.a.a\",\"a\":\"a\",\"a\":\"a-a\",\"a\":\"a.a.a.a\",\"a\":a,\"a\":{\"a-a\":{\"a\":\"a\"},\"a-a\":{\"a\":\"a\"},\"a-a\":{\"a\":\"a\"},\"a-a\":{\"a\":\"a\",\"a\":\"a\"},\"a\":{\"a\":\"a\"},\"a\":{\"a\":\"a\"},\"a\":{\"a\":\"a\"},\"a\":{\"a\":\"a\",\"a\":\"a\"},\"a\":{\"a\":\"a\"},\"a\":{\"a\":\"a\",\"a\":\"a\"},\"a-a\":{\"a\":\"a\"},\"a-a\":{\"a\":\"a\"},\"a-a\":{\"a\":\"a\"},\"a-a\":{\"a\":\"a\"},\"a-a\":{\"a\":\"a\",\"a\":\"a\"},\"a-a\":{\"a\":\"a\",\"a\":\"a\"},\"a-a\":{\"a\":\"a\",\"a\":\"a\"},\"a-a\":{\"a\":\"a\"},\"a\":{\"a\":\"a\"},\"a-a\":{\"a\":\"a\",\"a\":\"a\"},\"a-a\":{\"a\":\"a\",\"a\":\"a\"},\"a-a\":{\"a\":\"a\",\"a\":\"a\"},\"a-a\":{\"a\":\"a\"},\"a-a\":{\"a\":\"a\"},\"a-a\":{\"a\":\"a\"},\"a-a\":{\"a\":\"a\"},\"a-a\":{\"a\":\"a\"},\"a-a\":{\"a\":\"a\"},\"a-a\":{\"a\":\"a\"},\"a-a\":{\"a\":\"a\",\"a\":\"a\"}},\"a-a\":{},\"a\":[[{\"a\":\"a-a\",\"a\":\"a\",\"a\":a,\"a\":a,\"a\":\"a\",\"a\":\"a\",\"a\":[],\"a\":[],\"a\":\"a\",\"a\":a},{\"a\":\"a-a\",\"a\":\"a\",\"a\":a,\"a\":a,\"a\":\"a\",\"a\":\"a\",\"a\":[],\"a\":[],\"a\":\"a\",\"a\":a,\"a\":a,\"a\":[{\"a\":a,\"a\":\"a\"},{\"a\":a,\"a\":\"a\"},{\"a\":a,\"a\":\"a\"}]},{\"a\":\"a-a\",\"a\":\"a-a\",\"a\":a,\"a\":a,\"a\":\"a\",\"a\":\"a\",\"a\":[],\"a\":[],\"a\":\"a\",\"a\":a},{\"a\":\"a-a\",\"a\":\"a-a\",\"a\":a,\"a\":a,\"a\":\"a\",\"a\":\"a\",\"a\":[],\"a\":[],\"a\":\"a\",\"a\":a},{\"a\":\"a\",\"a\":\"a\",\"a\":a,\"a\":a,\"a\":\"a\",\"a\":\"a\",\"a\":[],\"a\":[],\"a\":\"a\",\"a\":a},{\"a\":\"a\",\"a\":\"a\",\"a\":a,\"a\":a,\"a\":\"a\",\"a\":\"a\",\"a\":[],\"a\":[],\"a\":\"a\",\"a\":a},{\"a\":\"a\",\"a\":\"a\",\"a\":a,\"a\":a,\"a\":\"a\",\"a\":\"a\",\"a\":[],\"a\":[],\"a\":\"a\",\"a\":a,\"a\":a,\"a\":[{\"a\":a,\"a\":\"a a a a\"},{\"a\":a,\"a\":\"a a\"},{\"a\":a,\"a\":\"a a a\"},{\"a\":a,\"a\":\"a a\"},{\"a\":a,\"a\":\"a a\"},{\"a\":a,\"a\":\"a a\"},{\"a\":a,\"a\":\"a\"},{\"a\":a,\"a\":\"a a\"},{\"a\":a,\"a\":\"a a\"}]},{\"a\":\"a\",\"a\":\"a\",\"a\":a,\"a\":a,\"a\":\"\"}]]}]}"}]}/
        
        println JSONSerializer.toJSON(stackOverflowText) // works properly
        new JsonSlurper().parseText(stackOverflowText)   // throws StackOverflowError
        
        Show
        Sergey Bondarenko added a comment - I can still reproduce the issue. Please find real-world example (obfuscated unfortunately) for details: @Grab(group='net.sf.json-lib', module='json-lib', version='2.4', classifier= "jdk15" ) import groovy.json.JsonSlurper import net.sf.json.JSONSerializer stackOverflowText = /{ "a" :[{ "a" : "{\" a\ ":[],\" a\ ":[],\" a\ ":[{\" a\ ":{\" a\ ":a,\" a\ ":a,\" a\ ":a,\" a\ ":a,\" a\ ":a,\" a\ ":a,\" a\ ":a,\" a\ ":a},\" a\ ":\" a\ ",\" a\ ":\" a.a.a\ ",\" a\ ":\" a\ ",\" a\ ":\" a-a\ ",\" a\ ":\" a.a.a.a\ ",\" a\ ":a,\" a\ ":{\" a-a\ ":{\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ ",\" a\ ":\" a\ "},\" a\ ":{\" a\ ":\" a\ "},\" a\ ":{\" a\ ":\" a\ "},\" a\ ":{\" a\ ":\" a\ "},\" a\ ":{\" a\ ":\" a\ ",\" a\ ":\" a\ "},\" a\ ":{\" a\ ":\" a\ "},\" a\ ":{\" a\ ":\" a\ ",\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ ",\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ ",\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ ",\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ "},\" a\ ":{\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ ",\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ ",\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ ",\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ "},\" a-a\ ":{\" a\ ":\" a\ ",\" a\ ":\" a\ "}},\" a-a\ ":{},\" a\ ":[[{\" a\ ":\" a-a\ ",\" a\ ":\" a\ ",\" a\ ":a,\" a\ ":a,\" a\ ":\" a\ ",\" a\ ":\" a\ ",\" a\ ":[],\" a\ ":[],\" a\ ":\" a\ ",\" a\ ":a},{\" a\ ":\" a-a\ ",\" a\ ":\" a\ ",\" a\ ":a,\" a\ ":a,\" a\ ":\" a\ ",\" a\ ":\" a\ ",\" a\ ":[],\" a\ ":[],\" a\ ":\" a\ ",\" a\ ":a,\" a\ ":a,\" a\ ":[{\" a\ ":a,\" a\ ":\" a\ "},{\" a\ ":a,\" a\ ":\" a\ "},{\" a\ ":a,\" a\ ":\" a\ "}]},{\" a\ ":\" a-a\ ",\" a\ ":\" a-a\ ",\" a\ ":a,\" a\ ":a,\" a\ ":\" a\ ",\" a\ ":\" a\ ",\" a\ ":[],\" a\ ":[],\" a\ ":\" a\ ",\" a\ ":a},{\" a\ ":\" a-a\ ",\" a\ ":\" a-a\ ",\" a\ ":a,\" a\ ":a,\" a\ ":\" a\ ",\" a\ ":\" a\ ",\" a\ ":[],\" a\ ":[],\" a\ ":\" a\ ",\" a\ ":a},{\" a\ ":\" a\ ",\" a\ ":\" a\ ",\" a\ ":a,\" a\ ":a,\" a\ ":\" a\ ",\" a\ ":\" a\ ",\" a\ ":[],\" a\ ":[],\" a\ ":\" a\ ",\" a\ ":a},{\" a\ ":\" a\ ",\" a\ ":\" a\ ",\" a\ ":a,\" a\ ":a,\" a\ ":\" a\ ",\" a\ ":\" a\ ",\" a\ ":[],\" a\ ":[],\" a\ ":\" a\ ",\" a\ ":a},{\" a\ ":\" a\ ",\" a\ ":\" a\ ",\" a\ ":a,\" a\ ":a,\" a\ ":\" a\ ",\" a\ ":\" a\ ",\" a\ ":[],\" a\ ":[],\" a\ ":\" a\ ",\" a\ ":a,\" a\ ":a,\" a\ ":[{\" a\ ":a,\" a\ ":\" a a a a\ "},{\" a\ ":a,\" a\ ":\" a a\ "},{\" a\ ":a,\" a\ ":\" a a a\ "},{\" a\ ":a,\" a\ ":\" a a\ "},{\" a\ ":a,\" a\ ":\" a a\ "},{\" a\ ":a,\" a\ ":\" a a\ "},{\" a\ ":a,\" a\ ":\" a\ "},{\" a\ ":a,\" a\ ":\" a a\ "},{\" a\ ":a,\" a\ ":\" a a\ "}]},{\" a\ ":\" a\ ",\" a\ ":\" a\ ",\" a\ ":a,\" a\ ":a,\" a\ ":\" \ "}]]}]}" }]}/ println JSONSerializer.toJSON(stackOverflowText) // works properly new JsonSlurper().parseText(stackOverflowText) // throws StackOverflowError
        Hide
        Sergey Bondarenko added a comment -

        The cause of the issue is (most of all) inefficient regexp groovy.json.JsonTokenType#STRING.
        I have prepared a patch that fixed the issue. Could you please review it?

        # HG changeset patch
        # User enterit
        # Date 1331596479 -7200
        # Node ID 7e7048d145315b6655c4182603512df7da5b6edb
        # Parent  3115bbd523ce0666f0f847def744229d6ef9cc5e
        JsonSlurper: fixed StackOverflowError that happened during parsing of long strings with backslashes.
        
        diff -r 3115bbd523ce -r 7e7048d14531 src/main/groovy/json/JsonTokenType.java
        --- a/src/main/groovy/json/JsonTokenType.java	Tue Mar 13 01:46:45 2012 +0200
        +++ b/src/main/groovy/json/JsonTokenType.java	Tue Mar 13 01:54:39 2012 +0200
        @@ -15,6 +15,8 @@
          */
         package groovy.json;
         
        +import groovy.lang.Closure;
        +
         import java.util.regex.Matcher;
         import java.util.regex.Pattern;
         
        @@ -35,7 +37,19 @@
             TRUE            ( "the constant 'true'",                "true"      ),
             FALSE           ( "the constant 'false'",               "false"     ),
             NUMBER          ( "a number",                           Pattern.compile("-?\\d+(\\.\\d+)?((e|E)(\\+|-)?\\d+)?")),
        -    STRING          ( "a string",                           Pattern.compile("\"([^\"\\\\]*|\\\\[\"\\\\bfnrt\\/]|\\\\u[0-9a-fA-F]{4})*\"", Pattern.DOTALL));
        +    //STRING          ( "a string",                           Pattern.compile("\"([^\"\\\\]*|\\\\[\"\\\\bfnrt\\/]|\\\\u[0-9a-fA-F]{4})*\"", Pattern.DOTALL));
        +    /**
        +     * Original pattern throws the StackOverflowError for long strings with backslashes.
        +     * So it is replaced by 2-step approach taken from json2.js sources: https://github.com/douglascrockford/JSON-js/blob/master/json2.js#L462
        +     * See {@link JsonTokenTypeTest#testMatchingLongStringWithBackslashes()} for details.
        +     */
        +    STRING          ( "a string",                           new Closure(null) {
        +        private Pattern replacePattern = Pattern.compile("(?:\\\\[\"\\\\bfnrt\\/]|\\\\u[0-9a-fA-F]{4})");
        +        private Pattern validatePattern = Pattern.compile("\"[^\"\\\\]*\"");
        +        boolean doCall(String it) {
        +            return validatePattern.matcher(replacePattern.matcher(it).replaceAll("@")).matches();
        +        }
        +    });
         
             /**
              * A String constant or a Pattern, serving as a validator for matching tokens.
        @@ -72,6 +86,8 @@
                 if (validator instanceof Pattern) {
                     Matcher matcher = ((Pattern)validator).matcher(input);
                     return matcher.matches();
        +        } else if (validator instanceof Closure) {
        +            return (Boolean)((Closure) validator).call(input);
                 } else if (validator instanceof String) {
                     return input.equals(validator);
                 } else {
        diff -r 3115bbd523ce -r 7e7048d14531 src/test/groovy/json/JsonTokenTypeTest.groovy
        --- a/src/test/groovy/json/JsonTokenTypeTest.groovy	Tue Mar 13 01:46:45 2012 +0200
        +++ b/src/test/groovy/json/JsonTokenTypeTest.groovy	Tue Mar 13 01:54:39 2012 +0200
        @@ -82,6 +82,10 @@
                 assert STRING.matching('"a\\""')
             }
         
        +    void testMatchingLongStringWithBackslashes() {
        +        assert STRING.matching('"a' + '\\"'*10000 + '"')
        +    }
        +
             void testTokenStartingWithChar() {
                 assert startingWith('{' as char)      == OPEN_CURLY
                 assert startingWith('}' as char)      == CLOSE_CURLY
        
        Show
        Sergey Bondarenko added a comment - The cause of the issue is (most of all) inefficient regexp groovy.json.JsonTokenType#STRING. I have prepared a patch that fixed the issue. Could you please review it? # HG changeset patch # User enterit # Date 1331596479 -7200 # Node ID 7e7048d145315b6655c4182603512df7da5b6edb # Parent 3115bbd523ce0666f0f847def744229d6ef9cc5e JsonSlurper: fixed StackOverflowError that happened during parsing of long strings with backslashes. diff -r 3115bbd523ce -r 7e7048d14531 src/main/groovy/json/JsonTokenType.java --- a/src/main/groovy/json/JsonTokenType.java Tue Mar 13 01:46:45 2012 +0200 +++ b/src/main/groovy/json/JsonTokenType.java Tue Mar 13 01:54:39 2012 +0200 @@ -15,6 +15,8 @@ */ package groovy.json; +import groovy.lang.Closure; + import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -35,7 +37,19 @@ TRUE ( "the constant 'true'", "true" ), FALSE ( "the constant 'false'", "false" ), NUMBER ( "a number", Pattern.compile("-?\\d+(\\.\\d+)?((e|E)(\\+|-)?\\d+)?")), - STRING ( "a string", Pattern.compile("\"([^\"\\\\]*|\\\\[\"\\\\bfnrt\\/]|\\\\u[0-9a-fA-F]{4})*\"", Pattern.DOTALL)); + //STRING ( "a string", Pattern.compile("\"([^\"\\\\]*|\\\\[\"\\\\bfnrt\\/]|\\\\u[0-9a-fA-F]{4})*\"", Pattern.DOTALL)); + /** + * Original pattern throws the StackOverflowError for long strings with backslashes. + * So it is replaced by 2-step approach taken from json2.js sources: https://github.com/douglascrockford/JSON-js/blob/master/json2.js#L462 + * See {@link JsonTokenTypeTest#testMatchingLongStringWithBackslashes()} for details. + */ + STRING ( "a string", new Closure(null) { + private Pattern replacePattern = Pattern.compile("(?:\\\\[\"\\\\bfnrt\\/]|\\\\u[0-9a-fA-F]{4})"); + private Pattern validatePattern = Pattern.compile("\"[^\"\\\\]*\""); + boolean doCall(String it) { + return validatePattern.matcher(replacePattern.matcher(it).replaceAll("@")).matches(); + } + }); /** * A String constant or a Pattern, serving as a validator for matching tokens. @@ -72,6 +86,8 @@ if (validator instanceof Pattern) { Matcher matcher = ((Pattern)validator).matcher(input); return matcher.matches(); + } else if (validator instanceof Closure) { + return (Boolean)((Closure) validator).call(input); } else if (validator instanceof String) { return input.equals(validator); } else { diff -r 3115bbd523ce -r 7e7048d14531 src/test/groovy/json/JsonTokenTypeTest.groovy --- a/src/test/groovy/json/JsonTokenTypeTest.groovy Tue Mar 13 01:46:45 2012 +0200 +++ b/src/test/groovy/json/JsonTokenTypeTest.groovy Tue Mar 13 01:54:39 2012 +0200 @@ -82,6 +82,10 @@ assert STRING.matching('"a\\""') } + void testMatchingLongStringWithBackslashes() { + assert STRING.matching('"a' + '\\"'*10000 + '"') + } + void testTokenStartingWithChar() { assert startingWith('{' as char) == OPEN_CURLY assert startingWith('}' as char) == CLOSE_CURLY
        Hide
        Guillaume Laforge added a comment -

        I've committed those changes.
        I haven't been able to test the behavior locally, but I trust you that it works well with the patch you prepared.
        Thanks for finding that out.

        Show
        Guillaume Laforge added a comment - I've committed those changes. I haven't been able to test the behavior locally, but I trust you that it works well with the patch you prepared. Thanks for finding that out.
        Hide
        Steven Ruppert added a comment -

        I can still reproduce this bug with Groovy 1.8.6 on

        java version "1.6.0_24"
        OpenJDK Runtime Environment (IcedTea6 1.11.1) (6b24-1.11.1-4ubuntu3)
        OpenJDK Client VM (build 20.0-b12, mixed mode, sharing)

        JSON with long strings (in my case, raw MIME email messages) seems to cause a StackOverflowException more often.

        Why does the JSON slurper use regex at all? Implementing a custom parser wuold be trivial, and would get around the JDK regex's WONTFIX bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050507

        Show
        Steven Ruppert added a comment - I can still reproduce this bug with Groovy 1.8.6 on java version "1.6.0_24" OpenJDK Runtime Environment (IcedTea6 1.11.1) (6b24-1.11.1-4ubuntu3) OpenJDK Client VM (build 20.0-b12, mixed mode, sharing) JSON with long strings (in my case, raw MIME email messages) seems to cause a StackOverflowException more often. Why does the JSON slurper use regex at all? Implementing a custom parser wuold be trivial, and would get around the JDK regex's WONTFIX bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050507
        Hide
        Guillaume Laforge added a comment -

        If it's trivial and as efficient and passes all the tests, feel free to submit a patch

        Show
        Guillaume Laforge added a comment - If it's trivial and as efficient and passes all the tests, feel free to submit a patch
        Hide
        Paul Hammant added a comment -

        This is still a defect in Groovy 2.0 - right ?

        Try this .......

        import groovy.json.JsonSlurper

        def doData(data) {
        def children = data.children
        if (children != null)

        { doChildren(children) }

        def replies = data.replies
        if (replies != null)

        { doReplies(replies) }

        def body = data.body
        if (body != null)

        { doBody(body) }

        }

        def doChildren(children) {
        def data = children.data
        if (data != null)

        { doData(data) }
        }

        def doReplies(replies) {
        def data = replies.data
        if (data != null) { doData(data) }

        }

        def doBody(body)

        { println "yay" }

        File dir = new File('.')
        JsonSlurper jsonSlurper = new JsonSlurper();

        URL url = new URL("http://www.reddit.com/r/programming/comments/vtuii/why_files_exist.json");

        InputStream urlStream = null;
        try {
        urlStream = url.openStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(urlStream));
        def doc = jsonSlurper.parse(reader)
        doc.each { it ->
        def d = it.data;
        if (d != null)

        { doData(d) }

        }
        } finally

        { urlStream.close(); }
        Show
        Paul Hammant added a comment - This is still a defect in Groovy 2.0 - right ? Try this ....... import groovy.json.JsonSlurper def doData(data) { def children = data.children if (children != null) { doChildren(children) } def replies = data.replies if (replies != null) { doReplies(replies) } def body = data.body if (body != null) { doBody(body) } } def doChildren(children) { def data = children.data if (data != null) { doData(data) } } def doReplies(replies) { def data = replies.data if (data != null) { doData(data) } } def doBody(body) { println "yay" } File dir = new File('.') JsonSlurper jsonSlurper = new JsonSlurper(); URL url = new URL("http://www.reddit.com/r/programming/comments/vtuii/why_files_exist.json"); InputStream urlStream = null; try { urlStream = url.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(urlStream)); def doc = jsonSlurper.parse(reader) doc.each { it -> def d = it.data; if (d != null) { doData(d) } } } finally { urlStream.close(); }

          People

          • Assignee:
            Guillaume Laforge
            Reporter:
            Evgeny Goldin
          • Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: