Skip to content

Commit

Permalink
fix: WeakReferenceKey.equals NPE (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
mr3 authored and DanLi39 committed Jan 11, 2024
1 parent adf2b66 commit a932133
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![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)
[![codecov](https://codecov.io/gh/arextest/arex-agent-java/branch/main/graph/badge.svg)](https://app.codecov.io/gh/arextest/arex-agent-java)
[![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)
[![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)

# <img src="https://avatars.githubusercontent.com/u/103105168?s=200&v=4" alt="Arex Icon" width="27" height=""> AREX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.lang.instrument.Instrumentation;

public class InstrumentationHolder {
private static volatile Instrumentation instrumentation;
private static Instrumentation instrumentation;

private static volatile ClassLoader agentClassLoader;
private static ClassLoader agentClassLoader;

public static Instrumentation getInstrumentation() {
return instrumentation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public int hashCode() {
public boolean equals(Object other) {
if (other instanceof WeakCache.WeakReferenceKey<?>) {
return ((WeakReferenceKey<?>) other).get() == get();
} else {
return other.equals(this);
}

return other != null && other.equals(this);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

import java.lang.ref.ReferenceQueue;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -56,4 +57,11 @@ void testNormalKeyValue() throws InterruptedException {
// check -> remove after gc
assertFalse(Cache.CAPTURED_CACHE.contains(null));
}

@Test
void testWeakReferenceKeyEqualsReturnsFalse() {
WeakCache.WeakReferenceKey<String> key = new WeakCache.WeakReferenceKey<>("test", new ReferenceQueue<>());
assertFalse(key.equals(null));
assertFalse(key.equals("test"));
}
}

0 comments on commit a932133

Please sign in to comment.