Find root cause of "net.sf.json.JSONException: JSON does not allow non-finite numbers"

user1083319 picture user1083319 · Dec 6, 2011 · Viewed 9.7k times · Source

I am creating a relatively complex and large structure encoded in json to send to a Web service. I use plain java and Apache Wink for JSON. Most requests go well but in one particular case I receive the following error:

net.sf.json.JSONException: JSON does not allow non-finite numbers
at net.sf.json.util.JSONUtils.testValidity(JSONUtils.java:586)
at net.sf.json.JSONObject._processValue(JSONObject.java:2786)
at net.sf.json.JSONObject._setInternal(JSONObject.java:2817)
at net.sf.json.JSONObject.setValue(JSONObject.java:1527)
at net.sf.json.JSONObject._fromBean(JSONObject.java:946)
at net.sf.json.JSONObject.fromObject(JSONObject.java:194)
at net.sf.json.JSONArray._processValue(JSONArray.java:2562)
at net.sf.json.JSONArray.processValue(JSONArray.java:2593)
at net.sf.json.JSONArray.addValue(JSONArray.java:2580)
at net.sf.json.JSONArray._fromCollection(JSONArray.java:1084)
at net.sf.json.JSONArray.fromObject(JSONArray.java:147)
at net.sf.json.JSONObject._processValue(JSONObject.java:2768)
at net.sf.json.JSONObject._setInternal(JSONObject.java:2817)
at net.sf.json.JSONObject.setValue(JSONObject.java:1527)
at net.sf.json.JSONObject._fromBean(JSONObject.java:946)
at net.sf.json.JSONObject.fromObject(JSONObject.java:194)
at net.sf.json.JSONArray._processValue(JSONArray.java:2562)
at net.sf.json.JSONArray.processValue(JSONArray.java:2593)
at net.sf.json.JSONArray.addValue(JSONArray.java:2580)
at net.sf.json.JSONArray._fromCollection(JSONArray.java:1084)
at net.sf.json.JSONArray.fromObject(JSONArray.java:147)
at net.sf.json.JSONObject._processValue(JSONObject.java:2768)
at net.sf.json.JSONObject._setInternal(JSONObject.java:2817)
at net.sf.json.JSONObject.setValue(JSONObject.java:1527)
at net.sf.json.JSONObject._fromBean(JSONObject.java:946)
at net.sf.json.JSONObject.fromObject(JSONObject.java:194)
at net.sf.json.JSONObject.fromObject(JSONObject.java:156)
at com.ibm.arc.sdm2pmp.wsclient.WSClient.createStaffingPlan(WSClient.java:693)
at com.ibm.arc.sdm2pmp.wsclient.WSClient.sendToPMP(WSClient.java:174)
at com.ibm.arc.sdm2pmp.Gateway.processCase(Gateway.java:129)
at com.ibm.arc.sdm2pmp.Gateway.main(Gateway.java:283)

I encode the whole structure at once (about 10 MB) and I have a problem finding out what leads to this weird exception. I was searching the Web but couldn't get beyond the obvious. (don't send non-finite numbers).

Do you know how best to debug this and what might typically lead to it?

Your help is highly appreciated.

Heiko

Answer

ziesemer picture ziesemer · Dec 6, 2011

You're probably trying to represent a value such as Double.POSITIVE_INFINITY or another non-finite number, which isn't allowed per the JSON specification.