Skip to content

Commit 4e6174a

Browse files
Fix SpotBugs null pointer dereference warnings
Addressed 12 SpotBugs "Possible null pointer dereference" warnings across 8 files: - CodenameOneImplementation.java: Fixed null usage in captureAudio logging and data check. - InteractionDialog.java: Added explicit null checks for Component and Rectangle arguments in showPopupDialog. - SimpleDateFormat.java: Added return statements to throwInvalid calls. - HashtableContent.java: Added null check for node. - Form.java: Added null checks for components in layered pane iteration and safely handled null Class argument in getLayeredPane. - DefaultLookAndFeel.java: Added null checks for badgeStyle. - SpinnerNode.java: Added null check for selectionListeners before calling isEmpty(). - CommonTransitions.java: Added default case to switch statement.
1 parent 9ddf708 commit 4e6174a

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

CodenameOne/src/com/codename1/components/InteractionDialog.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,10 @@ public void showPopupDialog(Component c) {
630630
* This is ignored if there isn't enough space
631631
*/
632632
public void showPopupDialog(Component c, boolean bias) {
633-
Form f = c == null ? null : c.getComponentForm(); // PMD Fix: BrokenNullCheck
633+
if (c == null) {
634+
throw new IllegalArgumentException("Component cannot be null");
635+
}
636+
Form f = c.getComponentForm(); // PMD Fix: BrokenNullCheck
634637
if (f != null && !formMode && !f.getContentPane().contains(c)) {
635638
setFormMode(true);
636639
}

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,15 +1435,17 @@ public Container getLayeredPane(Class c, boolean top) {
14351435
}
14361436
}
14371437
}
1438-
String n = c.getName();
1438+
String n = c != null ? c.getName() : null;
14391439
// NOTE: We need to use getChildrenAsList(true) rather than simply iterating
14401440
// over layeredPaneImpl because the latter won't find components while an animation
14411441
// is in progress.... We could end up adding a whole bunch of layered panes
14421442
// by accident
14431443
java.util.List<Component> children = layeredPaneImpl.getChildrenAsList(true);
1444-
for (Component cmp : children) {
1445-
if (cmp != null && n.equals(cmp.getClientProperty("cn1$_cls"))) {
1446-
return (Container) cmp;
1444+
if (n != null) {
1445+
for (Component cmp : children) {
1446+
if (cmp != null && n.equals(cmp.getClientProperty("cn1$_cls"))) {
1447+
return (Container) cmp;
1448+
}
14471449
}
14481450
}
14491451

@@ -1496,15 +1498,17 @@ public Container getLayeredPane(Class c, int zIndex) {
14961498
}
14971499
}
14981500
}
1499-
String n = c.getName();
1501+
String n = c != null ? c.getName() : null;
15001502
// NOTE: We need to use getChildrenAsList(true) rather than simply iterating
15011503
// over layeredPaneImpl because the latter won't find components while an animation
15021504
// is in progress.... We could end up adding a whole bunch of layered panes
15031505
// by accident
15041506
java.util.List<Component> children = layeredPaneImpl.getChildrenAsList(true);
1505-
for (Component cmp : children) {
1506-
if (cmp != null && n.equals(cmp.getClientProperty("cn1$_cls"))) {
1507-
return (Container) cmp;
1507+
if (n != null) {
1508+
for (Component cmp : children) {
1509+
if (cmp != null && n.equals(cmp.getClientProperty("cn1$_cls"))) {
1510+
return (Container) cmp;
1511+
}
15081512
}
15091513
}
15101514

0 commit comments

Comments
 (0)