Skip to content

Commit 4a8a53e

Browse files
authored
Fixed NN_NAKED_NOTIFY Spotbugs Issues (#4417)
1 parent 3b31486 commit 4a8a53e

File tree

9 files changed

+21
-13
lines changed

9 files changed

+21
-13
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ def main() -> None:
815815
"NM_CONFUSING",
816816
"NM_FIELD_NAMING_CONVENTION",
817817
"NM_METHOD_NAMING_CONVENTION",
818+
"NN_NAKED_NOTIFY",
818819
"NO_NOTIFY_NOT_NOTIFYALL",
819820
"NP_LOAD_OF_KNOWN_NULL_VALUE",
820821
"NP_BOOLEAN_RETURN_NULL",
@@ -851,6 +852,8 @@ def _is_exempt(f: Finding) -> bool:
851852
return True
852853
if f.rule == "URF_UNREAD_FIELD" and "GridBagLayoutInfo" in loc:
853854
return True
855+
if f.rule == "NN_NAKED_NOTIFY" and "Display.java" in loc:
856+
return True
854857
return False
855858

856859

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ public void actionPerformed(ActionEvent evt) {
257257
} else {
258258
url = (String) evt.getSource();
259259
}
260-
completed = true;
261260
synchronized (this) {
261+
completed = true;
262262
this.notifyAll();
263263
}
264264
}

CodenameOne/src/com/codename1/components/WebBrowser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ protected void readResponse(InputStream input) throws IOException {
154154
if (callback != null) {
155155
callback.streamReady(input, docInfo);
156156
} else {
157-
response[0] = input;
158157
synchronized (LOCK) {
158+
response[0] = input;
159159
LOCK.notifyAll();
160160
}
161161
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7177,13 +7177,9 @@ protected final void pushReceived(String data) {
71777177
* Sets the frequency for polling the server in case of polling based push notification
71787178
*
71797179
* @param freq the frequency in milliseconds
7180+
* @deprecated we no longer support push polling
71807181
*/
71817182
public void setPollingFrequency(int freq) {
7182-
if (callback != null && pollingThreadRunning) {
7183-
synchronized (callback) {
7184-
callback.notifyAll();
7185-
}
7186-
}
71877183
}
71887184

71897185
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ public void shutdown() {
330330
}
331331
}
332332
}
333-
networkThreads = null;
334333
synchronized (LOCK) {
334+
networkThreads = null;
335335
LOCK.notifyAll();
336336
}
337337

@@ -970,10 +970,10 @@ public void run() {
970970
if (!runCurrentRequest(currentRequest)) {
971971
continue;
972972
}
973-
currentRequest = null;
974973

975974
// wakeup threads waiting for the completion of this network operation
976975
synchronized (LOCK) {
976+
currentRequest = null;
977977
LOCK.notifyAll();
978978
}
979979
} else {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,8 @@ public static void init(Object m) {
506506
* Notice that minimize (being a Codename One method) MUST be invoked before invoking this method!
507507
*/
508508
public static void deinitialize() {
509-
510-
INSTANCE.codenameOneRunning = false;
511509
synchronized (lock) {
510+
INSTANCE.codenameOneRunning = false;
512511
lock.notifyAll();
513512
}
514513
}
@@ -4684,6 +4683,7 @@ public String getDatabasePath(String databaseName) {
46844683
* Sets the frequency for polling the server in case of polling based push notification
46854684
*
46864685
* @param freq the frequency in milliseconds
4686+
* @deprecated we no longer support push polling
46874687
*/
46884688
public void setPollingFrequency(int freq) {
46894689
impl.setPollingFrequency(freq);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public void run() {
106106
switch (type) {
107107
case 0:
108108
internal.run();
109-
done = true;
110109
synchronized (Display.lock) {
110+
done = true;
111111
Display.lock.notifyAll();
112112
}
113113
break;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ protected void readResponse(InputStream input) throws IOException {
155155
if (callback != null) {
156156
callback.streamReady(input, docInfo);
157157
} else {
158-
response[0] = input;
159158
synchronized (LOCK) {
159+
response[0] = input;
160160
LOCK.notifyAll();
161161
}
162162
}

maven/core-unittests/spotbugs-exclude.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@
152152
<Bug pattern="SF_SWITCH_FALLTHROUGH" />
153153
</Match>
154154

155+
<!--
156+
This rule is a bit broad for the complex threading logic in Display.
157+
Ideally, this code should be rewritten, but it's battle tested and deep.
158+
-->
159+
<Match>
160+
<Class name="~com\.codename1\.ui\.Display.*" />
161+
<Bug pattern="NN_NAKED_NOTIFY" />
162+
</Match>
163+
155164
<!-- Excluding since the class explicitly compares interned strings -->
156165
<Match>
157166
<Class name="~com\.codename1\.io\.ConnectionRequest.*" />

0 commit comments

Comments
 (0)