Skip to content

Commit 7facc88

Browse files
Fix SpotBugs "Condition has no effect" (UC_USELESS_CONDITION) warnings
Updated .github/scripts/generate-quality-report.py to fail on UC_USELESS_CONDITION. Fixed UC_USELESS_CONDITION warnings in: - CodenameOne/src/com/codename1/ui/layouts/mig/Grid.java - CodenameOne/src/com/codename1/ui/MenuBar.java - CodenameOne/src/com/codename1/util/MathUtil.java - CodenameOne/src/com/codename1/impl/CodenameOneImplementation.java - CodenameOne/src/com/codename1/ui/Component.java - CodenameOne/src/com/codename1/ui/ComponentGroup.java - CodenameOne/src/com/codename1/ui/html/CSSEngine.java - CodenameOne/src/com/codename1/ui/html/CSSParser.java - CodenameOne/src/com/codename1/ui/html/HTMLComponent.java - CodenameOne/src/com/codename1/ui/html/ResourceThreadQueue.java - CodenameOne/src/com/codename1/ui/layouts/mig/UnitValue.java - CodenameOne/src/com/codename1/util/regex/RECharacter.java - CodenameOne/src/com/codename1/xml/XMLParser.java
1 parent 365b110 commit 7facc88

File tree

14 files changed

+20
-30
lines changed

14 files changed

+20
-30
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,8 @@ def main() -> None:
770770
"ES_COMPARING_PARAMETER_STRING_WITH_EQ",
771771
"FE_FLOATING_POINT_EQUALITY",
772772
"FE_TEST_IF_EQUAL_TO_NOT_A_NUMBER",
773-
"SA_FIELD_SELF_ASSIGNMENT"
773+
"SA_FIELD_SELF_ASSIGNMENT",
774+
"UC_USELESS_CONDITION"
774775
}
775776
violations = [
776777
f for f in spotbugs.findings

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8475,14 +8475,14 @@ protected int drawLabelText(Object nativeGraphics, int textDecoration, boolean r
84758475
// Instead we simple reposition the text, and draw the 3 points, this is quite simple, but
84768476
// the downside is that a part of a letter may be shown here as well.
84778477

8478-
if (rtl && !isTickerRunning && endsWith3Points) {
8479-
// PMD Fix (CollapsibleIfStatements): Separate combined RTL and ticker checks into a single conditional.
8480-
String points = "...";
8481-
int pointsW = stringWidth(nativeFont, points);
8482-
drawString(nativeGraphics, nativeFont, points, shiftText + x, y, textDecoration, fontHeight);
8483-
clipRect(nativeGraphics, pointsW + shiftText + x, y, textSpaceW - pointsW, fontHeight);
8484-
}
84858478
if (rtl) {
8479+
if (!isTickerRunning && endsWith3Points) {
8480+
// PMD Fix (CollapsibleIfStatements): Separate combined RTL and ticker checks into a single conditional.
8481+
String points = "...";
8482+
int pointsW = stringWidth(nativeFont, points);
8483+
drawString(nativeGraphics, nativeFont, points, shiftText + x, y, textDecoration, fontHeight);
8484+
clipRect(nativeGraphics, pointsW + shiftText + x, y, textSpaceW - pointsW, fontHeight);
8485+
}
84868486
x = x - txtW + textSpaceW;
84878487
} else if (endsWith3Points) {
84888488
String points = "...";

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5816,10 +5816,7 @@ private void pointerReleaseImpl(Component lead, int x, int y) {
58165816
return;
58175817
}
58185818

5819-
int scroll = scrollY;
5820-
if (shouldScrollX) {
5821-
scroll = scrollX;
5822-
}
5819+
int scroll = shouldScrollX ? scrollX : scrollY;
58235820
float speed = getDragSpeed(!shouldScrollX);
58245821
int tl;
58255822
if (getTensileLength() > -1) {

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,7 @@ public Object getPropertyValue(String name) {
263263
return groupFlag;
264264
}
265265
if (name.equals("forceGroup")) {
266-
if (forceGroup) {
267-
return Boolean.TRUE;
268-
}
269-
return Boolean.FALSE;
266+
return forceGroup ? Boolean.TRUE : Boolean.FALSE;
270267
}
271268
return null;
272269
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,6 @@ public void actionPerformed(ActionEvent evt) {
752752
c = result;
753753
// a touch menu will always send its commands on its own...
754754
if (!isTouchMenus()) {
755-
c = result;
756755
if (c != null) {
757756
ActionEvent e = new ActionEvent(c, ActionEvent.Type.Command);
758757
c.actionPerformed(e);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,9 +1669,8 @@ private void applyStyleToUIElement(Component ui, CSSElement selector, HTMLElemen
16691669
}
16701670

16711671
private void addOutlineToStyle(Style style, Border outline) {
1672-
Border curBorder = style.getBorder();
1673-
if (curBorder != null) {
1674-
curBorder.addOuterBorder(outline);
1672+
if (style.getBorder() != null) {
1673+
style.getBorder().addOuterBorder(outline);
16751674
} else {
16761675
style.setBorder(outline);
16771676
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private char handleCSSComment(ExtInputStreamReader r) throws IOException {
102102
char c = r.readCharFromReader();
103103
if (c == '*') {
104104
char lastC = '\0';
105-
while ((c != '/') || (lastC != '*')) {
105+
while (!(c == '/' && lastC == '*')) {
106106
lastC = c;
107107
c = r.readCharFromReader();
108108
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2227,7 +2227,7 @@ private Label addString(String str, int align) {
22272227
for (int j = 0; j < spacesPerWord; j++) {
22282228
newStr += ' ';
22292229
}
2230-
if (i <= addtlSpaces) {
2230+
if (i - 1 < addtlSpaces) {
22312231
newStr += ' ';
22322232
}
22332233
newStr += ' ' + (String) words.elementAt(i);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public void streamReady(InputStream is, DocumentInfo docInfo) {
446446
htmlC.getHTMLCallback().parsingError(cssDocInfo != null ? HTMLCallback.ERROR_CSS_NOT_FOUND : HTMLCallback.ERROR_IMAGE_NOT_FOUND, null, null, null, (cssDocInfo != null ? "CSS" : "Image") + " not found at " + (cssDocInfo != null ? cssDocInfo.getUrl() : imageUrl));
447447
}
448448
} else {
449-
if (cssDocInfo != null) { // CSS
449+
if (this.cssDocInfo != null) { // CSS
450450
if (HTMLComponent.SUPPORT_CSS) { // no need to also check if loadCSS is true, since if we got so far - it is...
451451
CSSElement result = CSSParser.getInstance().parseCSSSegment(com.codename1.io.Util.getReader(is), is, htmlC, cssDocInfo.getUrl());
452452
result.setAttribute(result.getAttributeName(Integer.valueOf(CSSElement.CSS_PAGEURL)), cssDocInfo.getUrl());

CodenameOne/src/com/codename1/ui/layouts/mig/Grid.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public Grid(ContainerWrapper container, LC lc, AC rowConstr, AC colConstr, Map<?
288288
setCell(cellXY[1], cellXY[0], cell);
289289

290290
// Add a rectangle so we can know that spanned cells occupy more space.
291-
if (spanx > 1 || spany > 1) {
291+
if (spanx != 1 || spany != 1) {
292292
spannedRects.add(new int[]{cellXY[0], cellXY[1], spanx, spany});
293293
}
294294
}

0 commit comments

Comments
 (0)