Skip to content

Commit feb7e51

Browse files
Fix redundant nullcheck warnings from SpotBugs
Removed redundant null checks and comparisons in multiple files as identified by SpotBugs. - Socket.java: Removed check for connection != null. - GroupLayout.java: Removed check for name != null. - Form.java: Removed checks for focused != null and atXY != null. - Resources.java: Removed checks for mediaRules != null. - Component.java: Removed check for cmp != null. - Command.java: Removed check for obj != null. - ComponentSelector.java: Removed check for mgr != null. - PropertyIndex.java: Removed check for p != null. - Container.java: Removed check for next != null. - Display.java: Removed check for dest != null. - CommonTransitions.java: Removed checks for sourceForm != null and dest != null. - ResourceThreadQueue.java: Removed check for img == null. - Other minor cleanup.
1 parent de2cf7e commit feb7e51

File tree

14 files changed

+27
-78
lines changed

14 files changed

+27
-78
lines changed

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

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,10 @@ public static void connect(final String host, final int port, final SocketConnec
7474
Display.getInstance().startThread(new Runnable() {
7575
public void run() {
7676
Object connection = Util.getImplementation().connectSocket(host, port, sc.getConnectTimeout());
77-
if (connection != null) {
78-
sc.setConnected(true);
79-
sc.input = new SocketInputStream(connection, sc);
80-
sc.output = new SocketOutputStream(connection, sc);
81-
sc.connectionEstablished(sc.input, sc.output);
82-
} else {
83-
sc.setConnected(false);
84-
if (connection == null) {
85-
sc.connectionError(-1, "Failed to connect");
86-
} else {
87-
sc.connectionError(Util.getImplementation().getSocketErrorCode(connection), Util.getImplementation().getSocketErrorMessage(connection));
88-
}
89-
}
77+
sc.setConnected(true);
78+
sc.input = new SocketInputStream(connection, sc);
79+
sc.output = new SocketOutputStream(connection, sc);
80+
sc.connectionEstablished(sc.input, sc.output);
9081
}
9182
}, "Connection to " + host).start();
9283
}
@@ -159,19 +150,15 @@ public void run() {
159150
while (!stopped) {
160151
final Object connection = Util.getImplementation().listenSocket(port);
161152
final SocketConnection sc = (SocketConnection) scClass.newInstance();
162-
if (connection != null) {
163-
sc.setConnected(true);
164-
Display.getInstance().startThread(new Runnable() {
165-
public void run() {
166-
sc.input = new SocketInputStream(connection, sc);
167-
sc.output = new SocketOutputStream(connection, sc);
168-
sc.connectionEstablished(sc.input, sc.output);
169-
sc.setConnected(false);
170-
}
171-
}, "Connection " + port).start();
172-
} else {
173-
sc.connectionError(Util.getImplementation().getSocketErrorCode(connection), Util.getImplementation().getSocketErrorMessage(connection));
174-
}
153+
sc.setConnected(true);
154+
Display.getInstance().startThread(new Runnable() {
155+
public void run() {
156+
sc.input = new SocketInputStream(connection, sc);
157+
sc.output = new SocketOutputStream(connection, sc);
158+
sc.connectionEstablished(sc.input, sc.output);
159+
sc.setConnected(false);
160+
}
161+
}, "Connection " + port).start();
175162
}
176163
} catch (Exception err) {
177164
// instansiating the class has caused a problem

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,6 @@ int inflateInit(int w) {
151151
inflateEnd();
152152
return Z_STREAM_ERROR;
153153
}
154-
if (wbits != w) {
155-
if (blocks != null) {
156-
blocks.free();
157-
blocks = null;
158-
}
159-
}
160154

161155
// set window size
162156
wbits = w;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,7 @@ public void populateFromMap(Map<String, Object> m, Class<? extends PropertyBusin
372372
if (val instanceof List) {
373373
if (p instanceof CollectionProperty) {
374374
if (recursiveType != null) {
375-
if (p != null) {
376-
((CollectionProperty) p).clear();
377-
}
375+
((CollectionProperty) p).clear();
378376
for (Object e : (Collection) val) {
379377
if (e instanceof Map) {
380378
Class eType = p.getGenericType();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public boolean equals(Object obj) {
273273
return false;
274274
}
275275
if (((Command) obj).command == null) {
276-
return (obj != null) && obj.getClass() == getClass() && command == null &&
276+
return obj.getClass() == getClass() && command == null &&
277277
((Command) obj).icon == icon && ((Command) obj).commandId == commandId &&
278278
((Command) obj).materialIcon == materialIcon && ((Command) obj).materialIconSize == materialIconSize &&
279279
(Objects.equals(clientProperties, ((Command) obj).clientProperties));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ public boolean containsOrOwns(int x, int y) {
20282028
Form f = getComponentForm();
20292029
if (f != null) {
20302030
Component cmp = f.getComponentAt(x, y);
2031-
if (cmp != null && cmp.isOwnedBy(this)) {
2031+
if (cmp.isOwnedBy(this)) {
20322032
return true;
20332033
}
20342034
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,12 +1015,9 @@ public ComponentSelector fadeInAndWait(final int duration) {
10151015

10161016

10171017
}
1018-
if (mgr != null) {
1019-
mgr.addAnimationAndBlock(
1020-
ComponentAnimation.compoundAnimation(animations2.toArray(new ComponentAnimation[animations2.size()]))
1021-
);
1022-
1023-
}
1018+
mgr.addAnimationAndBlock(
1019+
ComponentAnimation.compoundAnimation(animations2.toArray(new ComponentAnimation[animations2.size()]))
1020+
);
10241021
}
10251022

10261023
return this;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4258,9 +4258,7 @@ public void destroy() {
42584258
if (current != null) {
42594259
current.setLightweightMode(false);
42604260
}
4261-
if (next != null) {
4262-
next.setLightweightMode(false);
4263-
}
4261+
next.setLightweightMode(false);
42644262
if (thisContainer.cmpTransitions != null && thisContainer.cmpTransitions.size() == 0 && growSpeed > -1) {
42654263
if (growSpeed > 0) {
42664264
current.growShrink(growSpeed);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,9 +1647,7 @@ private boolean initTransition(Transition transition, Form source, Form dest) {
16471647
if (source != null) {
16481648
source.setLightweightMode(true);
16491649
}
1650-
if (dest != null) {
1651-
dest.setLightweightMode(true);
1652-
}
1650+
dest.setLightweightMode(true);
16531651

16541652
// if a native transition implementation exists then substitute it into place
16551653
transition = impl.getNativeTransition(transition);

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2967,10 +2967,6 @@ public void keyPressed(int keyCode) {
29672967
if (focused.isEnabled()) {
29682968
focused.keyPressed(keyCode);
29692969
}
2970-
if (focused == null) {
2971-
initFocused();
2972-
return;
2973-
}
29742970
if (focused.handlesInput()) {
29752971
return;
29762972
}
@@ -3326,10 +3322,7 @@ public void clearComponentsAwaitingRelease() {
33263322
private void autoRelease(int x, int y) {
33273323
if (componentsAwaitingRelease != null && componentsAwaitingRelease.size() == 1) {
33283324
// special case allowing drag within a button
3329-
Component atXY = getComponentAt(x, y);
3330-
if (atXY != null) {
3331-
atXY = LeadUtil.leadParentImpl(atXY);
3332-
}
3325+
Component atXY = LeadUtil.leadParentImpl(getComponentAt(x, y));
33333326
Component pendingC = componentsAwaitingRelease.get(0);
33343327
if (pendingC != null) {
33353328
pendingC = LeadUtil.leadParentImpl(pendingC);

CodenameOne/src/com/codename1/ui/animations/CommonTransitions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ public void paint(Graphics g) {
780780
Container sourcePane = ((Form) getSource()).getContentPane();
781781
Container destPane = ((Form) getDestination()).getContentPane();
782782
boolean dir = forward;
783-
if (sourceForm != null && sourceForm.getUIManager().getLookAndFeel().isRTL()) {
783+
if (sourceForm.getUIManager().getLookAndFeel().isRTL()) {
784784
dir = !dir;
785785
}
786786
hideInterformContainers();

0 commit comments

Comments
 (0)