Skip to content

Commit

Permalink
[JNI]: Fix Race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan committed Jan 17, 2025
1 parent 0c1ff27 commit 455e985
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion jni/java/wallet/core/java/GenericPhantomReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import java.lang.ref.ReferenceQueue;
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;

public class GenericPhantomReference extends PhantomReference<Object> {
private final long nativeHandle;
private final OnDeleteCallback onDeleteCallback;

private static final Set<GenericPhantomReference> references = new HashSet<>();
private static final Set<GenericPhantomReference> references = Collections.synchronizedSet(new HashSet<>());
private static final ReferenceQueue<Object> queue = new ReferenceQueue<>();

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.trustwallet.core

import java.lang.ref.PhantomReference
import java.lang.ref.ReferenceQueue
import java.util.Collections

internal class GenericPhantomReference private constructor(
referent: Any,
Expand All @@ -10,7 +11,7 @@ internal class GenericPhantomReference private constructor(
) : PhantomReference<Any>(referent, queue) {

companion object {
private val references: MutableSet<GenericPhantomReference> = HashSet()
private val references: MutableSet<GenericPhantomReference> = Collections.synchronizedSet(HashSet())
private val queue: ReferenceQueue<Any> = ReferenceQueue()

init {
Expand Down
2 changes: 1 addition & 1 deletion tools/install-rust-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ cargo install cbindgen --locked

if [[ "$1" == "dev" ]]; then
rustup component add llvm-tools-preview clippy rustfmt
cargo install cargo-llvm-cov --locked
cargo install --version 0.6.14 cargo-llvm-cov --locked
fi

0 comments on commit 455e985

Please sign in to comment.