Skip to content

Commit 4897803

Browse files
authored
Fix SpotBugs warnings and tighten gates (#4418)
1 parent da736bf commit 4897803

File tree

9 files changed

+19
-11
lines changed

9 files changed

+19
-11
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ def main() -> None:
763763
if spotbugs:
764764
forbidden_rules = {
765765
"NP_ALWAYS_NULL",
766+
"NP_NULL_PARAM_DEREF",
766767
"RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE",
767768
"RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE",
768769
"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR",
@@ -772,6 +773,7 @@ def main() -> None:
772773
"IA_AMBIGUOUS_INVOCATION_OF_INHERITED_OR_OUTER_METHOD",
773774
"LI_LAZY_INIT_STATIC",
774775
"RpC_REPEATED_CONDITIONAL_TEST",
776+
"NS_NON_SHORT_CIRCUIT",
775777
"ES_COMPARING_PARAMETER_STRING_WITH_EQ",
776778
"FE_FLOATING_POINT_EQUALITY",
777779
"FE_TEST_IF_EQUAL_TO_NOT_A_NUMBER",
@@ -787,7 +789,9 @@ def main() -> None:
787789
"EQ_DOESNT_OVERRIDE_EQUALS",
788790
"CO_COMPARETO_INCORRECT_FLOATING",
789791
"DL_SYNCHRONIZATION_ON_SHARED_CONSTANT",
792+
"SSD_DO_NOT_USE_INSTANCE_LOCK_ON_SHARED_STATIC_DATA",
790793
"DLS_DEAD_LOCAL_STORE",
794+
"DLS_DEAD_LOCAL_STORE_OF_NULL",
791795
"DM_NUMBER_CTOR",
792796
"DMI_INVOKING_TOSTRING_ON_ARRAY",
793797
"EC_NULL_ARG",
@@ -819,6 +823,7 @@ def main() -> None:
819823
"NO_NOTIFY_NOT_NOTIFYALL",
820824
"NP_LOAD_OF_KNOWN_NULL_VALUE",
821825
"NP_BOOLEAN_RETURN_NULL",
826+
"RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN",
822827
"REFLC_REFLECTION_MAY_INCREASE_ACCESSIBILITY_OF_CLASS",
823828
"REC_CATCH_EXCEPTION",
824829
"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE",

CodenameOne/src/com/codename1/facebook/FacebookRESTService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,11 @@ public void numericToken(double tok) {
239239
}
240240

241241
public void keyValue(String key, String value) {
242+
if (key == null) {
243+
return;
244+
}
242245
//make sure value is not null to prevent NPE
243-
if (key != null && value == null) {
246+
if (value == null) {
244247
value = "";
245248
}
246249
getCurrent().put(key, value);

CodenameOne/src/com/codename1/io/gzip/DeflaterOutputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void write(int b) throws IOException {
8484
public void write(byte[] b, int off, int len) throws IOException {
8585
if (deflater.finished()) {
8686
throw new IOException("finished");
87-
} else if (off < 0 | len < 0 | off + len > b.length) {
87+
} else if (off < 0 || len < 0 || off + len > b.length) {
8888
throw new IndexOutOfBoundsException();
8989
} else if (len == 0) {
9090
} else {

CodenameOne/src/com/codename1/location/LocationManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public abstract class LocationManager {
5252
public static final int OUT_OF_SERVICE = 1;
5353
public static final int TEMPORARILY_UNAVAILABLE = 2;
5454
private static LocationListener listener;
55+
private static final Object LISTENER_LOCK = new Object();
5556
private LocationRequest request;
5657
private static Class backgroundlistener;
5758
private int status = TEMPORARILY_UNAVAILABLE;
@@ -198,7 +199,7 @@ protected LocationListener getLocationListener() {
198199
* from getting updates
199200
*/
200201
public void setLocationListener(final LocationListener l) {
201-
synchronized (this) {
202+
synchronized (LISTENER_LOCK) {
202203
if (listener != null) {
203204
clearListener();
204205
request = null;
@@ -243,7 +244,7 @@ protected Class getBackgroundLocationListener() {
243244
* try to create an instance and invoke the locationUpdated method
244245
*/
245246
public void setBackgroundLocationListener(Class locationListener) {
246-
synchronized (this) {
247+
synchronized (LISTENER_LOCK) {
247248
if (backgroundlistener != null) {
248249
clearBackgroundListener();
249250
}

CodenameOne/src/com/codename1/properties/InstantUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void excludeProperties(PropertyBase... exclude) {
8181
* @return true if the property was excluded from the GUI
8282
*/
8383
public boolean isExcludedProperty(PropertyBase exclude) {
84-
return exclude.getClientProperty("cn1$excludeFromUI") == Boolean.TRUE;
84+
return Boolean.TRUE.equals(exclude.getClientProperty("cn1$excludeFromUI"));
8585
}
8686

8787
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ public void putClientProperty(String key, Object value) {
16011601
* @return true if debug mode was activated
16021602
*/
16031603
public boolean isDebugMode() {
1604-
return getClientProperty("BrowserComponent.firebug") == Boolean.TRUE;
1604+
return Boolean.TRUE.equals(getClientProperty("BrowserComponent.firebug"));
16051605
}
16061606

16071607
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,13 @@ public HTMLComponent(DocumentRequestHandler handler) {
463463
* @param font The actual Codename One font object
464464
*/
465465
public static void addFont(String fontKey, Font font) {
466-
if (fontKey != null) {
467-
fontKey = fontKey.toLowerCase();
468-
} else {
466+
if (fontKey == null) {
469467
if (font.getCharset() != null) {
470468
throw new IllegalArgumentException("Font key must be non-null for bitmap fonts");
471469
}
470+
throw new IllegalArgumentException("Font key must be non-null");
472471
}
472+
fontKey = fontKey.toLowerCase();
473473
fonts.put(fontKey, new HTMLFont(fontKey, font));
474474
}
475475

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,6 @@ Style createStyle(String id, String prefix, boolean selected) {
19011901
style = new Style(getComponentStyle(baseStyle));
19021902
}
19031903
} else {
1904-
baseStyle = null;
19051904
if (selected) {
19061905
style = new Style(defaultSelectedStyle);
19071906
} else {

CodenameOne/src/com/codename1/util/TBigInteger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ public TBigInteger modPow(TBigInteger exponent, TBigInteger m) {
12401240
}
12411241
TBigInteger base = this;
12421242

1243-
if (m.isOne() | (exponent.sign > 0 & base.sign == 0)) {
1243+
if (m.isOne() || (exponent.sign > 0 && base.sign == 0)) {
12441244
return TBigInteger.ZERO;
12451245
}
12461246
if (exponent.sign == 0) {

0 commit comments

Comments
 (0)