Skip to content

Commit 085dde3

Browse files
Fix SpotBugs SS_SHOULD_BE_STATIC warnings (#4380)
* Fix SpotBugs "Unread field: should this field be static?" warnings Converted identified fields to static final constants where appropriate and removed unused fields in: - CacheMap.java - JavascriptContext.java - MapComponent.java - ArrowLinesLayer.java - Component.java - FlipTransition.java - LookAndFeel.java - DateSpinner3D.java - Spinner3D.java - SpinnerNode.java - Tree.java - CodenameOneMiGComponentWrapper.java - MigLayout.java Updated maven/core-unittests/pom.xml to fail on SpotBugs errors. * Fix SpotBugs "Unread field: should this field be static?" warnings Converted identified fields to static final constants where appropriate and removed unused fields in: - CacheMap.java - JavascriptContext.java - MapComponent.java - ArrowLinesLayer.java - Component.java - FlipTransition.java - LookAndFeel.java - DateSpinner3D.java - Spinner3D.java - SpinnerNode.java - Tree.java - CodenameOneMiGComponentWrapper.java - MigLayout.java Updated maven/core-unittests/pom.xml to fail on SpotBugs errors. Updated .github/scripts/generate-quality-report.py to fail on SS_SHOULD_BE_STATIC. * Fix SpotBugs "Unread field: should this field be static?" warnings Converted identified fields to static final constants where appropriate and removed unused fields in: - CacheMap.java - JavascriptContext.java - MapComponent.java - ArrowLinesLayer.java - Component.java - FlipTransition.java - LookAndFeel.java - DateSpinner3D.java - Spinner3D.java - SpinnerNode.java - Tree.java - CodenameOneMiGComponentWrapper.java - MigLayout.java Updated maven/core-unittests/pom.xml to fail on SpotBugs errors. Updated .github/scripts/generate-quality-report.py to fail on SS_SHOULD_BE_STATIC. * Fix SpotBugs SS_SHOULD_BE_STATIC warnings and enforce build failure Refactored several fields to be `static final` where appropriate to address "Unread field: should this field be static?" warnings. Removed unused fields in `MigLayout`, `CacheMap`, and `CodenameOneMiGComponentWrapper`. Updated `maven/core-unittests/pom.xml` to fail on error and `.github/scripts/generate-quality-report.py` to forbid `SS_SHOULD_BE_STATIC`. Modified files: - `CodenameOne/src/com/codename1/io/CacheMap.java` - `CodenameOne/src/com/codename1/javascript/JavascriptContext.java` - `CodenameOne/src/com/codename1/maps/MapComponent.java` - `CodenameOne/src/com/codename1/maps/layers/ArrowLinesLayer.java` - `CodenameOne/src/com/codename1/ui/Component.java` - `CodenameOne/src/com/codename1/ui/animations/FlipTransition.java` - `CodenameOne/src/com/codename1/ui/layouts/mig/CodenameOneMiGComponentWrapper.java` - `CodenameOne/src/com/codename1/ui/layouts/mig/MigLayout.java` - `CodenameOne/src/com/codename1/ui/plaf/LookAndFeel.java` - `CodenameOne/src/com/codename1/ui/spinner/DateSpinner3D.java` - `CodenameOne/src/com/codename1/ui/spinner/SpinnerNode.java` - `CodenameOne/src/com/codename1/ui/tree/Tree.java` - `maven/core-unittests/pom.xml` - `.github/scripts/generate-quality-report.py` --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 7b86654 commit 085dde3

File tree

15 files changed

+16
-20
lines changed

15 files changed

+16
-20
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,8 @@ def main() -> None:
808808
"UI_INHERITANCE_UNSAFE_GETRESOURCE",
809809
"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD",
810810
"UW_UNCOND_WAIT",
811-
"SIC_INNER_SHOULD_BE_STATIC_ANON"
811+
"SIC_INNER_SHOULD_BE_STATIC_ANON",
812+
"SS_SHOULD_BE_STATIC"
812813
}
813814

814815
def _is_exempt(f: Finding) -> bool:

CodenameOne/src/com/codename1/io/CacheMap.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public class CacheMap {
5050
private Vector storageCacheContentVec;
5151
private String cachePrefix = "";
5252
private boolean alwaysStore;
53-
private final int storageKey = -1;
5453

5554
/**
5655
* Default constructor

CodenameOne/src/com/codename1/javascript/JavascriptContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ public class JavascriptContext {
144144
* Whenever the objectMap exceeds this size, cleanup will be called whenever retain()
145145
* is called.
146146
*/
147-
private final int objectMapThresholdSize = 500;
147+
private static final int objectMapThresholdSize = 500;
148148
private final Random cleanupRandomizer = new Random();
149-
private final double cleanupProbability = 0.1;
149+
private static final double cleanupProbability = 0.1;
150150
private JSObject window;
151151

152152
/**

CodenameOne/src/com/codename1/maps/MapComponent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public class MapComponent extends Container {
8282
private int zoomCenterY = 0;
8383
private long lastPressed = -1;
8484
private int tapCount = 0;
85-
private final int singleTapThreshold = 200;
86-
private final int doubleTapThreshold = 200;
85+
private static final int singleTapThreshold = 200;
86+
private static final int doubleTapThreshold = 200;
8787
private ArrayList<MapListener> listeners;
8888

8989
/**

CodenameOne/src/com/codename1/maps/layers/ArrowLinesLayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636
public class ArrowLinesLayer extends LinesLayer {
3737

38-
private final int minArrowSementLength = 20;
38+
private static final int minArrowSementLength = 20;
3939
private int arrowSegmentLength = 60;
4040
private int arrowWidth = 5;
4141
private int arrowHeight = 10;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public class Component implements Animation, StyleListener, Editable {
321321
* is too slow to be useful. This may not be the case on other platforms, but, for now, we'll leave this flag on.
322322
* Later on, after evaluation, this flag will likely be removed, and the best strategy will be decided upon.
323323
*/
324-
private final boolean useLightweightElevationShadow = true;
324+
private static final boolean useLightweightElevationShadow = true;
325325
/**
326326
* This property is useful for blocking in z-order touch events, sometimes we might want to grab touch events in
327327
* a specific component without making it focusable.

CodenameOne/src/com/codename1/ui/animations/FlipTransition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public class FlipTransition extends Transition {
6262
private int transitionState = STATE_MOVE_AWAY;
6363

6464
private Motion motion;
65-
private final boolean firstFinished = false;
66-
private final boolean started = false;
65+
private static final boolean firstFinished = false;
66+
private static final boolean started = false;
6767

6868
private int bgColor = -1;
6969

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class CodenameOneMiGComponentWrapper implements ComponentWrapper {
7777
private final Component c;
7878
private int compType = TYPE_UNSET;
7979
private final Boolean bl = null;
80-
private final boolean prefCalled = false;
8180

8281
public CodenameOneMiGComponentWrapper(Component c) {
8382
this.c = c;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public final class MigLayout extends Layout {
8383
private ArrayList<LayoutCallback> callbackList = null;
8484

8585
private boolean dirty = true;
86-
private final long lastSize = 0;
8786

8887
/**
8988
* Constructor with no constraints.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ public abstract class LookAndFeel {
130130
private Image fadeScrollBottom;
131131
private Image fadeScrollRight;
132132
private Image fadeScrollLeft;
133-
private final int fadeScrollEdgeStartAlpha = 0x999999;
134-
private final int fadeScrollEdgeEndAlpha = 0;
133+
private static final int fadeScrollEdgeStartAlpha = 0x999999;
134+
private static final int fadeScrollEdgeEndAlpha = 0;
135135
private int textFieldCursorColor;
136136

137137
private boolean backgroundImageDetermineSize;

0 commit comments

Comments
 (0)