Bug1/7 Volatile.java: Line 18
Bug: Spinning on Volatile.flag in com.crossoverjie.concurrent.Volatile.run()
This method spins in a loop which reads a field. The compiler may legally hoist the read out of the loop, turning the code into an infinite loop. The class should be changed so it uses proper synchronization (including wait and notify calls).
Rank: Troubling (14), confidence: Normal
Pattern: SP_SPIN_ON_FIELD
Type: SP, Category: MT_CORRECTNESS (Multithreaded correctness)
Bug2/7 ThreadState.java: Line 59
Bug: com.crossoverjie.concurrent.ThreadState$Blocked.run() calls Thread.sleep() with a lock held
This method calls Thread.sleep() with a lock held. This may result in very poor performance and scalability, or a deadlock, since other threads may be waiting to acquire the lock. It is a much better idea to call wait() on the lock, which releases the lock and allows other threads to run.
Rank: Troubling (14), confidence: Normal
Pattern: SWL_SLEEP_WITH_LOCK_HELD
Type: SWL, Category: MT_CORRECTNESS (Multithreaded correctness)
Bug3/7 ThreadState.java Line42
Bug: Unconditional wait in com.crossoverjie.concurrent.ThreadState$Waiting.run()
This method contains a call to java.lang.Object.wait() which is not guarded by conditional control flow. The code should verify that condition it intends to wait for is not already satisfied before calling wait; any previous notifications will be ignored.
Rank: Troubling (14), confidence: Normal
Pattern: UW_UNCOND_WAIT
Type: UW, Category: MT_CORRECTNESS (Multithreaded correctness)
Bug4/7 MinorGC.java: Line34
Bug: Dead store to four in com.crossoverjie.gc.MinorGC.main(String[])
This instruction assigns a value to a local variable, but the value is not read or used in any subsequent instruction. Often, this indicates an error, because the value computed is never used.
Note that Sun's javac compiler often generates dead stores for final local variables. Because SpotBugs is a bytecode-based tool, there is no easy way to eliminate these false positives.
Rank: Of Concern (15), confidence: High
Pattern: DLS_DEAD_LOCAL_STORE
Type: DLS, Category: STYLE (Dodgy code)
Bug5/7 LlinkedListMergeSortTest.java Line17
Bug: Dead store to objectUnderTest in com.crossoverjie.algorithm.LinkedListMergeSortTest.constructorOutputVoid()
This instruction assigns a value to a local variable, but the value is not read or used in any subsequent instruction. Often, this indicates an error, because the value computed is never used.
Note that Sun's javac compiler often generates dead stores for final local variables. Because SpotBugs is a bytecode-based tool, there is no easy way to eliminate these false positives.
Rank: Of Concern (15), confidence: High
Pattern: DLS_DEAD_LOCAL_STORE
Type: DLS, Category: STYLE (Dodgy code)
Bug6/7 MinorGC.java Line30
Bug: Dead store to one in com.crossoverjie.gc.MinorGC.main(String[])
This instruction assigns a value to a local variable, but the value is not read or used in any subsequent instruction. Often, this indicates an error, because the value computed is never used.
Note that Sun's javac compiler often generates dead stores for final local variables. Because SpotBugs is a bytecode-based tool, there is no easy way to eliminate these false positives.
Rank: Of Concern (15), confidence: High
Pattern: DLS_DEAD_LOCAL_STORE
Type: DLS, Category: STYLE (Dodgy code)
Bug7/7 TwoThreadNonBlocking.java Line43
Bug: Write to static field com.crossoverjie.actual.TwoThreadNonBlocking.flag from instance method com.crossoverjie.actual.TwoThreadNonBlocking.run()
This instance method writes to a static field. This is tricky to get correct if multiple instances are being manipulated, and generally bad practice.
Rank: Of Concern (15), confidence: High
Pattern: ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD
Type: ST, Category: STYLE (Dodgy code)
master-branch:
Bug1/7 Volatile.java: Line 18 Bug: Spinning on Volatile.flag in com.crossoverjie.concurrent.Volatile.run() This method spins in a loop which reads a field. The compiler may legally hoist the read out of the loop, turning the code into an infinite loop. The class should be changed so it uses proper synchronization (including wait and notify calls). Rank: Troubling (14), confidence: Normal Pattern: SP_SPIN_ON_FIELD Type: SP, Category: MT_CORRECTNESS (Multithreaded correctness)
Bug2/7 ThreadState.java: Line 59 Bug: com.crossoverjie.concurrent.ThreadState$Blocked.run() calls Thread.sleep() with a lock held This method calls Thread.sleep() with a lock held. This may result in very poor performance and scalability, or a deadlock, since other threads may be waiting to acquire the lock. It is a much better idea to call wait() on the lock, which releases the lock and allows other threads to run. Rank: Troubling (14), confidence: Normal Pattern: SWL_SLEEP_WITH_LOCK_HELD Type: SWL, Category: MT_CORRECTNESS (Multithreaded correctness)
Bug3/7 ThreadState.java Line42 Bug: Unconditional wait in com.crossoverjie.concurrent.ThreadState$Waiting.run() This method contains a call to java.lang.Object.wait() which is not guarded by conditional control flow. The code should verify that condition it intends to wait for is not already satisfied before calling wait; any previous notifications will be ignored. Rank: Troubling (14), confidence: Normal Pattern: UW_UNCOND_WAIT Type: UW, Category: MT_CORRECTNESS (Multithreaded correctness)
Bug4/7 MinorGC.java: Line34 Bug: Dead store to four in com.crossoverjie.gc.MinorGC.main(String[]) This instruction assigns a value to a local variable, but the value is not read or used in any subsequent instruction. Often, this indicates an error, because the value computed is never used. Note that Sun's javac compiler often generates dead stores for final local variables. Because SpotBugs is a bytecode-based tool, there is no easy way to eliminate these false positives. Rank: Of Concern (15), confidence: High Pattern: DLS_DEAD_LOCAL_STORE Type: DLS, Category: STYLE (Dodgy code)
Bug5/7 LlinkedListMergeSortTest.java Line17 Bug: Dead store to objectUnderTest in com.crossoverjie.algorithm.LinkedListMergeSortTest.constructorOutputVoid() This instruction assigns a value to a local variable, but the value is not read or used in any subsequent instruction. Often, this indicates an error, because the value computed is never used. Note that Sun's javac compiler often generates dead stores for final local variables. Because SpotBugs is a bytecode-based tool, there is no easy way to eliminate these false positives. Rank: Of Concern (15), confidence: High Pattern: DLS_DEAD_LOCAL_STORE Type: DLS, Category: STYLE (Dodgy code)
Bug6/7 MinorGC.java Line30 Bug: Dead store to one in com.crossoverjie.gc.MinorGC.main(String[]) This instruction assigns a value to a local variable, but the value is not read or used in any subsequent instruction. Often, this indicates an error, because the value computed is never used. Note that Sun's javac compiler often generates dead stores for final local variables. Because SpotBugs is a bytecode-based tool, there is no easy way to eliminate these false positives. Rank: Of Concern (15), confidence: High Pattern: DLS_DEAD_LOCAL_STORE Type: DLS, Category: STYLE (Dodgy code)
Bug7/7 TwoThreadNonBlocking.java Line43 Bug: Write to static field com.crossoverjie.actual.TwoThreadNonBlocking.flag from instance method com.crossoverjie.actual.TwoThreadNonBlocking.run() This instance method writes to a static field. This is tricky to get correct if multiple instances are being manipulated, and generally bad practice. Rank: Of Concern (15), confidence: High Pattern: ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD Type: ST, Category: STYLE (Dodgy code)