Skip to content

Commit eb1f364

Browse files
Fix UC_USELESS_CONDITION SpotBugs warnings
Fixed multiple occurrences of UC_USELESS_CONDITION warnings across 13 files. Updated .github/scripts/generate-quality-report.py to fail on this violation. Notable fixes: - CSSParser.java: Fixed char to byte cast comparison that caused premature EOF on extended ASCII. - ResourceThreadQueue.java: Fixed variable shadowing and added volatile to cancelled flag. - UnitValue.java: Fixed condition checking operation type. - XMLParser.java: Used Character.toLowerCase instead of manual range check. - Various cleanups in Grid.java, MenuBar.java, Component.java, etc.
1 parent 7facc88 commit eb1f364

File tree

13 files changed

+29
-28
lines changed

13 files changed

+29
-28
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2635,7 +2635,7 @@ protected boolean hasDragStarted(final int x, final int y) {
26352635
if (getCurrentForm() == null) {
26362636
return false;
26372637
}
2638-
if (dragActivationCounter == 0) {
2638+
if (dragActivationCounter <= 0) {
26392639
dragActivationX = x;
26402640
dragActivationY = y;
26412641
dragActivationCounter++;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5142,8 +5142,8 @@ public void run() {
51425142
view = new Rectangle(getScrollX(), getScrollY(), w, h - invisibleAreaUnderVKB);
51435143
//if the dragging component is out of bounds move the scrollable parent
51445144
if (!view.contains(draggedx - scrollParent.getAbsoluteX(), draggedy - scrollParent.getAbsoluteY(), getWidth(), getHeight())) {
5145-
if ((scrollParent.isScrollableY() && scrollParent.getScrollY() >= 0 && scrollParent.getScrollY() + (draggedy + getHeight()) < scrollParent.getScrollDimension().getHeight()) ||
5146-
(scrollParent.isScrollableX() && scrollParent.getScrollX() >= 0 && scrollParent.getScrollX() + (draggedx + getWidth()) < scrollParent.getScrollDimension().getWidth())) {
5145+
if ((scrollParent.isScrollableY() && scrollParent.getScrollY() + (draggedy + getHeight()) < scrollParent.getScrollDimension().getHeight()) ||
5146+
(scrollParent.isScrollableX() && scrollParent.getScrollX() + (draggedx + getWidth()) < scrollParent.getScrollDimension().getWidth())) {
51475147
int yposition = draggedy - scrollParent.getAbsoluteY() - 40;
51485148
if (yposition < 0) {
51495149
yposition = 0;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ private void restoreUIID(Component c) {
184184
* @return the horizontal
185185
*/
186186
public boolean isHorizontal() {
187-
return getLayout() instanceof BoxLayout && ((BoxLayout) getLayout()).getAxis() == BoxLayout.X_AXIS;
187+
Layout l = getLayout();
188+
if (l instanceof BoxLayout) {
189+
return ((BoxLayout) l).getAxis() == BoxLayout.X_AXIS;
190+
}
191+
return false;
188192
}
189193

190194
/**

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -751,11 +751,9 @@ public void actionPerformed(ActionEvent evt) {
751751
} else {
752752
c = result;
753753
// a touch menu will always send its commands on its own...
754-
if (!isTouchMenus()) {
755-
if (c != null) {
756-
ActionEvent e = new ActionEvent(c, ActionEvent.Type.Command);
757-
c.actionPerformed(e);
758-
}
754+
if (!isTouchMenus() && c != null) {
755+
ActionEvent e = new ActionEvent(c, ActionEvent.Type.Command);
756+
c.actionPerformed(e);
759757
}
760758
}
761759
// menu item was handled internally in a touch interface that is not a touch menu

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,8 +1462,9 @@ private void applyStyleToUIElement(Component ui, CSSElement selector, HTMLElemen
14621462
if ((styles & STYLE_PRESSED) != 0) {
14631463
borderUi.getPressedStyle().setBorder(border);
14641464
}
1465-
if (borderUi.getParent() != null) {
1466-
borderUi.getParent().revalidate();
1465+
Container borderUiParent = borderUi.getParent();
1466+
if (borderUiParent != null) {
1467+
borderUiParent.revalidate();
14671468
} else if (borderUi instanceof Container) {
14681469
((Container) borderUi).revalidate();
14691470
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private String nextToken(ExtInputStreamReader r, boolean readNewline, boolean ig
134134
char c = r.readCharFromReader();
135135

136136
// read the next token from the CSS stream
137-
while (((byte) c) != -1 && isWhiteSpace(c)) {
137+
while (c != (char) -1 && isWhiteSpace(c)) {
138138
newline = newline || (c == 10 || c == 13 || c == ';' || ((c == ',') && (!ignoreCommas)) || (c == '>') || (c == '+'));
139139
if (!readNewline && newline) {
140140
return null;
@@ -143,15 +143,15 @@ private String nextToken(ExtInputStreamReader r, boolean readNewline, boolean ig
143143
}
144144
if (c == ';' && readNewline) { //leftover from compound operation
145145
c = r.readCharFromReader();
146-
while (((byte) c) != -1 && isWhiteSpace(c)) { // This was added since after reading ; there might be some more white spaces. However there needs to be a way to combine this with the previous white spaces code or with the revised newline detection and unreading char below
146+
while (c != (char) -1 && isWhiteSpace(c)) { // This was added since after reading ; there might be some more white spaces. However there needs to be a way to combine this with the previous white spaces code or with the revised newline detection and unreading char below
147147
newline = newline || (c == 10 || c == 13 || c == ';' || ((c == ',') && (!ignoreCommas)) || (c == '>') || (c == '+'));
148148
c = r.readCharFromReader();
149149
}
150150

151151

152152
}
153153
char segment = '\0'; // segment of (...) or "..." or '...'
154-
while (((byte) c) != -1 && ((!isWhiteSpace(c)) || (segment != '\0') || (ignoreWhiteSpaces)) && c != ';' && ((c != ':') ||
154+
while (c != (char) -1 && ((!isWhiteSpace(c)) || (segment != '\0') || (ignoreWhiteSpaces)) && c != ';' && ((c != ':') ||
155155
(segment != '\0') || (ignoreColons)) && ((c != ',') || (segment != '\0') ||
156156
(ignoreCommas)) && (((c != '>') && (c != '+')) || (segment != '\0'))) { //- : denotes pseudo-classes, would like to keep them as one token
157157

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,9 +2192,8 @@ private Label addString(String str, int align) {
21922192
lbl.getSelectedStyle().setFgColor(color);
21932193

21942194
//lbl.setVerticalAlignment(Component.BOTTOM); //TODO - This still doesn't align as label alignment in Codename One refers to the text alignment in relation to its icon (if exists)
2195-
if(font != null) {
2196-
lbl.getUnselectedStyle().setFont(font.getFont());
2197-
}
2195+
// font is always initialized to defaultFont
2196+
lbl.getUnselectedStyle().setFont(font.getFont());
21982197
lbl.getUnselectedStyle().setBgTransparency(0);
21992198
lbl.setGap(0);
22002199
lbl.setTickerEnabled(false);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ class ResourceThread implements Runnable, IOCallback {
360360
String imageUrl;
361361
DocumentRequestHandler handler;
362362
ResourceThreadQueue threadQueue;
363-
boolean cancelled;
363+
volatile boolean cancelled;
364364
HTMLComponent htmlC;
365365
Image img;
366366
DocumentInfo cssDocInfo;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,12 @@ public Grid(ContainerWrapper container, LC lc, AC rowConstr, AC colConstr, Map<?
197197
continue; // The "external" component should not be handled further.
198198
}
199199

200-
if (rootCc.getHorizontal().getSizeGroup() != null) {
200+
String sgX = rootCc.getHorizontal().getSizeGroup();
201+
if (sgX != null) {
201202
sizeGroupsX++;
202203
}
203-
if (rootCc.getVertical().getSizeGroup() != null) {
204+
String sgY = rootCc.getVertical().getSizeGroup();
205+
if (sgY != null) {
204206
sizeGroupsY++;
205207
}
206208

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private UnitValue(float value, String unitStr, int unit, boolean isHor, int oper
240240
if (oper < STATIC || oper > MID)
241241
throw new IllegalArgumentException("Unknown Operation: " + oper);
242242

243-
if (oper >= ADD && oper <= MID && (sub1 == null || sub2 == null))
243+
if (oper > STATIC && oper <= MID && (sub1 == null || sub2 == null))
244244
throw new IllegalArgumentException(oper + " Operation may not have null sub-UnitValues.");
245245

246246
this.value = value;

0 commit comments

Comments
 (0)