Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: WeakReferenceKey.equals NPE #371

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
}
}