Skip to content

Commit 0991d8a

Browse files
authored
Fixed SpotBugs: Switch statement found where one case falls through to the next case (#4400)
1 parent 77c3e9a commit 0991d8a

File tree

9 files changed

+398
-285
lines changed

9 files changed

+398
-285
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,12 +821,19 @@ def main() -> None:
821821
"SS_SHOULD_BE_STATIC",
822822
"UPM_UNCALLED_PRIVATE_METHOD",
823823
"RV_CHECK_FOR_POSITIVE_INDEXOF",
824+
"SF_SWITCH_FALLTHROUGH"
824825
}
825826

826827
def _is_exempt(f: Finding) -> bool:
827828
loc = f.path or f.location or ""
828829
if f.rule == "SA_FIELD_SELF_ASSIGNMENT" and "InfBlocks.java" in loc:
829830
return True
831+
if f.rule == "SF_SWITCH_FALLTHROUGH" and "InfBlocks.java" in loc:
832+
return True
833+
if f.rule == "SF_SWITCH_FALLTHROUGH" and "InfCodes.java" in loc:
834+
return True
835+
if f.rule == "SF_SWITCH_FALLTHROUGH" and "Inflate.java" in loc:
836+
return True
830837
if f.rule == "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" and "TarEntry.java" in loc:
831838
return True
832839
if f.rule == "URF_UNREAD_FIELD" and "GridBagLayoutInfo" in loc:

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

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,13 +1099,10 @@ private void calculateComponentPosition(int index, int defaultWidth, Rectangle r
10991099
y = recalcOffset(y, totalHeight, listHeight, height + itemGap);
11001100
break;
11011101
case FIXED_TRAIL:
1102-
y = listHeight - (height + itemGap + selectedDiff);
1102+
y = fixedLead(index, listHeight - (height + itemGap + selectedDiff), selection, height, selectedDiff, totalHeight, listHeight);
1103+
break;
11031104
case FIXED_LEAD:
1104-
y += (index - selection) * (height + itemGap);
1105-
if (index - selection > 0) {
1106-
y += selectedDiff;
1107-
}
1108-
y = recalcOffset(y, totalHeight, listHeight, height + itemGap);
1105+
y = fixedLead(index, y, selection, height, selectedDiff, totalHeight, listHeight);
11091106
break;
11101107
default:
11111108
y = index * (height + itemGap);
@@ -1142,16 +1139,11 @@ private void calculateComponentPosition(int index, int defaultWidth, Rectangle r
11421139
x = recalcOffset(x, totalWidth, listWidth, width + itemGap);
11431140
break;
11441141
case FIXED_TRAIL:
1145-
x = listWidth - (width + itemGap + selectedDiff);
1142+
x = fixedLead(index, listWidth - (width + itemGap + selectedDiff),
1143+
selection, width, selectedDiff, rtl, listWidth, totalWidth);
1144+
break;
11461145
case FIXED_LEAD:
1147-
x += (index - selection) * (width + itemGap);
1148-
if (index - selection > 0) {
1149-
x += selectedDiff;
1150-
}
1151-
if (rtl) {
1152-
x = listWidth - x - width;
1153-
}
1154-
x = recalcOffset(x, totalWidth, listWidth, width + itemGap);
1146+
x = fixedLead(index, x, selection, width, selectedDiff, rtl, listWidth, totalWidth);
11551147
break;
11561148
default:
11571149
x = index * (width + itemGap);
@@ -1177,6 +1169,27 @@ private void calculateComponentPosition(int index, int defaultWidth, Rectangle r
11771169
}
11781170
}
11791171

1172+
private int fixedLead(int index, int x, int selection, int width, int selectedDiff, boolean rtl, int listWidth, int totalWidth) {
1173+
x += (index - selection) * (width + itemGap);
1174+
if (index - selection > 0) {
1175+
x += selectedDiff;
1176+
}
1177+
if (rtl) {
1178+
x = listWidth - x - width;
1179+
}
1180+
x = recalcOffset(x, totalWidth, listWidth, width + itemGap);
1181+
return x;
1182+
}
1183+
1184+
private int fixedLead(int index, int y, int selection, int height, int selectedDiff, int totalHeight, int listHeight) {
1185+
y += (index - selection) * (height + itemGap);
1186+
if (index - selection > 0) {
1187+
y += selectedDiff;
1188+
}
1189+
y = recalcOffset(y, totalHeight, listHeight, height + itemGap);
1190+
return y;
1191+
}
1192+
11801193
/**
11811194
* Allows us to recalculate the bounds of a coordinate to make it "loop" back
11821195
* into view

CodenameOne/src/com/codename1/ui/html/HTMLComponent.java

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,13 +2921,10 @@ private void processTag(HTMLElement element, int align) {
29212921
if (headerFont != null) {
29222922
font = headerFont;
29232923
}
2924-
// No break here intentionally
2924+
curAlign = tagP(align, child);
2925+
break;
29252926
case HTMLElement.TAG_P:
2926-
curAlign = getHorizAlign(child.getAttributeById(HTMLElement.ATTR_ALIGN), align, true);
2927-
adjustAlignment(align, curAlign);
2928-
newLineIfNotEmpty(curAlign);
2929-
newLineIfLastWasNotEmpty(curAlign);
2930-
pushContainer(child);
2927+
curAlign = tagP(align, child);
29312928
break;
29322929
case HTMLElement.TAG_DIV:
29332930
case HTMLElement.TAG_CENTER: // CENTER is practically DIV align=CENTER
@@ -3067,6 +3064,8 @@ private void processTag(HTMLElement element, int align) {
30673064
case HTMLElement.TAG_PRE:
30683065
preTagCount++;
30693066
pushContainer(child);
3067+
processTagFontOp(child, oldFont);
3068+
break;
30703069
case HTMLElement.TAG_EM:
30713070
case HTMLElement.TAG_STRONG:
30723071
case HTMLElement.TAG_DFN:
@@ -3076,10 +3075,7 @@ private void processTag(HTMLElement element, int align) {
30763075
case HTMLElement.TAG_VAR:
30773076
case HTMLElement.TAG_CITE:
30783077
case HTMLElement.TAG_TT:
3079-
font = (HTMLFont) fonts.get(child.getTagName());
3080-
if (font == null) {
3081-
font = oldFont;
3082-
}
3078+
processTagFontOp(child, oldFont);
30833079
break;
30843080

30853081
case HTMLElement.TAG_B:
@@ -3266,11 +3262,10 @@ private void processTag(HTMLElement element, int align) {
32663262
case HTMLElement.TAG_H5:
32673263
case HTMLElement.TAG_H6:
32683264
font = oldFont;
3265+
curAlign = processTagP(align);
3266+
break;
32693267
case HTMLElement.TAG_P:
3270-
curAlign = align; //Restore previous alignment
3271-
newLineIfNotEmpty(curAlign);
3272-
popContainer();
3273-
newLine(curAlign);
3268+
curAlign = processTagP(align);
32743269
break;
32753270
case HTMLElement.TAG_DIV:
32763271
case HTMLElement.TAG_CENTER:
@@ -3356,8 +3351,13 @@ private void processTag(HTMLElement element, int align) {
33563351
case HTMLElement.TAG_PRE:
33573352
preTagCount--;
33583353
popContainer();
3354+
textColor = oldFontColor;
3355+
font = oldFont;
3356+
break;
33593357
case HTMLElement.TAG_FONT:
33603358
textColor = oldFontColor;
3359+
font = oldFont;
3360+
break;
33613361
case HTMLElement.TAG_EM:
33623362
case HTMLElement.TAG_STRONG:
33633363
case HTMLElement.TAG_DFN:
@@ -3588,6 +3588,32 @@ private void processTag(HTMLElement element, int align) {
35883588
}
35893589
}
35903590

3591+
private int processTagP(int align) {
3592+
int curAlign;
3593+
curAlign = align; //Restore previous alignment
3594+
newLineIfNotEmpty(curAlign);
3595+
popContainer();
3596+
newLine(curAlign);
3597+
return curAlign;
3598+
}
3599+
3600+
private void processTagFontOp(HTMLElement child, HTMLFont oldFont) {
3601+
font = (HTMLFont) fonts.get(child.getTagName());
3602+
if (font == null) {
3603+
font = oldFont;
3604+
}
3605+
}
3606+
3607+
private int tagP(int align, HTMLElement child) {
3608+
int curAlign;
3609+
curAlign = getHorizAlign(child.getAttributeById(HTMLElement.ATTR_ALIGN), align, true);
3610+
adjustAlignment(align, curAlign);
3611+
newLineIfNotEmpty(curAlign);
3612+
newLineIfLastWasNotEmpty(curAlign);
3613+
pushContainer(child);
3614+
return curAlign;
3615+
}
3616+
35913617
/**
35923618
* The following replaces the layout of the curLine container with the correct alignment, in non fixed width alignment is done by flowlayout's orientation.
35933619
* In case the line is not empty, a new line will be opened by newLineIfNotEmpty below

0 commit comments

Comments
 (0)