This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-exec.git

commit ed6cfbae73dc67d2b80efa4f3e86ecfed4992daf
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Wed Apr 30 09:48:45 2025 -0400

    Fix SpotBugs AT_STALE_THREAD_WRITE_OF_PRIMITIVE
    
    Error:  Medium: Shared primitive variable "shouldDestroy" in one thread may 
not yield the value of the most recent write from another thread 
[org.apache.commons.exec.ShutdownHookProcessDestroyer$ProcessDestroyerThread] 
At ShutdownHookProcessDestroyer.java:[line 43] 
AT_STALE_THREAD_WRITE_OF_PRIMITIVE
---
 src/changes/changes.xml                                            | 1 +
 .../java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java | 7 ++++---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index af327898..a70843a3 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -42,6 +42,7 @@
             <action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate 
MapUtils.MapUtils().</action>
             <action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate 
StringUtils.StringUtils().</action>
             <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix 
Javadoc warnings.</action>
+            <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix 
SpotBugs AT_STALE_THREAD_WRITE_OF_PRIMITIVE: Shared primitive variable 
"shouldDestroy" in one thread may not yield the value of the most recent write 
from another thread 
[org.apache.commons.exec.ShutdownHookProcessDestroyer$ProcessDestroyerThread].</action>
             <!-- UPDATE -->
             <action type="update" dev="ggregory" due-to="Dependabot, Gary 
Gregory">Bump org.apache.commons:commons-parent from 65 to 81 #174, #204, #212, 
#214, #219, #223, #226, #233, #253.</action>
         </release>
diff --git 
a/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java 
b/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java
index 77169c6c..49e337df 100644
--- a/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java
+++ b/src/main/java/org/apache/commons/exec/ShutdownHookProcessDestroyer.java
@@ -18,6 +18,7 @@
 package org.apache.commons.exec;
 
 import java.util.Vector;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * Destroys all registered {@code Process}es when the VM exits.
@@ -26,7 +27,7 @@ public class ShutdownHookProcessDestroyer implements 
ProcessDestroyer, Runnable
 
     private final class ProcessDestroyerThread extends Thread {
 
-        private boolean shouldDestroy = true;
+        private AtomicBoolean shouldDestroy = new AtomicBoolean(true);
 
         public ProcessDestroyerThread() {
             super("ProcessDestroyer Shutdown Hook");
@@ -34,13 +35,13 @@ public class ShutdownHookProcessDestroyer implements 
ProcessDestroyer, Runnable
 
         @Override
         public void run() {
-            if (shouldDestroy) {
+            if (shouldDestroy.get()) {
                 ShutdownHookProcessDestroyer.this.run();
             }
         }
 
         public void setShouldDestroy(final boolean shouldDestroy) {
-            this.shouldDestroy = shouldDestroy;
+            this.shouldDestroy.set(shouldDestroy);
         }
     }
 

Reply via email to