Skip to content

Commit

Permalink
Fix race condition accessing HashMap.
Browse files Browse the repository at this point in the history
The race condition was causing:
`java.lang.ClassCastException: java.util.HashMap$Node cannot be cast to java.util.HashMap$TreeNode`
  • Loading branch information
runningcode committed Oct 25, 2020
1 parent 434443a commit cee8add
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

## 0.6.3
* Fix ClassCastException caused by race condition. [PR](https://github.com/runningcode/gradle-doctor/pull/129)

## 0.6.2
* [Add threshold for negative avoidance savings.](https://github.com/runningcode/gradle-doctor/pull/126)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import org.gradle.internal.operations.OperationFinishEvent
import org.gradle.internal.operations.OperationIdentifier
import org.gradle.internal.operations.OperationProgressEvent
import org.gradle.internal.operations.OperationStartEvent
import java.util.concurrent.ConcurrentHashMap

class BuildOperations(negativeAvoidanceThreshold: Property<Int>) : OperationEvents, BuildOperationListener {

// TODO move this out of this class
private val snapshotIdsMap = HashMap<OperationIdentifier, SnapshotTaskInputsBuildOperationType.Result>()
// When multiple threads are accessing this HashMap, a ClassCastException may be thrown.
private val snapshotIdsMap = ConcurrentHashMap<OperationIdentifier, SnapshotTaskInputsBuildOperationType.Result>()
private val executeTaskIdsMap = HashMap<OperationIdentifier, ExecuteTaskBuildOperationType.Result>()

private val starts: PublishSubject<OperationStartEvent> = PublishSubject.create()
Expand Down

0 comments on commit cee8add

Please sign in to comment.