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
        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: