Skip to content

Commit de2cf7e

Browse files
Fix redundant null checks identified by SpotBugs
1 parent c113e8a commit de2cf7e

29 files changed

+64
-144
lines changed

CodenameOne/src/com/codename1/compat/java/util/Objects.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static boolean equals(Object a, Object b) {
4848
if (a == b) {
4949
return true;
5050
}
51-
return a == null ? b == null : a.equals(b);
51+
return a != null && a.equals(b);
5252
}
5353

5454
/**

CodenameOne/src/com/codename1/io/ConnectionRequest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,9 +2747,6 @@ public void run() {
27472747
if (fs.exists(file)) {
27482748
try {
27492749
EncodedImage img = EncodedImage.create(fs.openInputStream(file), (int) fs.getLength(file));
2750-
if (img == null) {
2751-
throw new IOException("Failed to load image at " + file);
2752-
}
27532750
CallbackDispatcher.dispatchSuccess(onSuccess, img);
27542751
} catch (Exception ex) {
27552752
CallbackDispatcher.dispatchError(onFail, ex);
@@ -2763,9 +2760,6 @@ public void run() {
27632760
if (fs.exists(file)) {
27642761
try {
27652762
EncodedImage img = EncodedImage.create(fs.createInputStream(file), fs.entrySize(file));
2766-
if (img == null) {
2767-
throw new IOException("Failed to load image at " + file);
2768-
}
27692763
CallbackDispatcher.dispatchSuccess(onSuccess, img);
27702764
} catch (Exception ex) {
27712765
CallbackDispatcher.dispatchError(onFail, ex);

CodenameOne/src/com/codename1/io/gzip/Inflate.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ int inflateInit(int w) {
151151
inflateEnd();
152152
return Z_STREAM_ERROR;
153153
}
154-
if (blocks != null && wbits != w) {
155-
blocks.free();
156-
blocks = null;
154+
if (wbits != w) {
155+
if (blocks != null) {
156+
blocks.free();
157+
blocks = null;
158+
}
157159
}
158160

159161
// set window size

CodenameOne/src/com/codename1/l10n/SimpleDateFormat.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,7 @@ public Date parse(String source) throws ParseException {
521521

522522
throwInvalid("timezone", startIndex);
523523
}
524-
if (res != null) {
525-
parsedTimeZone = res.timeZone;
526-
}
524+
parsedTimeZone = res.timeZone;
527525
tzMinutes = ((tzMinutes == -1) ? 0 : tzMinutes) + v;
528526
break;
529527
case YEAR_LETTER:
@@ -844,10 +842,11 @@ String readAmPmMarker(String source, int ofs) {
844842
if (i == -1) {
845843
i = source.length();
846844
}
847-
String fragment = readSubstring(source, ofs, i).toLowerCase();
845+
String fragment = readSubstring(source, ofs, i);
848846
if (fragment == null) {
849847
return null;
850848
}
849+
fragment = fragment.toLowerCase();
851850
DateFormatSymbols ds = getDateFormatSymbols();
852851
String[] markers = ds.getAmPmStrings();
853852
for (String marker : markers) {

CodenameOne/src/com/codename1/processing/ContainsEvaluator.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ private String[] _getLeftValue(StructuredContent element, String lvalue) {
7373
*/
7474
protected Object evaluateLeftContainsRight(StructuredContent element, String lvalue, String rvalue) {
7575
String[] lvalues = _getLeftValue(element, lvalue);
76-
if (lvalues == null) {
77-
return null;
78-
}
7976
// if the rvalue is wrapped with "()", the caller explicitly expects the lvalue to be an array of values,
8077
// otherwise try to do a "string contains" match first if there's only one lvalue
8178
if (rvalue.indexOf("(") == -1 && lvalues.length == 1) {

CodenameOne/src/com/codename1/processing/TextEvaluator.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ private String[] _getLeftValue(StructuredContent element, String lvalue) {
8080
protected Object evaluateLeftLessRight(StructuredContent element,
8181
String lvalue, String rvalue) {
8282
String[] v = _getLeftValue(element, lvalue);
83-
if (v == null) {
84-
return null;
85-
}
8683
int vlen = v.length;
8784
for (int i = 0; i < vlen; i++) {
8885
if (isNumeric(rvalue) && isNumeric(v[i])) {
@@ -112,9 +109,6 @@ protected Object evaluateLeftLessRight(StructuredContent element,
112109
protected Object evaluateLeftGreaterRight(StructuredContent element,
113110
String lvalue, String rvalue) {
114111
String[] v = _getLeftValue(element, lvalue);
115-
if (v == null) {
116-
return null;
117-
}
118112
int vlen = v.length;
119113
for (int i = 0; i < vlen; i++) {
120114
if (isNumeric(rvalue) && isNumeric(v[i])) {
@@ -144,9 +138,6 @@ protected Object evaluateLeftGreaterRight(StructuredContent element,
144138
protected Object evaluateLeftEqualsRight(StructuredContent element,
145139
String lvalue, String rvalue) {
146140
String[] v = _getLeftValue(element, lvalue);
147-
if (v == null) {
148-
return null;
149-
}
150141
int vlen = v.length;
151142
for (int i = 0; i < vlen; i++) {
152143
if (isNumeric(rvalue) && isNumeric(v[i])) {

CodenameOne/src/com/codename1/properties/PropertyXMLElement.java

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,13 @@ public boolean contains(Element element) {
6161
return true;
6262
}
6363
Vector children = getChildren();
64-
if (children != null) {
65-
int i = 0;
66-
while (i < children.size()) {
67-
Element child = (Element) children.get(i);
68-
if (child.contains(element)) {
69-
return true;
70-
}
71-
i++;
64+
int i = 0;
65+
while (i < children.size()) {
66+
Element child = (Element) children.get(i);
67+
if (child.contains(element)) {
68+
return true;
7269
}
70+
i++;
7371
}
7472
return false;
7573
}
@@ -193,17 +191,14 @@ public Element getElementById(String id) {
193191
return this;
194192
}
195193
Vector children = getChildren();
196-
if (children != null) {
197-
int i = 0;
198-
while (i < children.size()) {
199-
Element child = (Element) children.get(i);
200-
Element match = child.getElementById(id);
201-
if (match != null) {
202-
return match;
203-
}
204-
i++;
194+
int i = 0;
195+
while (i < children.size()) {
196+
Element child = (Element) children.get(i);
197+
Element match = child.getElementById(id);
198+
if (match != null) {
199+
return match;
205200
}
206-
201+
i++;
207202
}
208203
return null;
209204
}
@@ -389,10 +384,8 @@ public String toString(String spacing) {
389384
}
390385
str += ">\n";
391386
Vector children = getChildren();
392-
if (children != null) {
393-
for (int i = 0; i < children.size(); i++) {
394-
str += ((Element) children.get(i)).toString(spacing + ' ');
395-
}
387+
for (int i = 0; i < children.size(); i++) {
388+
str += ((Element) children.get(i)).toString(spacing + ' ');
396389
}
397390
str += spacing + "</" + getTagName() + ">\n";
398391
return str;

CodenameOne/src/com/codename1/ui/BrowserComponent.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,14 +1263,12 @@ public void execute(String js, Object[] params) {
12631263
* @return the string returned from the Javascript call
12641264
*/
12651265
public String executeAndReturnString(String javaScript) {
1266-
if (internal == null) {
1267-
while (internal == null) {
1268-
CN.invokeAndBlock(new Runnable() {
1269-
public void run() {
1270-
Util.sleep(50);
1271-
}
1272-
});
1273-
}
1266+
while (internal == null) {
1267+
CN.invokeAndBlock(new Runnable() {
1268+
public void run() {
1269+
Util.sleep(50);
1270+
}
1271+
});
12741272
}
12751273
if (Display.impl.supportsBrowserExecuteAndReturnString(internal)) {
12761274
return Display.impl.browserExecuteAndReturnString(internal, javaScript);

CodenameOne/src/com/codename1/ui/Command.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public boolean equals(Object obj) {
278278
((Command) obj).materialIcon == materialIcon && ((Command) obj).materialIconSize == materialIconSize &&
279279
(Objects.equals(clientProperties, ((Command) obj).clientProperties));
280280
} else {
281-
return (obj != null) && obj.getClass() == getClass() && ((Command) obj).command.equals(command) &&
281+
return obj.getClass() == getClass() && ((Command) obj).command.equals(command) &&
282282
((Command) obj).icon == icon && ((Command) obj).commandId == commandId &&
283283
((Command) obj).materialIcon == materialIcon && ((Command) obj).materialIconSize == materialIconSize &&
284284
(Objects.equals(clientProperties, ((Command) obj).clientProperties));

CodenameOne/src/com/codename1/ui/Component.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,9 @@ public boolean containsOrOwns(int x, int y) {
20282028
Form f = getComponentForm();
20292029
if (f != null) {
20302030
Component cmp = f.getComponentAt(x, y);
2031-
return cmp != null && cmp.isOwnedBy(this);
2031+
if (cmp != null && cmp.isOwnedBy(this)) {
2032+
return true;
2033+
}
20322034
}
20332035
return false;
20342036

0 commit comments

Comments
 (0)