Skip to content

Commit c43fc81

Browse files
Fix SpotBugs SF_SWITCH_NO_DEFAULT warnings (#4350)
* 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. * Fixed verification issues due to merge * More issues due to the merge problem --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Shai Almog <[email protected]>
1 parent 47ebae4 commit c43fc81

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

+280
-27
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: 36 additions & 18 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
}
@@ -7970,24 +7976,6 @@ public void paintComponentBackground(Object nativeGraphics, int x, int y, int wi
79707976
int iH = bgImageOrig.getHeight();
79717977
Object bgImage = bgImageOrig.getImage();
79727978
switch (s.getBackgroundType()) {
7973-
case Style.BACKGROUND_NONE:
7974-
if (s.getBgTransparency() != 0) {
7975-
setColor(nativeGraphics, s.getBgColor());
7976-
fillRect(nativeGraphics, x, y, width, height, s.getBgTransparency());
7977-
}
7978-
return;
7979-
case Style.BACKGROUND_IMAGE_SCALED:
7980-
if (isScaledImageDrawingSupported()) {
7981-
drawImage(nativeGraphics, bgImage, x, y, width, height);
7982-
} else {
7983-
if (iW != width || iH != height) {
7984-
bgImageOrig = bgImageOrig.scaled(width, height);
7985-
s.setBgImage(bgImageOrig, true);
7986-
bgImage = bgImageOrig.getImage();
7987-
}
7988-
drawImage(nativeGraphics, bgImage, x, y);
7989-
}
7990-
return;
79917979
case Style.BACKGROUND_IMAGE_SCALED_FILL:
79927980
float r = Math.max(((float) width) / ((float) iW), ((float) height) / ((float) iH));
79937981
int bwidth = (int) (((float) iW) * r);
@@ -8110,6 +8098,19 @@ public void paintComponentBackground(Object nativeGraphics, int x, int y, int wi
81108098
case Style.BACKGROUND_GRADIENT_LINEAR_VERTICAL:
81118099
case Style.BACKGROUND_GRADIENT_RADIAL:
81128100
drawGradientBackground(s, nativeGraphics, x, y, width, height);
8101+
return;
8102+
default:
8103+
// Style.BACKGROUND_IMAGE_SCALED:
8104+
if (isScaledImageDrawingSupported()) {
8105+
drawImage(nativeGraphics, bgImage, x, y, width, height);
8106+
} else {
8107+
if (iW != width || iH != height) {
8108+
bgImageOrig = bgImageOrig.scaled(width, height);
8109+
s.setBgImage(bgImageOrig, true);
8110+
bgImage = bgImageOrig.getImage();
8111+
}
8112+
drawImage(nativeGraphics, bgImage, x, y);
8113+
}
81138114
}
81148115
}
81158116
}
@@ -8129,6 +8130,13 @@ private void drawGradientBackground(Style s, Object nativeGraphics, int x, int y
81298130
x, y, width, height, s.getBackgroundGradientRelativeX(), s.getBackgroundGradientRelativeY(),
81308131
s.getBackgroundGradientRelativeSize());
81318132
return;
8133+
default:
8134+
// Style.BACKGROUND_NONE
8135+
if (s.getBgTransparency() != 0) {
8136+
setColor(nativeGraphics, s.getBgColor());
8137+
fillRect(nativeGraphics, x, y, width, height, s.getBgTransparency());
8138+
}
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
@@ -474,6 +474,8 @@ String format(Date source, StringBuilder toAppendTo) {
474474
v = ((calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7) + 1;
475475
toAppendTo.append(leftPad(v, len));
476476
break;
477+
default:
478+
break;
477479
}
478480
}
479481
return toAppendTo.toString();
@@ -615,6 +617,8 @@ public Date parse(String source) throws ParseException {
615617
// v % 7 + 1
616618
calendar.set(Calendar.DAY_OF_WEEK, (v % 7) + 1);
617619
break;
620+
default:
621+
break;
618622
}
619623
if (s != null) {
620624
startIndex += s.length();

0 commit comments

Comments
 (0)