File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
main/java/com/alibaba/fastjson
test/java/com/alibaba/json/bvt/bug Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -218,7 +218,11 @@ public static JSONObject parseObject(String text) {
218
218
return (JSONObject ) obj ;
219
219
}
220
220
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
+ }
222
226
}
223
227
224
228
/**
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments