Skip to content

Commit 73565cb

Browse files
google-labs-jules[bot]shai-almogCopilot
authored
Fix SpotBugs "Condition has no effect" warnings (#4366)
* 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 * 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. * Fix UC_USELESS_CONDITION SpotBugs warnings and compilation error Fixed UC_USELESS_CONDITION warnings across 13 files and resolved a compilation error in ComponentGroup.java. Updated .github/scripts/generate-quality-report.py to fail on this violation. Notable fixes: - ComponentGroup.java: Added missing import for Layout class. - 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. * Fix UC_USELESS_CONDITION SpotBugs warnings and enforce rule in CI * Fix UC_USELESS_CONDITION SpotBugs warnings Resolves "Condition has no effect" warnings in: - HTMLComponent.java (Redundant SUPPORT_CSS check, fix variable shadowing) - CSSEngine.java (Redundant indent >= 0 check) - CSSParser.java (Incorrect EOF check for char) - RECharacter.java (Duplicate whitespace check) - Updated generate-quality-report.py to enforce this rule. * Fix UC_USELESS_CONDITION SpotBugs warnings Resolves "Condition has no effect" warnings in: - HTMLComponent.java (Redundant else/assignment) - CSSEngine.java (Redundant getUi() != null check) - CSSParser.java (Redundant EOF check) - RECharacter.java (Duplicate check) - ResourceThreadQueue.java (Simplified boolean check) - Component.java (Redundant isFlatten() || !opaque check) - CodenameOneImplementation.java (Redundant width/height check) - MathUtil.java (Redundant huge + x > one check) - MenuBar.java (Dead code removal for ICS check) - ComponentGroup.java (Refactored logic) - Updated generate-quality-report.py to enforce this rule. * Fix UC_USELESS_CONDITION SpotBugs warnings Resolves "Condition has no effect" warnings in: - CodenameOneImplementation.java (Redundant width/height check) - MathUtil.java (Redundant huge + x > one check) - Component.java (Redundant isFlatten() || !opaque check) - HTMLComponent.java (Redundant else/assignment) - ResourceThreadQueue.java (Simplified boolean check) - CSSEngine.java (Redundant getUi() != null check) - CSSParser.java (Redundant EOF check) - MenuBar.java (Dead code removal for ICS check) - ComponentGroup.java (Refactored logic) - Updated generate-quality-report.py to enforce this rule. * Fix UC_USELESS_CONDITION SpotBugs warnings across multiple files This change resolves "Condition has no effect" (UC_USELESS_CONDITION) warnings reported by SpotBugs in several core classes including Component, MenuBar, CSSEngine, CSSParser, and MathUtil. It also updates the quality report generation script to enforce this rule in CI. Key changes: - `Component.java`: Refactored `paintLock` logic to remove redundant checks. - `ComponentGroup.java`: Simplified boolean logic in `updateUIIDs` to avoid redundancy. - `MenuBar.java`: Removed dead code related to deprecated ICS command behavior. - `CSSEngine.java`: Made `fontSize` range check explicit. - `CSSParser.java`: Improved EOF check readability in whitespace loop. - `MathUtil.java`: Removed redundant floating-point precision checks in `asin` and `atan`. - `.github/scripts/generate-quality-report.py`: Added `UC_USELESS_CONDITION` to the list of enforced rules. * Fix SpotBugs UC_USELESS_CONDITION warnings and enforce check in CI Fixed multiple instances of 'Condition has no effect' (UC_USELESS_CONDITION) in core classes including Grid, MenuBar, MathUtil, Component, and others. Updated generate-quality-report.py to treat this violation as a build failure. * Fix remaining SpotBugs UC_USELESS_CONDITION warnings Fixed multiple instances of 'Condition has no effect' (UC_USELESS_CONDITION) in core classes: * CodenameOne/src/com/codename1/util/MathUtil.java: Fixed bitwise shift logic in `ieee754_pow` (`>>>` to `>>`) to restore correct negative number handling. * CodenameOne/src/com/codename1/ui/MenuBar.java: Removed redundant `COMMAND_BEHAVIOR_ICS` check. * CodenameOne/src/com/codename1/ui/Component.java: Removed duplicate `!animateBackground` check. * CodenameOne/src/com/codename1/ui/ComponentGroup.java: Removed redundant `if (count > 1)` check. * CodenameOne/src/com/codename1/ui/html/CSSParser.java: Removed redundant whitespace check. * CodenameOne/src/com/codename1/ui/html/HTMLComponent.java: Removed redundant whitespace check. * CodenameOne/src/com/codename1/xml/XMLParser.java: Removed redundant whitespace check. * CodenameOne/src/com/codename1/ui/html/CSSEngine.java: Removed redundant whitespace check. * CodenameOne/src/com/codename1/impl/CodenameOneImplementation.java: Refactored `setCommandBehavior` condition logic. * Fix remaining SpotBugs UC_USELESS_CONDITION warnings Addressed persistent SpotBugs warnings in core classes: * CodenameOne/src/com/codename1/util/MathUtil.java: Removed redundant `if (ix >= 0x3ff00000)` check in `ieee754_pow` as it is logically implied by previous conditions. * CodenameOne/src/com/codename1/ui/MenuBar.java: Removed redundant `COMMAND_BEHAVIOR_SIDE_NAVIGATION` check which was impossible in the given context. * CodenameOne/src/com/codename1/impl/CodenameOneImplementation.java: Removed redundant `(c == 10)` check in `isWhitespace` as `\n` (10) was already checked. * CodenameOne/src/com/codename1/ui/html/HTMLComponent.java, CSSParser.java, XMLParser.java, CSSEngine.java: Standardized whitespace checks to remove redundancy (`\n` vs 10) and ensured consistency. These fixes clean up logic errors and redundant code flagged by strict static analysis. * Fix SpotBugs UC_USELESS_CONDITION warnings and restore MathUtil behavior Fixed multiple instances of 'Condition has no effect' (UC_USELESS_CONDITION) in core classes. Restored `MathUtil.ieee754_pow` to use logical right shift (`>>>`) to preserve original behavior for negative inputs, while removing the dead code blocks that SpotBugs flagged to resolve the static analysis violation. Fixes: * CodenameOne/src/com/codename1/util/MathUtil.java: Reverted `n` calculation to `>>>` and removed dead code blocks. * CodenameOne/src/com/codename1/ui/MenuBar.java: Removed redundant `COMMAND_BEHAVIOR_SIDE_NAVIGATION` check. * CodenameOne/src/com/codename1/impl/CodenameOneImplementation.java: Removed redundant `(c == 10)` check in `isWhitespace`. * CodenameOne/src/com/codename1/ui/html/HTMLComponent.java, CSSParser.java, XMLParser.java, CSSEngine.java: Standardized whitespace checks. * Fix SpotBugs UC_USELESS_CONDITION warnings and correct MathUtil pow logic Fixed multiple instances of 'Condition has no effect' (UC_USELESS_CONDITION) in core classes. Corrected `MathUtil.ieee754_pow` to use arithmetic right shift (`>>`) instead of logical right shift (`>>>`) for negative input handling, restoring correct mathematical behavior while removing the redundant `if (ix >= 0x3ff00000)` check that flagged the static analysis violation. Fixes: * CodenameOne/src/com/codename1/util/MathUtil.java: Corrected bitwise logic for `n` calculation and removed redundant condition. * CodenameOne/src/com/codename1/ui/MenuBar.java: Removed redundant `COMMAND_BEHAVIOR_SIDE_NAVIGATION` check. * CodenameOne/src/com/codename1/impl/CodenameOneImplementation.java: Removed redundant `(c == 10)` check in `isWhitespace`. * CodenameOne/src/com/codename1/ui/html/HTMLComponent.java, CSSParser.java, XMLParser.java, CSSEngine.java: Standardized whitespace checks. * Update CodenameOne/src/com/codename1/xml/XMLParser.java Co-authored-by: Copilot <[email protected]> * Restored code that Jules removed, probably incorrectly --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Shai Almog <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 365b110 commit 73565cb

File tree

14 files changed

+127
-171
lines changed

14 files changed

+127
-171
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: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3651,7 +3651,7 @@ public int getCharLocation(String source, int index) {
36513651
}
36523652

36533653
private boolean isWhitespace(char c) {
3654-
return c == ' ' || (c == '\n') || (c == '\t') || (c == 10) || (c == 13);
3654+
return c == ' ' || (c == '\n') || (c == '\t') || (c == 13);
36553655
}
36563656

36573657
/**
@@ -7447,9 +7447,10 @@ public int getCommandBehavior() {
74477447
* @param commandBehavior the commandBehavior to set
74487448
*/
74497449
public void setCommandBehavior(int commandBehavior) {
7450-
// PMD Fix (CollapsibleIfStatements): Combine touch capability and behavior checks.
7451-
if (!isTouchDevice() && commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR) {
7452-
commandBehavior = Display.COMMAND_BEHAVIOR_SOFTKEY;
7450+
if (commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR) {
7451+
if (!isTouchDevice()) {
7452+
commandBehavior = Display.COMMAND_BEHAVIOR_SOFTKEY;
7453+
}
74537454
}
74547455
this.commandBehavior = commandBehavior;
74557456
notifyCommandBehavior(commandBehavior);
@@ -8475,14 +8476,14 @@ protected int drawLabelText(Object nativeGraphics, int textDecoration, boolean r
84758476
// Instead we simple reposition the text, and draw the 3 points, this is quite simple, but
84768477
// the downside is that a part of a letter may be shown here as well.
84778478

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-
}
84858479
if (rtl) {
8480+
if (!isTickerRunning && endsWith3Points) {
8481+
// PMD Fix (CollapsibleIfStatements): Separate combined RTL and ticker checks into a single conditional.
8482+
String points = "...";
8483+
int pointsW = stringWidth(nativeFont, points);
8484+
drawString(nativeGraphics, nativeFont, points, shiftText + x, y, textDecoration, fontHeight);
8485+
clipRect(nativeGraphics, pointsW + shiftText + x, y, textSpaceW - pointsW, fontHeight);
8486+
}
84868487
x = x - txtW + textSpaceW;
84878488
} else if (endsWith3Points) {
84888489
String points = "...";

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

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3548,20 +3548,11 @@ public boolean contains(int x, int y) {
35483548
* @see #contains(int, int)
35493549
*/
35503550
public boolean visibleBoundsContains(int x, int y) {
3551-
boolean contains = isVisible() && contains(x, y);
3552-
if (contains) {
3553-
Container parent = getParent();
3554-
while (parent != null) {
3555-
if (!parent.visibleBoundsContains(x, y)) {
3556-
contains = false;
3557-
}
3558-
if (!contains) {
3559-
break;
3560-
}
3561-
parent = parent.getParent();
3562-
}
3551+
if (!isVisible() || !contains(x, y)) {
3552+
return false;
35633553
}
3564-
return contains;
3554+
Container parent = getParent();
3555+
return parent == null || parent.visibleBoundsContains(x, y);
35653556
}
35663557

35673558
/**
@@ -5142,8 +5133,8 @@ public void run() {
51425133
view = new Rectangle(getScrollX(), getScrollY(), w, h - invisibleAreaUnderVKB);
51435134
//if the dragging component is out of bounds move the scrollable parent
51445135
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())) {
5136+
if ((scrollParent.isScrollableY() && scrollParent.getScrollY() + (draggedy + getHeight()) < scrollParent.getScrollDimension().getHeight()) ||
5137+
(scrollParent.isScrollableX() && scrollParent.getScrollX() + (draggedx + getWidth()) < scrollParent.getScrollDimension().getWidth())) {
51475138
int yposition = draggedy - scrollParent.getAbsoluteY() - 40;
51485139
if (yposition < 0) {
51495140
yposition = 0;
@@ -5816,10 +5807,7 @@ private void pointerReleaseImpl(Component lead, int x, int y) {
58165807
return;
58175808
}
58185809

5819-
int scroll = scrollY;
5820-
if (shouldScrollX) {
5821-
scroll = scrollX;
5822-
}
5810+
int scroll = shouldScrollX ? scrollX : scrollY;
58235811
float speed = getDragSpeed(!shouldScrollX);
58245812
int tl;
58255813
if (getTensileLength() > -1) {
@@ -6557,7 +6545,7 @@ public boolean animate() {
65576545
}
65586546

65596547
if (!animateBackground && (destScrollY == -1 || destScrollY == scrollY) &&
6560-
!animateBackground && m == null && draggedMotionY == null &&
6548+
m == null && draggedMotionY == null &&
65616549
draggedMotionX == null && !dragActivated) {
65626550
tryDeregisterAnimated();
65636551
}
@@ -7393,15 +7381,12 @@ public Image paintLock(boolean hardLock) {
73937381
paintInternalImpl(((Image) paintLockImage).getGraphics(), false);
73947382
setX(x);
73957383
setY(y);
7396-
if (hardLock) {
7397-
return (Image) paintLockImage;
7398-
} else {
7384+
if (!hardLock) {
73997385
paintLockImage = Display.getInstance().createSoftWeakRef(paintLockImage);
74007386
}
7401-
} else {
7402-
if (hardLock) {
7403-
return (Image) paintLockImage;
7404-
}
7387+
}
7388+
if (hardLock) {
7389+
return (Image) paintLockImage;
74057390
}
74067391
return null;
74077392
}

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package com.codename1.ui;
2525

2626
import com.codename1.ui.layouts.BoxLayout;
27+
import com.codename1.ui.layouts.Layout;
2728

2829
/**
2930
* <p>A component group is a container that applies the given UIID to a set of components within it
@@ -104,16 +105,17 @@ void insertComponentAt(int index, Object con, Component cmp) {
104105
*/
105106
public void refreshTheme(boolean merge) {
106107
super.refreshTheme(merge);
107-
if (!getUIManager().isThemeConstant(groupFlag, false) && !forceGroup) {
108+
boolean ignoreGroup = getUIManager().isThemeConstant(groupFlag, false);
109+
if (ignoreGroup || forceGroup) {
110+
updateUIIDs();
111+
} else {
108112
if (uiidsDirty) {
109113
uiidsDirty = false;
110114
int count = getComponentCount();
111115
for (int iter = 0; iter < count; iter++) {
112116
restoreUIID(getComponentAt(iter));
113117
}
114118
}
115-
} else {
116-
updateUIIDs();
117119
}
118120
}
119121

@@ -137,7 +139,7 @@ private String elementPrefix(Component c) {
137139
}
138140

139141
private void updateUIIDs() {
140-
if (!getUIManager().isThemeConstant(groupFlag, false) && !forceGroup) {
142+
if (!(getUIManager().isThemeConstant(groupFlag, false) || forceGroup)) {
141143
return;
142144
}
143145
int count = getComponentCount();
@@ -149,13 +151,11 @@ private void updateUIIDs() {
149151
} else {
150152
Component c = getComponentAt(0);
151153
updateUIID(elementPrefix(c) + "First", c);
152-
if (count > 1) {
153-
c = getComponentAt(count - 1);
154-
updateUIID(elementPrefix(c) + "Last", c);
155-
for (int iter = 1; iter < count - 1; iter++) {
156-
c = getComponentAt(iter);
157-
updateUIID(elementPrefix(c), c);
158-
}
154+
c = getComponentAt(count - 1);
155+
updateUIID(elementPrefix(c) + "Last", c);
156+
for (int iter = 1; iter < count - 1; iter++) {
157+
c = getComponentAt(iter);
158+
updateUIID(elementPrefix(c), c);
159159
}
160160
}
161161
}
@@ -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
/**
@@ -263,10 +267,7 @@ public Object getPropertyValue(String name) {
263267
return groupFlag;
264268
}
265269
if (name.equals("forceGroup")) {
266-
if (forceGroup) {
267-
return Boolean.TRUE;
268-
}
269-
return Boolean.FALSE;
270+
return forceGroup ? Boolean.TRUE : Boolean.FALSE;
270271
}
271272
return null;
272273
}

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

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ public void actionPerformed(ActionEvent evt) {
595595
// the list for the menu sent the event
596596
if (src instanceof Button) {
597597
for (int iter = 0; iter < soft.length; iter++) {
598-
if (src == soft[iter]) {
598+
if (soft[iter].equals(src)) {
599599
Container parent = commandList.getParent();
600600
while (parent != null) {
601601
if (parent instanceof Dialog) {
@@ -751,12 +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-
c = result;
756-
if (c != null) {
757-
ActionEvent e = new ActionEvent(c, ActionEvent.Type.Command);
758-
c.actionPerformed(e);
759-
}
754+
if (!isTouchMenus() && c != null) {
755+
ActionEvent e = new ActionEvent(c, ActionEvent.Type.Command);
756+
c.actionPerformed(e);
760757
}
761758
}
762759
// menu item was handled internally in a touch interface that is not a touch menu
@@ -1058,9 +1055,7 @@ public void addCommand(Command cmd) {
10581055
return;
10591056
}
10601057
if (parent.getBackCommand() != cmd) {
1061-
if ((behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK ||
1062-
behavior == Display.COMMAND_BEHAVIOR_ICS ||
1063-
behavior == Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION)
1058+
if ((behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK)
10641059
&& parent.getTitle() != null && parent.getTitle().length() > 0) {
10651060
synchronizeCommandsWithButtonsInBackbutton();
10661061
return;
@@ -1500,17 +1495,11 @@ protected Command showMenuDialog(Dialog menu) {
15001495
marginRight = marginLeft;
15011496
marginLeft = 0;
15021497
}
1503-
if (getCommandBehavior() == Display.COMMAND_BEHAVIOR_ICS) {
1504-
menu.setTransitionOutAnimator(transitionIn);
1505-
menu.setTransitionInAnimator(transitionOut);
1506-
int th = getTitleAreaContainer().getHeight();
1507-
return menu.show(th, height - th, marginLeft, marginRight, true);
1498+
1499+
if (manager.getLookAndFeel().isTouchMenus() && manager.isThemeConstant("PackTouchMenuBool", true)) {
1500+
return menu.showPacked(BorderLayout.SOUTH, true);
15081501
} else {
1509-
if (manager.getLookAndFeel().isTouchMenus() && manager.isThemeConstant("PackTouchMenuBool", true)) {
1510-
return menu.showPacked(BorderLayout.SOUTH, true);
1511-
} else {
1512-
return menu.show(height, 0, marginLeft, marginRight, true);
1513-
}
1502+
return menu.show(height, 0, marginLeft, marginRight, true);
15141503
}
15151504
}
15161505

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ private boolean containsClass(String elementClass, String selectorClass) {
467467
* @param htmlC The HTMLComponent
468468
*/
469469
private void applyStyle(HTMLElement element, CSSElement selector, HTMLComponent htmlC) {
470-
if ((element.getUi() != null) && (element.getUi().size() > 0)) {
470+
if (element.getUi().size() > 0) {
471471
if (!HTMLComponent.PROCESS_HTML_MP1_ONLY) {
472472
String reset = selector.getAttributeById(CSSElement.CSS_COUNTER_RESET);
473473
if (reset != null) {
@@ -807,7 +807,7 @@ private void setNowrapRecursive(final HTMLElement element) {
807807
String newText = "";
808808
for (int c = 0; c < text.length(); c++) {
809809
char ch = text.charAt(c);
810-
if ((ch == ' ') || (ch == 10) || (ch == 13) || (ch == '\t') || (ch == '\n')) {
810+
if ((ch == ' ') || (ch == '\n') || (ch == '\r') || (ch == '\t')) {
811811
if (!word.equals("")) {
812812
newText += word + " ";
813813
word = "";
@@ -1338,9 +1338,7 @@ private void applyStyleToUIElement(Component ui, CSSElement selector, HTMLElemen
13381338

13391339
// Text indentation
13401340
int indent = selector.getAttrLengthVal(CSSElement.CSS_TEXT_INDENT, ui, htmlC.getWidth());
1341-
if (indent >= 0) { // Only positive (0 also as it may cancel previous margins)
1342-
setTextIndentationRecursive(ui, indent);
1343-
}
1341+
setTextIndentationRecursive(ui, indent);
13441342

13451343
//
13461344
// Font
@@ -1362,7 +1360,7 @@ private void applyStyleToUIElement(Component ui, CSSElement selector, HTMLElemen
13621360
int fontWeight = selector.getAttrVal(CSSElement.CSS_FONT_WEIGHT);
13631361

13641362
int fontSize = selector.getAttrLengthVal(CSSElement.CSS_FONT_SIZE, ui, ui.getStyle().getFont().getHeight());
1365-
if (fontSize < -1) {
1363+
if (fontSize < 0 && fontSize != -1) {
13661364
int curSize = ui.getStyle().getFont().getHeight();
13671365
if (fontSize == CSSElement.FONT_SIZE_LARGER) {
13681366
fontSize = curSize + 2;
@@ -1462,8 +1460,9 @@ private void applyStyleToUIElement(Component ui, CSSElement selector, HTMLElemen
14621460
if ((styles & STYLE_PRESSED) != 0) {
14631461
borderUi.getPressedStyle().setBorder(border);
14641462
}
1465-
if (borderUi.getParent() != null) {
1466-
borderUi.getParent().revalidate();
1463+
Container borderUiParent = borderUi.getParent();
1464+
if (borderUiParent != null) {
1465+
borderUiParent.revalidate();
14671466
} else if (borderUi instanceof Container) {
14681467
((Container) borderUi).revalidate();
14691468
}
@@ -1669,9 +1668,8 @@ private void applyStyleToUIElement(Component ui, CSSElement selector, HTMLElemen
16691668
}
16701669

16711670
private void addOutlineToStyle(Style style, Border outline) {
1672-
Border curBorder = style.getBorder();
1673-
if (curBorder != null) {
1674-
curBorder.addOuterBorder(outline);
1671+
if (style.getBorder() != null) {
1672+
style.getBorder().addOuterBorder(outline);
16751673
} else {
16761674
style.setBorder(outline);
16771675
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void setCSSSupportedMediaTypes(String[] supportedMediaTypes) {
8787
* @return true if the character is a white space, false otherwise
8888
*/
8989
static boolean isWhiteSpace(char ch) {
90-
return ((ch == ' ') || (ch == '\n') || (ch == '\t') || (ch == 10) || (ch == 13));
90+
return ((ch == ' ') || (ch == '\n') || (ch == '\t') || (ch == '\r'));
9191
}
9292

9393

@@ -102,12 +102,12 @@ 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
}
109109
c = r.readCharFromReader();
110-
while (((byte) c) != -1 && isWhiteSpace(c)) { //skip white spaces
110+
while (c != (char)-1 && isWhiteSpace(c)) { //skip white spaces
111111
c = r.readCharFromReader();
112112
}
113113
} else {
@@ -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

0 commit comments

Comments
 (0)