forked from spotbugs/spotbugs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37d57e5
commit ad09f70
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
spotbugsTestCases/src/java/commonResources/UnsafeFieldUsage5.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package commonResources; | ||
|
||
public class UnsafeFieldUsage5 { | ||
|
||
private final Vehicle vehicle = new Vehicle(); | ||
|
||
public UnsafeFieldUsage5() { | ||
Thread t1 = new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
vehicle.setModel("Toyota"); | ||
} | ||
}); | ||
t1.start(); | ||
|
||
Thread t2 = new Thread(this::createVehicle); | ||
t2.start(); | ||
} | ||
|
||
private void createVehicle() { | ||
vehicle.setModel("Honda"); | ||
vehicle.setYear(2020); | ||
vehicle.setColor("Red"); | ||
vehicle.setPrice(20000); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
spotbugsTestCases/src/java/commonResources/UnsafeFieldUsage6.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package commonResources; | ||
|
||
public class UnsafeFieldUsage6 { | ||
|
||
private final Vehicle vehicle = new Vehicle(); | ||
|
||
public UnsafeFieldUsage6() { | ||
|
||
Thread t1 = new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
vehicle.setModel("Toyota"); | ||
} | ||
}); | ||
t1.start(); | ||
|
||
Thread t2 = new Thread( | ||
() -> vehicle.setModel("Honda") | ||
); | ||
t2.start(); | ||
|
||
Thread t3 = new Thread(this::createVehicle); | ||
t3.start(); | ||
} | ||
|
||
private void createVehicle() { | ||
vehicle.setModel("Honda"); | ||
} | ||
} |