Skip to content

Commit aeb7815

Browse files
committed
Fixed a bug and excluded some spotbugs tests
1 parent 4802879 commit aeb7815

File tree

5 files changed

+62
-18
lines changed

5 files changed

+62
-18
lines changed

CodenameOne/src/com/codename1/capture/Capture.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,10 @@ public void run() {
267267
while (!completed) {
268268
synchronized (this) {
269269
try {
270-
this.wait();
270+
// we need to recheck the condition within the synchronized block (double locking)
271+
if(!completed) {
272+
this.wait();
273+
}
271274
} catch (InterruptedException ex) {
272275
}
273276
}

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ static Motion getRippleMotion() {
260260
return rippleMotion;
261261
}
262262

263+
static void setRippleMotion(Motion m) {
264+
rippleMotion = m;
265+
}
266+
263267
/**
264268
* Sets the title after invoking the constructor
265269
*
@@ -3107,8 +3111,9 @@ static void setRippleComponent(Component cmp) {
31073111

31083112
private void initRippleEffect(int x, int y, Component cmp) {
31093113
if (cmp.isRippleEffect()) {
3110-
rippleMotion = Motion.createEaseInMotion(0, 1000, 800);
3111-
rippleMotion.start();
3114+
Motion motion = Motion.createEaseInMotion(0, 1000, 800);
3115+
motion.start();
3116+
setRippleMotion(motion);
31123117
setRippleComponent(cmp);
31133118
rippleX = x;
31143119
rippleY = y;
@@ -3391,7 +3396,7 @@ public void pointerDragged(int x, int y) {
33913396
}
33923397
}
33933398

3394-
rippleMotion = null;
3399+
setRippleMotion(null);
33953400

33963401
if (dragged != null) {
33973402
LeadUtil.pointerDragged(dragged, x, y);
@@ -3463,7 +3468,7 @@ public void pointerDragged(int[] x, int[] y) {
34633468
}
34643469
}
34653470

3466-
rippleMotion = null;
3471+
setRippleMotion(null);
34673472

34683473
if (dragged != null) {
34693474
LeadUtil.pointerDragged(dragged, x, y);
@@ -3668,7 +3673,7 @@ private boolean fireReleaseListeners(int x, int y) {
36683673
public void pointerReleased(int x, int y) {
36693674
try {
36703675
Component origPressedCmp = pressedCmp;
3671-
rippleMotion = null;
3676+
setRippleMotion(null);
36723677
setPressedCmp(null);
36733678
boolean isScrollWheeling = Display.impl.isScrollWheeling();
36743679
Container actual = getActualPane(formLayeredPane, x, y);

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ public final class PlatformDefaults {
118118
* to specify the visual padding.
119119
* <p>
120120
*/
121-
public static final String VISUAL_PADDING_PROPERTY = "visualPadding";
121+
public static final String VISUAL_PADDING_PROPERTY = "visualPadding";
122122
static BoundSize RELATED_X = null, RELATED_Y = null, UNRELATED_X = null, UNRELATED_Y = null;
123123
private static int DEF_H_UNIT = UnitValue.LPX;
124124
private static int DEF_V_UNIT = UnitValue.LPY;
125125
private static InCellGapProvider GAP_PROVIDER = null;
126-
private static volatile int MOD_COUNT = 0;
126+
private static int MOD_COUNT = 0;
127127
private static int CUR_PLAF = WINDOWS_XP;
128128
private static String BUTTON_FORMAT = null;
129129
private static BoundSize DEF_VGAP = null, DEF_HGAP = null;
@@ -342,7 +342,7 @@ public static Float getHorizontalScaleFactor() {
342342
public static void setHorizontalScaleFactor(Float f) {
343343
if (!LayoutUtil.equals(horScale, f)) {
344344
horScale = f;
345-
MOD_COUNT++;
345+
incModeCount();
346346
}
347347
}
348348

@@ -371,7 +371,7 @@ public static Float getVerticalScaleFactor() {
371371
public static void setVerticalScaleFactor(Float f) {
372372
if (!LayoutUtil.equals(verScale, f)) {
373373
verScale = f;
374-
MOD_COUNT++;
374+
incModeCount();
375375
}
376376
}
377377

@@ -401,7 +401,7 @@ public static void setLogicalPixelBase(int base) {
401401
throw new IllegalArgumentException("Unrecognized base: " + base);
402402

403403
LP_BASE = base;
404-
MOD_COUNT++;
404+
incModeCount();
405405
}
406406
}
407407

@@ -465,7 +465,7 @@ public static void setGridCellGap(UnitValue x, UnitValue y) {
465465
if (y != null)
466466
DEF_VGAP = new BoundSize(y, y, null, null);
467467

468-
MOD_COUNT++;
468+
incModeCount();
469469
}
470470

471471
/**
@@ -484,7 +484,7 @@ public static UnitValue getMinimumButtonWidth() {
484484
*/
485485
public static void setMinimumButtonWidth(UnitValue width) {
486486
BUTT_WIDTH = width;
487-
MOD_COUNT++;
487+
incModeCount();
488488
}
489489

490490
/**
@@ -525,7 +525,7 @@ public static void setUnitValue(String[] unitStrings, UnitValue x, UnitValue y)
525525
if (y != null)
526526
VER_DEFS.put(s, y);
527527
}
528-
MOD_COUNT++;
528+
incModeCount();
529529
}
530530

531531
/**
@@ -587,7 +587,7 @@ public static String getButtonOrder() {
587587
*/
588588
public static void setButtonOrder(String order) {
589589
BUTTON_FORMAT = order;
590-
MOD_COUNT++;
590+
incModeCount();
591591
}
592592

593593
/**
@@ -678,7 +678,7 @@ public static void setDialogInsets(UnitValue top, UnitValue left, UnitValue bott
678678
if (right != null)
679679
DIALOG_INS[3] = right;
680680

681-
MOD_COUNT++;
681+
incModeCount();
682682
}
683683

684684
/**
@@ -712,7 +712,7 @@ public static void setPanelInsets(UnitValue top, UnitValue left, UnitValue botto
712712
if (right != null)
713713
PANEL_INS[3] = right;
714714

715-
MOD_COUNT++;
715+
incModeCount();
716716
}
717717

718718
/**
@@ -777,6 +777,10 @@ public static int getModCount() {
777777
return MOD_COUNT;
778778
}
779779

780+
private static void incModeCount() {
781+
MOD_COUNT++;
782+
}
783+
780784
/**
781785
* Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
782786
*

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,10 @@ public boolean isBackgroundPainter() {
627627
return true;
628628
}
629629

630+
private static void setContext(Context ctx) {
631+
context = ctx;
632+
}
633+
630634
/**
631635
* {@inheritDoc }
632636
*/
@@ -647,7 +651,7 @@ public void paintBorderBackground(Graphics g, Component c) {
647651
calculateContentRect(c.getWidth(), c.getHeight(), contentRect);
648652
contentRect.setX(contentRect.getX() + c.getX());
649653
contentRect.setY(contentRect.getY() + c.getY());
650-
context = new Context(c, contentRect);
654+
setContext(new Context(c, contentRect));
651655
String borderPathKey = "$$CSSBorderPath";
652656
GeneralPath p = (GeneralPath) c.getClientProperty(borderPathKey);
653657
if (p == null) {

maven/core-unittests/spotbugs-exclude.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@
7575
<Bug pattern="CN_IDIOM_NO_SUPER_CALL"/>
7676
</Match>
7777

78+
<!--
79+
This fails on writing to a static field from a non-static method.
80+
This is a bad practice in general because it could indicate a state
81+
that changes across threads. However, in our case, we have many such
82+
fields and threads are typically mostly the EDT. The risk is much lower
83+
as a result.
84+
-->
85+
<Match>
86+
<Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD"/>
87+
</Match>
88+
89+
<!--
90+
Since the code runs on the clientside performance is more important than
91+
abstraction. We don't always copy values or wrap them in immutable data.
92+
-->
93+
<Match>
94+
<Bug pattern="EI_EXPOSE_REP"/>
95+
</Match>
96+
<Match>
97+
<Bug pattern="EI_EXPOSE_REP2"/>
98+
</Match>
7899

79100
<!-- Match>
80101
<Bug pattern="UI_INHERITANCE_UNSAFE_GETRESOURCE"/>
@@ -104,6 +125,13 @@
104125
<Bug pattern="ES_COMPARING_STRINGS_WITH_EQ" />
105126
</Match>
106127

128+
<!-- The API should return null when the value isn't found -->
129+
<Match>
130+
<Class name="~com\.codename1\.plaf\.UIManager" />
131+
<Method name="isThemeConstant" />
132+
<Bug pattern="NP_BOOLEAN_RETURN_NULL" />
133+
</Match>
134+
107135
<!-- Deprecated classes that should be excluded from checks -->
108136
<Match>
109137
<Class name="~com\.codename1\.db\.ThreadSafeDatabase.*" />

0 commit comments

Comments
 (0)