@@ -1973,13 +1973,7 @@ public void jsonObjectParsingErrors() {
1973
1973
"Null pointer" ,
1974
1974
e .getMessage ());
1975
1975
}
1976
- try {
1977
- // null put key
1978
- JSONObject jsonObject = new JSONObject ("{}" );
1979
- jsonObject .put (null , 0 );
1980
- fail ("Expected an exception" );
1981
- } catch (NullPointerException ignored ) {
1982
- }
1976
+
1983
1977
try {
1984
1978
// multiple putOnce key
1985
1979
JSONObject jsonObject = new JSONObject ("{}" );
@@ -2182,6 +2176,10 @@ public void jsonObjectPutOnceNull() {
2182
2176
JSONObject jsonObject = new JSONObject ();
2183
2177
jsonObject .putOnce (null , null );
2184
2178
assertTrue ("jsonObject should be empty" , jsonObject .length () == 0 );
2179
+ jsonObject .putOnce ("" , null );
2180
+ assertTrue ("jsonObject should be empty" , jsonObject .length () == 0 );
2181
+ jsonObject .putOnce (null , "" );
2182
+ assertTrue ("jsonObject should be empty" , jsonObject .length () == 0 );
2185
2183
}
2186
2184
2187
2185
/**
@@ -2453,7 +2451,7 @@ public void write() throws IOException {
2453
2451
* Confirms that exceptions thrown when writing values are wrapped properly.
2454
2452
*/
2455
2453
@ Test
2456
- public void testJSONWriterException () throws IOException {
2454
+ public void testJSONWriterException () {
2457
2455
final JSONObject jsonObject = new JSONObject ();
2458
2456
2459
2457
jsonObject .put ("someKey" ,new BrokenToString ());
@@ -2893,4 +2891,62 @@ public void testExceptionalBean() {
2893
2891
assertTrue (jo .get ("closeable" ) instanceof JSONObject );
2894
2892
assertTrue (jo .getJSONObject ("closeable" ).has ("string" ));
2895
2893
}
2894
+
2895
+ @ Test (expected =NullPointerException .class )
2896
+ public void testPutNullBoolean () {
2897
+ // null put key
2898
+ JSONObject jsonObject = new JSONObject ("{}" );
2899
+ jsonObject .put (null , false );
2900
+ fail ("Expected an exception" );
2901
+ }
2902
+ @ Test (expected =NullPointerException .class )
2903
+ public void testPutNullCollection () {
2904
+ // null put key
2905
+ JSONObject jsonObject = new JSONObject ("{}" );
2906
+ jsonObject .put (null , Collections .emptySet ());
2907
+ fail ("Expected an exception" );
2908
+ }
2909
+ @ Test (expected =NullPointerException .class )
2910
+ public void testPutNullDouble () {
2911
+ // null put key
2912
+ JSONObject jsonObject = new JSONObject ("{}" );
2913
+ jsonObject .put (null , 0.0d );
2914
+ fail ("Expected an exception" );
2915
+ }
2916
+ @ Test (expected =NullPointerException .class )
2917
+ public void testPutNullFloat () {
2918
+ // null put key
2919
+ JSONObject jsonObject = new JSONObject ("{}" );
2920
+ jsonObject .put (null , 0.0f );
2921
+ fail ("Expected an exception" );
2922
+ }
2923
+ @ Test (expected =NullPointerException .class )
2924
+ public void testPutNullInt () {
2925
+ // null put key
2926
+ JSONObject jsonObject = new JSONObject ("{}" );
2927
+ jsonObject .put (null , 0 );
2928
+ fail ("Expected an exception" );
2929
+ }
2930
+ @ Test (expected =NullPointerException .class )
2931
+ public void testPutNullLong () {
2932
+ // null put key
2933
+ JSONObject jsonObject = new JSONObject ("{}" );
2934
+ jsonObject .put (null , 0L );
2935
+ fail ("Expected an exception" );
2936
+ }
2937
+ @ Test (expected =NullPointerException .class )
2938
+ public void testPutNullMap () {
2939
+ // null put key
2940
+ JSONObject jsonObject = new JSONObject ("{}" );
2941
+ jsonObject .put (null , Collections .emptyMap ());
2942
+ fail ("Expected an exception" );
2943
+ }
2944
+ @ Test (expected =NullPointerException .class )
2945
+ public void testPutNullObject () {
2946
+ // null put key
2947
+ JSONObject jsonObject = new JSONObject ("{}" );
2948
+ jsonObject .put (null , new Object ());
2949
+ fail ("Expected an exception" );
2950
+ }
2951
+
2896
2952
}
0 commit comments