Skip to content

Commit 66a5997

Browse files
author
Leonardo Lopes
committed
Better null return
1 parent e7b570e commit 66a5997

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ In project's pom.xml add in ```<dependencies>```:
2828
<dependency>
2929
<groupId>com.github.leonardofel</groupId>
3030
<artifactId>json-java-put-null-fix</artifactId>
31-
<version>3.0.33</version>
31+
<version>3.0.34</version>
3232
</dependency>
3333
</dependencies>
3434
```

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>com.github.leonardofel</groupId>
55
<artifactId>json-java-put-null-fix</artifactId>
6-
<version>3.0.33</version>
6+
<version>3.0.34</version>
77
<packaging>jar</packaging>
88

99
<name>JSON in Java WITH WORKING .put(null)</name>

src/main/java/org/json/JSONArray.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ public Iterator<Object> iterator() {
256256
* If there is no value for the index.
257257
*/
258258
public Object get(int index) throws JSONException {
259-
Object object = this.opt(index);
260-
if (object == null) {
261-
throw new JSONException("JSONArray[" + index + "] not found.");
259+
try {
260+
return this.opt(index);
261+
} catch (Exception e) {
262+
throw new JSONException(e.getMessage());
262263
}
263-
return object;
264264
}
265265

266266
/**

src/main/java/org/json/JSONObject.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -568,14 +568,11 @@ public static String doubleToString(double d) {
568568
* if the key is not found.
569569
*/
570570
public Object get(String key) throws JSONException {
571-
if (key == null) {
572-
throw new JSONException("Null key.");
573-
}
574-
Object object = this.opt(key);
575-
if (object == null) {
576-
throw new JSONException("JSONObject[" + quote(key) + "] not found.");
571+
try {
572+
return this.map.get(key);
573+
} catch (Exception e) {
574+
throw new JSONException(e.getMessage());
577575
}
578-
return object;
579576
}
580577

581578
/**

0 commit comments

Comments
 (0)