Skip to content

Commit 10a21cd

Browse files
committed
bug fixed for issue alibaba#1296
1 parent 5a59b8a commit 10a21cd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/main/java/com/alibaba/fastjson/JSON.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,11 @@ public static JSONObject parseObject(String text) {
218218
return (JSONObject) obj;
219219
}
220220

221-
return (JSONObject) JSON.toJSON(obj);
221+
try {
222+
return (JSONObject) JSON.toJSON(obj);
223+
} catch (RuntimeException e) {
224+
throw new JSONException("can not cast to JSONObject.", e);
225+
}
222226
}
223227

224228
/**
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.alibaba.json.bvt.bug;
2+
3+
import com.alibaba.fastjson.JSON;
4+
import com.alibaba.fastjson.JSONException;
5+
import junit.framework.TestCase;
6+
7+
/**
8+
* Created by wenshao on 02/07/2017.
9+
*/
10+
public class Issue1296 extends TestCase {
11+
public void test_for_issue() throws Exception {
12+
Exception error = null;
13+
try {
14+
JSON.parseObject("1");
15+
} catch (JSONException e) {
16+
error = e;
17+
}
18+
assertNotNull(error);
19+
}
20+
}

0 commit comments

Comments
 (0)