Permalink
Browse files

[MSC-121] Fix unprotected access of non-synch fields

  • Loading branch information...
1 parent d8d6817 commit 21a8af388f898a1a4e259c42b82c02e354605d6d @dmlloyd dmlloyd committed Oct 8, 2012
Showing with 23 additions and 1 deletion.
  1. +23 −1 src/main/java/org/jboss/msc/service/OptionalDependency.java
@@ -151,7 +151,7 @@ public void removeDependent(Dependent dependent) {
assert !holdsLock(this);
assert !holdsLock(dependent);
synchronized (this) {
- dependent = null;
+ this.dependent = null;
forwardNotifications = false;
}
optionalDependency.removeDependent(this);
@@ -178,6 +178,7 @@ public void removeDemand() {
final DependencyState depState;
final boolean transDepUnavailable;
final boolean depFailed;
+ final Dependent dependent;
synchronized (this) {
demandedByDependent = false;
depState = dependencyState;
@@ -190,6 +191,7 @@ public void removeDemand() {
notifyOptionalDependency = false;
startNotifying = forwardNotifications = dependencyState.compareTo(DependencyState.AVAILABLE) >= 0;//);
}
+ dependent = this.dependent;
}
if (startNotifying) {
if (depState == DependencyState.AVAILABLE) {
@@ -262,7 +264,9 @@ public void immediateDependencyAvailable(ServiceName dependencyName) {
final boolean notifyOptionalDependent;
final boolean depFailed;
final boolean startNotifying;
+ final Dependent dependent;
synchronized (this) {
+ dependent = this.dependent;
depFailed = dependencyFailed;
startNotifying = !forwardNotifications;
dependencyState = DependencyState.AVAILABLE;
@@ -285,7 +289,9 @@ public void immediateDependencyUnavailable(ServiceName dependencyName) {
final DependencyState depState;
final boolean transitiveDepUnavailable;
final boolean depFailed;
+ final Dependent dependent;
synchronized (this) {
+ dependent = this.dependent;
depState = dependencyState;
transitiveDepUnavailable = transitiveDependencyUnavailable;
depFailed = dependencyFailed;
@@ -315,7 +321,9 @@ public void immediateDependencyUnavailable(ServiceName dependencyName) {
public void immediateDependencyUp() {
assert !holdsLock(this);
final boolean notifyOptionalDependent;
+ final Dependent dependent;
synchronized (this) {
+ dependent = this.dependent;
dependencyState = DependencyState.UP;
notifyOptionalDependent = forwardNotifications;
}
@@ -328,7 +336,9 @@ public void immediateDependencyUp() {
public void immediateDependencyDown() {
assert !holdsLock(this);
final boolean notifyOptionalDependent;
+ final Dependent dependent;
synchronized (this) {
+ dependent = this.dependent;
dependencyState = DependencyState.AVAILABLE;
notifyOptionalDependent = forwardNotifications;
}
@@ -341,7 +351,9 @@ public void immediateDependencyDown() {
public void dependencyFailed() {
assert !holdsLock(this);
final boolean notifyOptionalDependent;
+ final Dependent dependent;
synchronized (this) {
+ dependent = this.dependent;
notifyOptionalDependent = forwardNotifications;
dependencyFailed = true;
}
@@ -354,7 +366,9 @@ public void dependencyFailed() {
public void dependencyFailureCleared() {
assert !holdsLock(this);
final boolean notifyOptionalDependent;
+ final Dependent dependent;
synchronized (this) {
+ dependent = this.dependent;
notifyOptionalDependent = forwardNotifications;
dependencyFailed = false;
}
@@ -367,9 +381,11 @@ public void dependencyFailureCleared() {
public void transitiveDependencyAvailable() {
assert !holdsLock(this);
final boolean notifyOptionalDependent;
+ final Dependent dependent;
synchronized (this) {
notifyOptionalDependent = forwardNotifications;
transitiveDependencyUnavailable = false;
+ dependent = this.dependent;
}
if (notifyOptionalDependent) {
dependent.transitiveDependencyAvailable();
@@ -378,14 +394,20 @@ public void transitiveDependencyAvailable() {
@Override
public ServiceControllerImpl<?> getController() {
+ final Dependent dependent;
+ synchronized (this) {
+ dependent = this.dependent;
+ }
return dependent.getController();
}
@Override
public void transitiveDependencyUnavailable() {
assert !holdsLock(this);
final boolean notifyOptionalDependent;
+ final Dependent dependent;
synchronized (this) {
+ dependent = this.dependent;
notifyOptionalDependent = forwardNotifications;
transitiveDependencyUnavailable = true;
}

0 comments on commit 21a8af3

Please sign in to comment.