Skip to content

Commit 4efa565

Browse files
authored
tail end of big spotbugs issues (#4419)
1 parent 4897803 commit 4efa565

File tree

5 files changed

+69
-15
lines changed

5 files changed

+69
-15
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ def main() -> None:
778778
"FE_FLOATING_POINT_EQUALITY",
779779
"FE_TEST_IF_EQUAL_TO_NOT_A_NUMBER",
780780
"ICAST_IDIV_CAST_TO_DOUBLE",
781+
"ICAST_QUESTIONABLE_UNSIGNED_RIGHT_SHIFT",
781782
"SA_FIELD_SELF_ASSIGNMENT",
782783
"UC_USELESS_CONDITION",
783784
"UC_USELESS_OBJECT",
@@ -824,6 +825,7 @@ def main() -> None:
824825
"NP_LOAD_OF_KNOWN_NULL_VALUE",
825826
"NP_BOOLEAN_RETURN_NULL",
826827
"RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN",
828+
"OS_OPEN_STREAM",
827829
"REFLC_REFLECTION_MAY_INCREASE_ACCESSIBILITY_OF_CLASS",
828830
"REC_CATCH_EXCEPTION",
829831
"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE",
@@ -865,6 +867,8 @@ def _is_exempt(f: Finding) -> bool:
865867
return True
866868
if f.rule == "NN_NAKED_NOTIFY" and "Display.java" in loc:
867869
return True
870+
if f.rule == "ICAST_QUESTIONABLE_UNSIGNED_RIGHT_SHIFT" and "Deflate.java" in loc:
871+
return True
868872
return False
869873

870874

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3966,22 +3966,19 @@ public Rectangle getDisplaySafeArea(Rectangle rect) {
39663966
* common constants in this class or be a user/implementation defined sound
39673967
*/
39683968
public void playBuiltinSound(String soundIdentifier) {
3969-
boolean played = playUserSound(soundIdentifier);
3970-
if (!played) {
3971-
return;
3972-
}
3969+
playUserSound(soundIdentifier);
39733970
}
39743971

39753972
/**
39763973
* Plays a sound defined by the user
39773974
*
39783975
* @param soundIdentifier the sound identifier which can match one of the
39793976
* common constants in this class or be a user/implementation defined sound
3980-
* @return true if a user sound exists and was sent to playback
39813977
*/
3982-
protected boolean playUserSound(String soundIdentifier) {
3983-
Object sound = builtinSounds.get(soundIdentifier);
3984-
return sound != null;
3978+
protected void playUserSound(String soundIdentifier) {
3979+
// TODO: Reintroduce builitin sound support
3980+
//Object sound = builtinSounds.get(soundIdentifier);
3981+
//return sound != null;
39853982
//playAudio(sound);
39863983
}
39873984

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package com.codename1.impl;
2424

2525
import com.codename1.io.Log;
26+
import com.codename1.io.Util;
2627
import com.codename1.ui.Display;
2728

2829
import java.io.DataInputStream;
@@ -133,6 +134,8 @@ public void storeStackForException(Throwable t, int currentStackFrame) {
133134
* Prints the stack trace matching the given stack
134135
*/
135136
public String getStack(Throwable t) {
137+
InputStream inp = null;
138+
DataInputStream di = null;
136139
try {
137140
StringBuilder b = new StringBuilder();
138141
int size;
@@ -145,11 +148,11 @@ public String getStack(Throwable t) {
145148
}
146149
String[] stk = new String[size];
147150

148-
InputStream inp = Display.getInstance().getResourceAsStream(getClass(), "/methodData.dat");
151+
inp = Display.getInstance().getResourceAsStream(getClass(), "/methodData.dat");
149152
if (inp == null) {
150153
return t.toString();
151154
}
152-
DataInputStream di = new DataInputStream(inp);
155+
di = new DataInputStream(inp);
153156
int totalAmount = di.readInt();
154157
String lastClass = "";
155158
for (int x = 0; x < totalAmount; x++) {
@@ -172,6 +175,9 @@ public String getStack(Throwable t) {
172175
return b.toString();
173176
} catch (IOException ex) {
174177
ex.printStackTrace();
178+
} finally {
179+
Util.cleanup(di);
180+
Util.cleanup(inp);
175181
}
176182
return "Failed in stack generation for " + t;
177183
}

CodenameOne/src/com/codename1/testing/DeviceRunner.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package com.codename1.testing;
2424

2525
import com.codename1.io.Log;
26+
import com.codename1.io.Util;
2627
import com.codename1.ui.CN;
2728
import com.codename1.ui.Display;
2829

@@ -48,8 +49,10 @@ public void runTests() {
4849
failedTests = 0;
4950
passedTests = 0;
5051
Log.p("-----STARTING TESTS-----");
52+
InputStream is = null;
53+
DataInputStream di = null;
5154
try {
52-
InputStream is = DeviceRunner.class.getResourceAsStream("/tests.dat");
55+
is = DeviceRunner.class.getResourceAsStream("/tests.dat");
5356

5457
if (is == null) {
5558
is = Display.getInstance().getResourceAsStream(null, "/tests.dat");
@@ -60,7 +63,7 @@ public void runTests() {
6063
System.exit(2);
6164
return;
6265
}
63-
DataInputStream di = new DataInputStream(is);
66+
di = new DataInputStream(is);
6467
int version = di.readInt();
6568
if (version > VERSION) {
6669
Log.p("Tests were built with a new version of Codename One and can't be executed with this runner");
@@ -72,13 +75,16 @@ public void runTests() {
7275
for (int iter = 0; iter < tests.length; iter++) {
7376
tests[iter] = di.readUTF();
7477
}
75-
di.close();
78+
Util.cleanup(di);
7679

77-
for (int iter = 0; iter < tests.length; iter++) {
78-
runTest(tests[iter]);
80+
for (String test : tests) {
81+
runTest(test);
7982
}
8083
} catch (IOException err) {
8184
TestReporting.getInstance().logException(err);
85+
} finally {
86+
Util.cleanup(is);
87+
Util.cleanup(di);
8288
}
8389
TestReporting.getInstance().testExecutionFinished(getClass().getName());
8490
if (failedTests > 0) {

maven/core-unittests/spotbugs-exclude.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,47 @@
151151
<Class name="~com\.codename1\.io\.gzip\.Inflate.*" />
152152
<Bug pattern="SF_SWITCH_FALLTHROUGH" />
153153
</Match>
154+
<Match>
155+
<Class name="~com\.codename1\.io\.gzip\.Deflate.*" />
156+
<Bug pattern="ICAST_QUESTIONABLE_UNSIGNED_RIGHT_SHIFT" />
157+
</Match>
158+
159+
<!--
160+
There are two failures for this specific bug:
161+
com.codename1.ui.Container.setLightweightMode(boolean)
162+
com.codename1.impl.CodenameOneImplementation.playBuiltinSound(String)
163+
164+
Lightweight mode is useful in peer components, which is only
165+
visible in the native layer (invisible to spotbugs).
166+
playBuiltinSound seems unused, but we probably would want to fix
167+
that at some point.
168+
-->
169+
<Match>
170+
<Bug pattern="UC_USELESS_VOID_METHOD" />
171+
</Match>
172+
173+
<!--
174+
These are actual bugs we're ignoring specifically:
175+
components isn't initialized in com.codename1.ui.Container.initLaf(UIManager) when invoked from constructor for superclass
176+
fontIconSize isn't initialized in com.codename1.ui.Label.initLaf(UIManager) when invoked from constructor for superclass
177+
materialIconSize isn't initialized in com.codename1.ui.Label.initLaf(UIManager) when invoked from constructor for superclass
178+
179+
Unfortunately, we can't fix them without breaking Codename One.
180+
initLaf is deeply embedded in the code and the constructor chain,
181+
and we just can't fix it properly.
182+
-->
183+
<Match>
184+
<Bug pattern="UR_UNINIT_READ_CALLED_FROM_SUPER_CONSTRUCTOR" />
185+
</Match>
186+
187+
<!--
188+
This fires for timed waits which shouldn't be in a loop.
189+
It's a bad check. In one particular case, it also misses a loop
190+
in the parent (EDT main loop).
191+
-->
192+
<Match>
193+
<Bug pattern="WA_NOT_IN_LOOP" />
194+
</Match>
154195

155196
<!--
156197
This rule is a bit broad for the complex threading logic in Display.

0 commit comments

Comments
 (0)