Skip to content

Commit

Permalink
Using reflection to unmonitor a reference results in errors in Java 17
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-lawrey authored and JerryShea committed May 20, 2024
1 parent bae6162 commit 9da9aee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static <T> T defaultValueForType(@NotNull Class<T> tClass) {
&& !tClass.isEnum()
&& !tClass.isArray()) {
T t = ObjectUtils.newInstance(tClass);
IOTools.unmonitor(t);
Monitorable.unmonitor(t);
return t;
}
if (DynamicEnum.class.isAssignableFrom(tClass)) {
Expand Down
12 changes: 11 additions & 1 deletion src/test/java/net/openhft/chronicle/wire/TextWireTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.annotation.UsedViaReflection;
import net.openhft.chronicle.core.io.IORuntimeException;
import net.openhft.chronicle.core.io.Monitorable;
import net.openhft.chronicle.core.pool.ClassAliasPool;
import org.easymock.EasyMock;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -2643,19 +2644,28 @@ public void unexpectedField(Object event, ValueIn valueIn) {
}

// Class with fields of Bytes type initialized with various Byte buffers
static class ABCD extends SelfDescribingMarshallable {
static class ABCD extends SelfDescribingMarshallable implements Monitorable {
Bytes<?> A = Bytes.allocateElasticDirect();
Bytes<?> B = Bytes.allocateDirect(64);
Bytes<?> C = Bytes.elasticByteBuffer();
Bytes<?> D = Bytes.allocateElasticOnHeap(1);


// Method to release all byte buffers
void releaseAll() {
A.releaseLast();
B.releaseLast();
C.releaseLast();
D.releaseLast();
}

@Override
public void unmonitor() {
Monitorable.unmonitor(A);
Monitorable.unmonitor(B);
Monitorable.unmonitor(C);
Monitorable.unmonitor(D);
}
}

// Class containing three StringBuilder fields
Expand Down

0 comments on commit 9da9aee

Please sign in to comment.