From f0e0018a31db8f9f16bbfa34c6c929afb436e6bc Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 17 May 2024 10:18:34 +0100 Subject: [PATCH] Using reflection to unmonitor a reference results in errors in Java 17 Fixes https://github.com/OpenHFT/Chronicle-Core/issues/656 --- .../java/net/openhft/chronicle/bytes/AbstractBytes.java | 6 ++++++ .../net/openhft/chronicle/bytes/UncheckedNativeBytes.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/net/openhft/chronicle/bytes/AbstractBytes.java b/src/main/java/net/openhft/chronicle/bytes/AbstractBytes.java index c1af53b8835..a5be0711039 100644 --- a/src/main/java/net/openhft/chronicle/bytes/AbstractBytes.java +++ b/src/main/java/net/openhft/chronicle/bytes/AbstractBytes.java @@ -1535,6 +1535,12 @@ public int copyTo(byte[] bytes) throws BufferUnderflowException, ClosedIllegalSt return (int) read(readPosition(), bytes, 0, bytes.length); } + @Override + public void unmonitor() { + super.unmonitor(); + Monitorable.unmonitor(bytesStore); + } + static final class ReportUnoptimised { static { Jvm.reportUnoptimised(); diff --git a/src/main/java/net/openhft/chronicle/bytes/UncheckedNativeBytes.java b/src/main/java/net/openhft/chronicle/bytes/UncheckedNativeBytes.java index 0708a243cf4..d0e52a1dcc5 100644 --- a/src/main/java/net/openhft/chronicle/bytes/UncheckedNativeBytes.java +++ b/src/main/java/net/openhft/chronicle/bytes/UncheckedNativeBytes.java @@ -1090,6 +1090,12 @@ public Bytes write8bit(@Nullable BytesStore bs) throws BufferOverflowExceptio return uncheckedRandomDataInput; } + @Override + public void unmonitor() { + super.unmonitor(); + Monitorable.unmonitor(bytesStore); + } + private final class UncheckedRandomDataInputHolder implements UncheckedRandomDataInput { @Override