Json matcher throw NullPointerException when check root element when children element contain some null value

42 views
Skip to first unread message

Mike Chen

unread,
Feb 21, 2015, 6:50:21 AM2/21/15
to specs2...@googlegroups.com
private val msg4: String = """{"code":0,"data":null}"""  //OK
private val msg5: String = """{"code":0,"data":[{"test": null}]}"""  //NPE
private val msg6: String = """{"code":0,"data":[{"test": "aaa"}]}"""  //OK
private val msg7: String = """{"code":0,"data":[{"test": "aaa", "t2": null}]}"""  //NPE
private val msg8: String = """{"code":0,"data":{"test": "aaa", "t2": null}}"""  //NPE


def testEquals = {
 
try {
    msg
(4~8) must /("code" -> 0.0)  //msg(4~8) means msg4, msg5, ..,msg8
 
} catch {
   
case e:NullPointerException => {
      e
.printStackTrace()
     
throw e
   
}
 
}

As comment that in the end of msg string shown, Some string will occure NPE when check root element that "code" equals 0(as code shown).

The json string is well format, and test code is match the specs2 reference, so maybe is this a bug?

I am newbie to scala, so to trace the code is too slow, can anybody help me to find the solution? Thanks.






etorreborre

unread,
Feb 22, 2015, 3:42:22 PM2/22/15
to specs2...@googlegroups.com
Hi Mike,

Which version are you using? This is indeed a bug but it is fixed in 2.4.16 (I think it was fixed in 2.4.12).

Eric.

Mike Chen

unread,
Feb 24, 2015, 3:35:33 AM2/24/15
to specs2...@googlegroups.com
thanks for reply, etorreborre.


I was use Specs2 in Scalatra_2.3.0 with its default sbt dependency,maybe specs is 2.3.12.

I just update specs2 to 2.4.16 manual and the problem is resolved.

Sorry for my carelessness, I have not try the specs2 newer version .



Thanks again.
Reply all
Reply to author
Forward
0 new messages