Skip to content

Commit 65b6916

Browse files
committed
Supress bug warning for purposeful Boolean null return
1 parent 9a48250 commit 65b6916

File tree

2 files changed

+9
-44
lines changed

2 files changed

+9
-44
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
<version>4.13.2</version>
3131
<scope>test</scope>
3232
</dependency>
33+
34+
<dependency>
35+
<groupId>com.github.spotbugs</groupId>
36+
<artifactId>spotbugs-annotations</artifactId>
37+
<version>4.7.3</version>
38+
<scope>provided</scope>
39+
</dependency>
3340
</dependencies>
3441

3542
<build>

src/main/java/core/JSONObject.java

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.Iterator;
55
import java.util.List;
6+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
67

78
/**
89
* A JSONObject is a custom data structure that represents a JSON object. It supports nested key-value pairs, arrays (as
@@ -165,6 +166,7 @@ public Number getAsNumber() {
165166
return value instanceof Number ? (Number) value : null;
166167
}
167168

169+
@SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL")
168170
public Boolean getAsBoolean() {
169171
return value instanceof Boolean ? (Boolean) value : null;
170172
}
@@ -307,50 +309,6 @@ public String toString() {
307309
return String.join("\n", JSONStringifier.expandJson(JSONStringifier.stringifyJson(this)));
308310
}
309311

310-
/**
311-
* Format a value as it would appear within a JSON file.
312-
*
313-
* @param val
314-
* An Object to format
315-
*
316-
* @return A String for the value properly formatted for JSON
317-
*/
318-
private static String formatValue(Object val) {
319-
if (val == null)
320-
return "null";
321-
if (val instanceof String)
322-
return String.format("\"%s\"", val);
323-
if (val instanceof JSONObject)
324-
return val.toString();
325-
return val.toString();
326-
}
327-
328-
/**
329-
* Counts the number of items within the list, for use with formatting a String representation of a JSONObject. Most
330-
* types count as 1 entry, while instances of inner JSONObjects count as 3. Inner Arrays will be recursively
331-
* counted.
332-
*
333-
* @param list
334-
* A list to count the number of entries within
335-
*
336-
* @return An int count of the list's recursive calculated size
337-
*
338-
* @see JSONObject#toString()
339-
* @see JSONObject#SINGLE_LINE_ENTRIES_MAX
340-
*/
341-
private static int countInnerListEntries(List<?> list) {
342-
int entries = 0;
343-
for (Object o : list) {
344-
if (o instanceof JSONObject)
345-
entries += 3;
346-
else if (o instanceof List<?>)
347-
entries += countInnerListEntries((List<?>) o);
348-
else
349-
entries += 1;
350-
}
351-
return entries;
352-
}
353-
354312
@Override
355313
public int hashCode() {
356314
return this.toString().hashCode();

0 commit comments

Comments
 (0)