Skip to content

Commit 28d4fd9

Browse files
authored
fix: WeakReferenceKey.equals NPE (#371)
1 parent a73cac7 commit 28d4fd9

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[![Build Status](https://github.com/arextest/arex-agent-java/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/arextest/arex-agent-java/actions/workflows/build.yml)
2-
[![codecov](https://codecov.io/gh/arextest/arex-agent-java/branch/main/graph/badge.svg)](https://app.codecov.io/gh/arextest/arex-agent-java)
2+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=arextest_arex-agent-java&metric=coverage)](https://sonarcloud.io/summary/overall?id=arextest_arex-agent-java)
33
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=arextest_arex-agent-java&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=arextest_arex-agent-java)
44

55
# <img src="https://avatars.githubusercontent.com/u/103105168?s=200&v=4" alt="Arex Icon" width="27" height=""> AREX

arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/InstrumentationHolder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import java.lang.instrument.Instrumentation;
44

55
public class InstrumentationHolder {
6-
private static volatile Instrumentation instrumentation;
6+
private static Instrumentation instrumentation;
77

8-
private static volatile ClassLoader agentClassLoader;
8+
private static ClassLoader agentClassLoader;
99

1010
public static Instrumentation getInstrumentation() {
1111
return instrumentation;

arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/internal/WeakCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public int hashCode() {
6363
public boolean equals(Object other) {
6464
if (other instanceof WeakCache.WeakReferenceKey<?>) {
6565
return ((WeakReferenceKey<?>) other).get() == get();
66-
} else {
67-
return other.equals(this);
6866
}
67+
68+
return other != null && other.equals(this);
6969
}
7070
}
7171
}

arex-agent-bootstrap/src/test/java/io/arex/agent/bootstrap/internal/WeakCacheTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.junit.jupiter.api.Assertions.*;
44

5+
import java.lang.ref.ReferenceQueue;
56
import java.util.concurrent.ForkJoinTask;
67
import java.util.concurrent.TimeUnit;
78
import org.junit.jupiter.api.AfterEach;
@@ -56,4 +57,11 @@ void testNormalKeyValue() throws InterruptedException {
5657
// check -> remove after gc
5758
assertFalse(Cache.CAPTURED_CACHE.contains(null));
5859
}
60+
61+
@Test
62+
void testWeakReferenceKeyEqualsReturnsFalse() {
63+
WeakCache.WeakReferenceKey<String> key = new WeakCache.WeakReferenceKey<>("test", new ReferenceQueue<>());
64+
assertFalse(key.equals(null));
65+
assertFalse(key.equals("test"));
66+
}
5967
}

0 commit comments

Comments
 (0)