Skip to content

Commit 269e17b

Browse files
Fix SpotBugs Repeated Conditional Tests (#4360)
* Fix repeated conditional tests warnings and enforce rule in CI Fixed RpC_REPEATED_CONDITIONAL_TEST violations in: - GridBagConstraints.java: Fixed copy-paste error in insets check - CSSBorder.java: Fixed redundant quote check - ImageViewer.java: Fixed logic in keyReleased method - Container.java: Simplified componentAt logic Updated generate-quality-report.py to enforce this rule. * Fix repeated conditional tests warnings and enforce rule in CI Fixed RpC_REPEATED_CONDITIONAL_TEST violations in: - GridBagConstraints.java: Fixed copy-paste error in insets check - CSSBorder.java: Fixed redundant quote check - ImageViewer.java: Fixed logic in keyReleased method - Container.java: Simplified componentAt logic - Form.java: Removed redundant nested if check Updated generate-quality-report.py to enforce this rule. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 24a85df commit 269e17b

File tree

6 files changed

+11
-14
lines changed

6 files changed

+11
-14
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,8 @@ def main() -> None:
764764
"SF_SWITCH_NO_DEFAULT",
765765
"DM_DEFAULT_ENCODING",
766766
"EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS",
767-
"IA_AMBIGUOUS_INVOCATION_OF_INHERITED_OR_OUTER_METHOD"
767+
"IA_AMBIGUOUS_INVOCATION_OF_INHERITED_OR_OUTER_METHOD",
768+
"RpC_REPEATED_CONDITIONAL_TEST"
768769
}
769770
violations = [
770771
f for f in spotbugs.findings

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public void keyReleased(int key) {
307307
new AnimatePanX(-1, getImageLeft(), getImageLeftPos());
308308
return;
309309
}
310-
if (gk == Display.GAME_RIGHT || gk == Display.GAME_RIGHT && (cycleRight || swipeableImages.getSelectedIndex() < getImageRightPos())) {
310+
if (gk == Display.GAME_RIGHT && (cycleRight || swipeableImages.getSelectedIndex() < getImageRightPos())) {
311311
new AnimatePanX(2, getImageRight(), getImageRightPos());
312312
}
313313
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,10 +2975,8 @@ public Component getComponentAt(int x, int y) {
29752975

29762976
}
29772977
}
2978-
if (component == null || (!component.respondsToPointerEvents() && top != null)) {
2979-
if (top != null) {
2980-
return top;
2981-
}
2978+
if (top != null && (component == null || !component.respondsToPointerEvents())) {
2979+
return top;
29822980
}
29832981

29842982
if (component != null) {

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,11 +1462,9 @@ public Container getLayeredPane(Class c, boolean top) {
14621462
layeredPaneImpl.add(cnt);
14631463
} else {
14641464
if (componentCount > 0) {
1465-
if (componentCount > 0) {
1466-
Integer z = (Integer) children.get(0).getClientProperty(Z_INDEX_PROP);
1467-
if (z != null) {
1468-
zIndex = z.intValue();
1469-
}
1465+
Integer z = (Integer) children.get(0).getClientProperty(Z_INDEX_PROP);
1466+
if (z != null) {
1467+
zIndex = z.intValue();
14701468
}
14711469
}
14721470
layeredPaneImpl.addComponent(0, cnt);

CodenameOne/src/com/codename1/ui/layouts/GridBagConstraints.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ void verify() throws IllegalArgumentException {
170170
// awt.9C=wrong value of GridBagConstraints: {0}
171171
throw new IllegalArgumentException("wrong value of GridBagConstraints: " + ipady); //$NON-NLS-1$ //$NON-NLS-2$
172172
}
173-
if ((insets == null) || (insets.left < 0) || (insets.left < 0)
174-
|| (insets.left < 0) || (insets.left < 0)) {
173+
if ((insets == null) || (insets.top < 0) || (insets.left < 0)
174+
|| (insets.bottom < 0) || (insets.right < 0)) {
175175
// awt.9C=wrong value of GridBagConstraints: {0}
176176
throw new IllegalArgumentException("wrong value of GridBagConstraints: " + insets); //$NON-NLS-1$ //$NON-NLS-2$
177177
}

CodenameOne/src/com/codename1/ui/plaf/CSSBorder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ public CSSBorder backgroundImage(String cssDirective) {
11341134
if (part.indexOf("url(") == 0) {
11351135
part = part.substring(4, part.length() - 1);
11361136
}
1137-
if (part.charAt(0) == '"' || part.charAt(0) == '"') {
1137+
if (part.charAt(0) == '"' || part.charAt(0) == '\'') {
11381138
part = part.substring(1, part.length() - 1);
11391139
}
11401140
if (part.indexOf("/") != -1) {

0 commit comments

Comments
 (0)