3

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

user1083319
  • 31
  • 1
  • 1
  • 2

2 Answers2

4

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.

ziesemer
  • 27,712
  • 8
  • 86
  • 94
  • I wouldn't know how I would do this. I am not doing any fancy math at all. Can division by 0 lead to this? – user1083319 Dec 06 '11 at 11:04
  • Yes - as long as you're using floats or doubles. – ziesemer Dec 06 '11 at 11:06
  • I do use doubles at one point and I do divisions. I would have expected an exception related to division by zero when I actually do the division. – user1083319 Dec 06 '11 at 11:11
  • If you're using non-floating types, e.g. integers, then you will get an exception - but not with floats / doubles. – ziesemer Dec 06 '11 at 11:13
  • Hello i have the same issue , i am not trying to represent any integers, doubles/floats. My complete value is a string. Even though i have numbers those are of type string. Can somebody help me out? – Shaik Mujahid Ali Jan 27 '16 at 09:48
0

In my similar case, I had a finite number divided by zero, which leads to infinite number. Check your calculations.

Ville Laitila
  • 1,187
  • 11
  • 18