Skip to content

Commit 52c70cf

Browse files
Fix SpotBugs SF_SWITCH_NO_DEFAULT warnings and enforce as error
This commit addresses missing default cases in switch statements across the codebase, as flagged by SpotBugs (SF_SWITCH_NO_DEFAULT). Key changes: - Added `default: break;` or appropriate fallback logic to switch statements in `CodenameOne/src` files including Charts, Components, UI, Layouts, and Utils. - Updated `.github/scripts/generate-quality-report.py` to treat `SF_SWITCH_NO_DEFAULT` as a forbidden rule, causing the build to fail if new violations are introduced. - Verified compilation of `codenameone-core` to ensure no syntax errors (e.g., duplicate labels) were introduced.
1 parent 7af2bce commit 52c70cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+242
-8
lines changed

.github/scripts/generate-quality-report.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,8 @@ def main() -> None:
760760
forbidden_rules = {
761761
"RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE",
762762
"RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE",
763-
"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR"
763+
"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR",
764+
"SF_SWITCH_NO_DEFAULT"
764765
}
765766
violations = [
766767
f for f in spotbugs.findings

CodenameOne/src/com/codename1/charts/transitions/SeriesTransition.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ protected void initTransition() {
111111
case EASING_IN_OUT:
112112
motion = Motion.createEaseInOutMotion(0, 100, getDuration());
113113
break;
114+
default:
115+
motion = Motion.createLinearMotion(0, 100, getDuration());
116+
break;
114117
}
115118
motion.start();
116119
}

CodenameOne/src/com/codename1/cloud/CloudObject.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,8 @@ public void propertyChanged(Component source, String propertyName, Object oldVal
765765
status = STATUS_MODIFIED;
766766
CloudStorage.getInstance().save(CloudObject.this);
767767
break;
768+
default:
769+
break;
768770
}
769771
}
770772
};

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ public void actionPerformed(ActionEvent evt) {
176176
pause.setEnabled(true);
177177
revalidateLater();
178178
break;
179+
default:
180+
break;
179181
}
180182
}
181183

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ private void disposeTo(int direction, final Runnable onFinish) {
492492
case Component.BOTTOM:
493493
setY(Display.getInstance().getDisplayHeight());
494494
break;
495-
495+
default:
496+
break;
496497
}
497498

498499
if (animateShow) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ public void actionPerformed(ActionEvent evt) {
149149
s.setInfinite(true);
150150
}
151151
break;
152+
default:
153+
break;
152154
}
153155
}
154156
});

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ public void actionPerformed(NetworkEvent evt) {
289289
} else {
290290
s.setProgress(-1);
291291
}
292+
break;
293+
default:
294+
break;
292295
}
293296
}
294297
};

CodenameOne/src/com/codename1/impl/CodenameOneImplementation.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,6 +2696,8 @@ protected boolean hasDragStarted(final int x, final int y) {
26962696
startX = Math.min(startX, 2f);
26972697
startY = Math.min(startY, 2f);
26982698
break;
2699+
default:
2700+
break;
26992701
}
27002702

27012703
// have we passed the motion threshold on the X axis?
@@ -5867,6 +5869,8 @@ public void actionPerformed(ActionEvent evt) {
58675869
});
58685870

58695871

5872+
break;
5873+
default:
58705874
break;
58715875
}
58725876
}
@@ -5926,6 +5930,8 @@ public boolean isGalleryTypeSupported(int type) {
59265930
case Display.GALLERY_VIDEO:
59275931
case Display.GALLERY_ALL:
59285932
return true;
5933+
default:
5934+
break;
59295935
}
59305936
return false;
59315937
}
@@ -8129,6 +8135,8 @@ private void drawGradientBackground(Style s, Object nativeGraphics, int x, int y
81298135
x, y, width, height, s.getBackgroundGradientRelativeX(), s.getBackgroundGradientRelativeY(),
81308136
s.getBackgroundGradientRelativeSize());
81318137
return;
8138+
default:
8139+
break;
81328140
}
81338141
setColor(nativeGraphics, s.getBgColor());
81348142
fillRect(nativeGraphics, x, y, width, height, s.getBgTransparency());
@@ -8237,6 +8245,8 @@ public void drawLabelComponent(Object nativeGraphics, int cmpX, int cmpY, int cm
82378245
case Label.TOP:
82388246
y = y + (cmpHeight - (topPadding + bottomPadding + ((icon != null) ? iconHeight + gap : 0) + fontHeight)) / 2;
82398247
break;
8248+
default:
8249+
break;
82408250
}
82418251
break;
82428252
case Component.CENTER:
@@ -8266,6 +8276,8 @@ public void drawLabelComponent(Object nativeGraphics, int cmpX, int cmpY, int cm
82668276
+ ((icon != null) ? iconHeight + gap : 0)
82678277
+ fontHeight)) / 2;
82688278
break;
8279+
default:
8280+
break;
82698281
}
82708282
break;
82718283
case Component.RIGHT:
@@ -8295,6 +8307,8 @@ public void drawLabelComponent(Object nativeGraphics, int cmpX, int cmpY, int cm
82958307
+ bottomPadding
82968308
+ ((icon != null) ? iconHeight + gap : 0) + fontHeight)) / 2;
82978309
break;
8310+
default:
8311+
break;
82988312
}
82998313
break;
83008314
default:
@@ -8381,6 +8395,8 @@ public void drawLabelComponent(Object nativeGraphics, int cmpX, int cmpY, int cm
83818395
drawImage(nativeGraphics, icon, x + iconStringWGap, y + fontHeight + gap);
83828396
}
83838397
break;
8398+
default:
8399+
break;
83848400
}
83858401
}
83868402
setAlpha(nativeGraphics, alpha);
@@ -8570,6 +8586,8 @@ private int reverseAlignForBidi(boolean rtl, int align) {
85708586
return Component.LEFT;
85718587
case Component.LEFT:
85728588
return Component.RIGHT;
8589+
default:
8590+
break;
85738591
}
85748592
}
85758593
return align;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,9 @@ void addToQueue(@Async.Schedule ConnectionRequest request, boolean retry) {
598598
case ConnectionRequest.PRIORITY_REDUNDANT:
599599
addSortedToQueue(request, i);
600600
break;
601+
default:
602+
addSortedToQueue(request, i);
603+
break;
601604
}
602605
LOCK.notify();
603606
}
@@ -877,6 +880,8 @@ private boolean runCurrentRequest(@Async.Execute ConnectionRequest req) {
877880
case ConnectionRequest.PRIORITY_REDUNDANT:
878881
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
879882
break;
883+
default:
884+
break;
880885
}
881886

882887
if (progressListeners != null) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ String format(Date source, StringBuilder toAppendTo) {
441441
v = calendar.get(DAY_OF_WEEK_IN_MONTH);
442442
toAppendTo.append(leftPad(v, len));
443443
break;
444+
default:
445+
break;
444446
}
445447
}
446448
return toAppendTo.toString();
@@ -572,6 +574,8 @@ public Date parse(String source) throws ParseException {
572574
calendar.set(DAY_OF_WEEK_IN_MONTH,
573575
parseNumber(s, startIndex, "day of week in month", -5, 5));
574576
break;
577+
default:
578+
break;
575579
}
576580
if (s != null) {
577581
startIndex += s.length();

0 commit comments

Comments
 (0)