diff --git a/pom.xml b/pom.xml
index a43b6904f7..cf166ffeda 100644
--- a/pom.xml
+++ b/pom.xml
@@ -40,7 +40,7 @@
net.openhftthird-party-bom
- 3.27ea5
+ 3.27ea7pomimport
@@ -85,6 +85,7 @@
org.jetbrainsannotations
+ compile
diff --git a/src/main/java/net/openhft/chronicle/core/Bootstrap.java b/src/main/java/net/openhft/chronicle/core/Bootstrap.java
index 6d05f9bea4..5e003e395d 100644
--- a/src/main/java/net/openhft/chronicle/core/Bootstrap.java
+++ b/src/main/java/net/openhft/chronicle/core/Bootstrap.java
@@ -9,6 +9,7 @@
* Contains the pieces which must be loaded first
*/
public class Bootstrap {
+ @Deprecated(/* make private in 2026 */)
public Bootstrap() {
}
static {
diff --git a/src/main/java/net/openhft/chronicle/core/ChronicleInit.java b/src/main/java/net/openhft/chronicle/core/ChronicleInit.java
index 82126375c2..2729230a59 100644
--- a/src/main/java/net/openhft/chronicle/core/ChronicleInit.java
+++ b/src/main/java/net/openhft/chronicle/core/ChronicleInit.java
@@ -29,10 +29,6 @@ public final class ChronicleInit {
public static final String CHRONICLE_INIT_CLASS = "chronicle.init.runnable";
public static final String CHRONICLE_POSTINIT_CLASS = "chronicle.postinit.runnable";
- private ChronicleInit() {
- // Suppresses default constructor, ensuring non-instantiability.
- }
-
static {
// Jvm#getProperty() does not make sense here - not initialized yet
String initRunnableClass = System.getProperty(CHRONICLE_INIT_CLASS);
@@ -58,6 +54,10 @@ private ChronicleInit() {
}
}
+ private ChronicleInit() {
+ // Suppresses default constructor, ensuring non-instantiability.
+ }
+
private static void runQuietly(Runnable runnable) {
try {
runnable.run();
@@ -66,14 +66,6 @@ private static void runQuietly(Runnable runnable) {
}
}
- /**
- * May be run multiple times, supposed to be idempotent
- */
- @SuppressWarnings("EmptyMethod")
- static void init() {
- // No-op unless class is replaced
- }
-
/**
* Should be only run once by Jvm.class static block
*/
diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java
index b204392b0e..eddd5597ee 100644
--- a/src/main/java/net/openhft/chronicle/core/Jvm.java
+++ b/src/main/java/net/openhft/chronicle/core/Jvm.java
@@ -17,7 +17,7 @@
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import sun.misc.Signal; // NOSONAR
+import sun.misc.Signal;
import sun.misc.Unsafe;
import sun.nio.ch.Interruptible;
@@ -32,6 +32,8 @@
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.spi.AbstractInterruptibleChannel;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.Map.Entry;
@@ -98,8 +100,8 @@ public final class Jvm {
);
private static final MethodHandle onSpinWaitMH;
private static final ChainedSignalHandler signalHandlerGlobal;
- private static boolean RESOURCE_TRACING;
private static final boolean PROC_EXISTS = new File(PROC).exists();
+ private static boolean RESOURCE_TRACING;
@SuppressWarnings("unused")
private static volatile Thread s_blackHole;
@@ -144,7 +146,7 @@ public final class Jvm {
if (DISABLE_DEBUG)
logger.info("-Ddisable.debug.info turned of debug logging");
if (logger.isInfoEnabled() && notJUnitTest)
- logger.info(String.format("Chronicle core loaded from %s", Jvm.class.getProtectionDomain().getCodeSource().getLocation()));
+ logger.info("Chronicle core loaded from {}", Jvm.class.getProtectionDomain().getCodeSource().getLocation());
if (RESOURCE_TRACING && !Jvm.getBoolean("disable.resource.warning"))
logger.warn("Resource tracing is turned on. If you are performance testing or running in PROD you probably don't want this");
REPORT_UNOPTIMISED = Jvm.getBoolean("report.unoptimised");
@@ -152,6 +154,10 @@ public final class Jvm {
ChronicleInit.postInit();
}
+ // Suppresses default constructor, ensuring non-instantiability.
+ private Jvm() {
+ }
+
private static MethodHandle getOnSpinWait() {
MethodType voidType = MethodType.methodType(void.class);
MethodHandles.Lookup lookup = MethodHandles.lookup();
@@ -170,10 +176,6 @@ private static MethodHandle getOnSpinWait() {
return null;
}
- // Suppresses default constructor, ensuring non-instantiability.
- private Jvm() {
- }
-
public static void reportUnoptimised() {
if (!REPORT_UNOPTIMISED)
return;
@@ -207,7 +209,6 @@ else if (new File("../" + SYSTEM_PROPERTIES).exists())
public static void init() {
// force static initialisation
- ChronicleInit.init();
}
private static void loadSystemProperties(final String name, final boolean wasSet) {
@@ -217,7 +218,7 @@ private static void loadSystemProperties(final String name, final boolean wasSet
if (is0 == null) {
File file = new File(name);
if (file.exists())
- is0 = new FileInputStream(file);
+ is0 = Files.newInputStream(file.toPath());
}
try (InputStream is = is0) {
if (is == null) {
@@ -282,6 +283,7 @@ public static boolean isJava9Plus() {
/**
* @return if the major Java version is 12 or higher
*/
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static boolean isJava12Plus() {
return Bootstrap.isJava12Plus();
}
@@ -396,6 +398,7 @@ public static boolean isDebug() {
* @return if the JVM is running in flight recorder mode
*/
@SuppressWarnings("SameReturnValue")
+ @Deprecated(/* to be removed in 2027 */)
public static boolean isFlightRecorder() {
return IS_FLIGHT_RECORDER;
}
@@ -568,6 +571,7 @@ public static V getValue(@NotNull Object target, @NotNull final String field
* @param lock to log
* @return the lock.toString plus a stack trace.
*/
+ @Deprecated(/* to be removed in 2027 */)
public static String lockWithStack(@NotNull final ReentrantLock lock) {
final Thread t = getValue(lock, "sync/exclusiveOwnerThread");
if (t == null) {
@@ -602,6 +606,7 @@ public static long fieldOffset(final Class> clazz, final String fieldName) {
* @return the accumulated amount of memory in bytes used by direct ByteBuffers
* or 0 if the value cannot be determined
*/
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static long usedDirectMemory() {
return ReserveMemoryHolder.reservedMemory.get();
}
@@ -611,6 +616,7 @@ public static long usedDirectMemory() {
*
* @return the accumulated amount of memory used in bytes by UnsafeMemory.allocate()
*/
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static long usedNativeMemory() {
return UnsafeMemory.INSTANCE.nativeMemoryUsed();
}
@@ -749,6 +755,7 @@ public static void setThreadLocalExceptionHandlers(@Nullable final ExceptionHand
((ThreadLocalisedExceptionHandler) DEBUG).threadLocalHandler(debug);
}
+ @Deprecated(/* to be removed in 2027 */)
public static void setThreadLocalExceptionHandlers(@Nullable final ExceptionHandler error,
@Nullable final ExceptionHandler warn,
@Nullable final ExceptionHandler debug,
@@ -860,6 +867,7 @@ public static void safepoint() {
}
}
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static boolean areOptionalSafepointsEnabled() {
return SAFEPOINT_ENABLED;
}
@@ -873,6 +881,7 @@ public static boolean areOptionalSafepointsEnabled() {
* @return if there is a class name that ends with the provided {@code endsWith} string
* when examining the current stack trace of depth at most up to the provided {@code maxDepth}
*/
+ @Deprecated(/* to be removed in 2027 */)
public static boolean stackTraceEndsWith(final String endsWith, final int maxDepth) {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for (int i = maxDepth + 2; i < stackTrace.length; i++)
@@ -908,6 +917,7 @@ public static boolean isMacArm() {
* @see ClassMetrics
*/
@NotNull
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static ClassMetrics classMetrics(final Class> clazz) throws IllegalArgumentException {
return CLASS_METRICS_MAP.computeIfAbsent(clazz, Jvm::getClassMetrics);
}
@@ -958,6 +968,7 @@ private static void validateClassMetrics(final Class> c,
* if the user's home director cannot be determined
*/
@NotNull
+ @Deprecated(/* to be removed in 2027 */)
public static String userHome() {
return System.getProperty("user.home", ".");
}
@@ -1220,6 +1231,7 @@ public void interrupt(Thread target) {
ci.interrupt();
}
+ @SuppressWarnings({"EmptyMethod", "unused"})
public void postInterrupt() {
// added in Java 23+
}
@@ -1335,21 +1347,25 @@ public static boolean isProcessAlive(long pid) {
@SuppressWarnings("deprecation")
private static boolean isProcessAlive0(final long pid, final String command) {
+ Process process = null;
try {
- InputStreamReader isReader = new InputStreamReader(
- getRuntime().exec(command).getInputStream());
-
- final BufferedReader bReader = new BufferedReader(isReader);
- String strLine;
- while ((strLine = bReader.readLine()) != null) {
- if (strLine.contains(" " + pid + " ") || strLine.startsWith(pid + " ")) {
- return true;
+ process = getRuntime().exec(command);
+ try (BufferedReader bReader = new BufferedReader(
+ new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
+ String strLine;
+ while ((strLine = bReader.readLine()) != null) {
+ if (strLine.contains(" " + pid + " ") || strLine.startsWith(pid + " ")) {
+ return true;
+ }
}
}
-
return false;
} catch (Exception ex) {
return true;
+ } finally {
+ if (process != null) {
+ process.destroy();
+ }
}
}
@@ -1523,6 +1539,17 @@ public static String getPackageName(Class> clazz) {
return PackageNameUtil.getPackageName(clazz);
}
+ private static boolean isJUnitTest0() {
+ for (StackTraceElement[] stackTrace : Thread.getAllStackTraces().values()) {
+ for (StackTraceElement element : stackTrace) {
+ if (element.getClassName().contains(".junit")) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
public interface SignalHandler {
/**
* Handle a Signal
@@ -1569,7 +1596,7 @@ private Safepoint() {
public static void force() {
// trick only works from Java 9+
//noinspection StatementWithEmptyBody
- for (int i = 0; i < one; i++) ;
+ for (int i = 0; i < one; i++);
}
}
@@ -1632,21 +1659,9 @@ public void handle(final Signal signal) {
}
}
- private static boolean isJUnitTest0() {
- for (StackTraceElement[] stackTrace : Thread.getAllStackTraces().values()) {
- for (StackTraceElement element : stackTrace) {
- if (element.getClassName().contains(".junit")) {
- return true;
- }
- }
- }
- return false;
- }
-
static class ReserveMemoryHolder {
- private ReserveMemoryHolder() {
- }
static final Supplier reservedMemory;
+
static {
Supplier reservedMemoryGetter;
try {
@@ -1666,6 +1681,9 @@ private ReserveMemoryHolder() {
}
reservedMemory = reservedMemoryGetter;
}
+
+ private ReserveMemoryHolder() {
+ }
}
static class MaxMemoryHolder {
diff --git a/src/main/java/net/openhft/chronicle/core/LicenceCheck.java b/src/main/java/net/openhft/chronicle/core/LicenceCheck.java
index f5c3cd9bc6..6c3276f94d 100644
--- a/src/main/java/net/openhft/chronicle/core/LicenceCheck.java
+++ b/src/main/java/net/openhft/chronicle/core/LicenceCheck.java
@@ -11,6 +11,7 @@
import java.time.temporal.ChronoUnit;
import java.util.function.BiConsumer;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static net.openhft.chronicle.core.Jvm.startup;
import static net.openhft.chronicle.core.Jvm.warn;
@@ -72,7 +73,7 @@ static void licenceExpiry(String product, Class> caller, BiConsumer 0; ) {
- sw.write(chars, 0, len);
+ try {
+ @NotNull StringWriter sw = new StringWriter();
+ char @NotNull [] chars = new char[1024];
+ try (@NotNull Reader r = new InputStreamReader(process.getInputStream(), UTF_8)) {
+ for (int len; (len = r.read(chars)) > 0; ) {
+ sw.write(chars, 0, len);
+ }
}
+ return sw.toString();
+ } finally {
+ process.destroy();
}
- return sw.toString();
}
/**
@@ -641,6 +660,7 @@ private static String run(String... cmds) throws IOException {
*
* @return the user's current working directory
*/
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static String userDir() {
return USER_DIR;
}
@@ -757,11 +777,12 @@ private static String getHostName0() {
@SuppressWarnings({"deprecation", "RedundantSuppression"})
static String execHostname() throws IOException {
+ Process process = Runtime.getRuntime().exec("hostname"); // NOSONAR
try (BufferedReader br = new BufferedReader(
- new InputStreamReader(
- Runtime.getRuntime().exec("hostname") // NOSONAR
- .getInputStream()))) {
+ new InputStreamReader(process.getInputStream(), UTF_8))) {
return br.readLine();
+ } finally {
+ process.destroy();
}
}
diff --git a/src/main/java/net/openhft/chronicle/core/StackTrace.java b/src/main/java/net/openhft/chronicle/core/StackTrace.java
index 364bed87f5..301877f314 100644
--- a/src/main/java/net/openhft/chronicle/core/StackTrace.java
+++ b/src/main/java/net/openhft/chronicle/core/StackTrace.java
@@ -171,7 +171,7 @@ public Less(String message) {
}
/**
- * @param message the detail message for this stack trace.
+ * @param message the detail message for this stack trace.
* @param stackTrace the stack trace elements for this stack trace.
*/
@SuppressWarnings("this-escape")
diff --git a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java
index c55a2dffed..9d3481b29d 100644
--- a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java
+++ b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java
@@ -60,6 +60,7 @@ public class UnsafeMemory implements Memory {
// during a large copy
static final long UNSAFE_COPY_THRESHOLD = 1024L * 1024L;
// NOSONAR
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static final boolean IS_LITTLE_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN;
// Create a local copy of type long (instead of int) to optimize performance
@@ -148,6 +149,7 @@ private static long retryReadVolatileLong(long address, long value) {
* @param offset the offset at which to insert the value.
* @param value the integer value to insert.
*/
+ @Deprecated(/* to be removed in 2027 */)
public static void putInt(byte[] bytes, int offset, int value) {
assert SKIP_ASSERTIONS || bytes != null;
assert SKIP_ASSERTIONS || offset + Integer.BYTES <= bytes.length;
@@ -159,6 +161,7 @@ public static void putInt(byte[] bytes, int offset, int value) {
*
* Can be used to prevent reordering of instructions by the compiler or processor.
*/
+ @Deprecated(/* to be removed in 2027 */)
public static void unsafeStoreFence() {
UNSAFE.storeFence();
}
@@ -211,6 +214,7 @@ public static byte unsafeGetByte(long address) {
* @param address memory address where the value is to be put.
* @param value the long value to put.
*/
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static void unsafePutLong(long address, long value) {
assert SKIP_ASSERTIONS || address != 0;
UNSAFE.putLong(address, value);
@@ -258,6 +262,7 @@ public static void unsafePutLong(byte[] bytes, int offset, long value) {
* @param offset in the provided bytes where the value is written
* @param value to put
*/
+ @Deprecated(/* to be removed in 2027 */)
public static void unsafePutInt(byte[] bytes, int offset, int value) {
assert SKIP_ASSERTIONS || bytes != null;
assert SKIP_ASSERTIONS || offset + Integer.BYTES <= bytes.length;
@@ -271,6 +276,7 @@ public static void unsafePutInt(byte[] bytes, int offset, int value) {
* @param offset in the provided bytes where the value is written
* @param value to put
*/
+ @Deprecated(/* to be removed in 2027 */)
public static void unsafePutByte(byte[] bytes, int offset, byte value) {
assert SKIP_ASSERTIONS || bytes != null;
assert SKIP_ASSERTIONS || offset + Byte.BYTES <= bytes.length;
diff --git a/src/main/java/net/openhft/chronicle/core/annotation/ForceInline.java b/src/main/java/net/openhft/chronicle/core/annotation/ForceInline.java
index c64307463c..190f96f720 100644
--- a/src/main/java/net/openhft/chronicle/core/annotation/ForceInline.java
+++ b/src/main/java/net/openhft/chronicle/core/annotation/ForceInline.java
@@ -28,5 +28,6 @@
*/
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
@Retention(RetentionPolicy.RUNTIME)
+@Deprecated(/* to be removed in 2027 */)
public @interface ForceInline {
}
diff --git a/src/main/java/net/openhft/chronicle/core/annotation/HotMethod.java b/src/main/java/net/openhft/chronicle/core/annotation/HotMethod.java
index 675446327d..bf3ddb3635 100644
--- a/src/main/java/net/openhft/chronicle/core/annotation/HotMethod.java
+++ b/src/main/java/net/openhft/chronicle/core/annotation/HotMethod.java
@@ -25,11 +25,10 @@
*
*
This annotation has no runtime impact but aids Chronicle benchmarking
* tools.
- *
- * @see ForceInline
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
+@Deprecated(/* to be removed in 2027 */)
public @interface HotMethod {
@NotNull String value() default "";
}
diff --git a/src/main/java/net/openhft/chronicle/core/cooler/CoolerTester.java b/src/main/java/net/openhft/chronicle/core/cooler/CoolerTester.java
index 7cb4f9ec77..f5c396b872 100644
--- a/src/main/java/net/openhft/chronicle/core/cooler/CoolerTester.java
+++ b/src/main/java/net/openhft/chronicle/core/cooler/CoolerTester.java
@@ -20,6 +20,7 @@
*/
public class CoolerTester {
+ private static final Object BLACK_HOLE_SENTINEL = new Object();
/**
* Holds the results of the tests to avoid being optimised away and making the test meaningless.
*/
@@ -55,6 +56,7 @@ public class CoolerTester {
* @param tested the task to be executed during the tests
* @param disturbers the array of CpuCoolers to be tested
*/
+ // TODO Move to Chronicle-Test-Framework in 2026
public CoolerTester(Callable> tested, CpuCooler... disturbers) {
Collections.addAll(this.disturbers, disturbers);
this.testNames.add("");
@@ -102,6 +104,9 @@ private static void innerLoop2(Callable> tested, Histogram histogram) throws E
UNSAFE.fullFence();
long start0 = System.nanoTime();
blackhole = tested.call();
+ if (blackhole == BLACK_HOLE_SENTINEL) {
+ throw new AssertionError("Blackhole sentinel reached");
+ }
// UNSAFE.fullFence();
long time0 = System.nanoTime() - start0;
histogram.sample(time0);
diff --git a/src/main/java/net/openhft/chronicle/core/cooler/CpuCoolers.java b/src/main/java/net/openhft/chronicle/core/cooler/CpuCoolers.java
index 708d937c92..8cbabf5802 100644
--- a/src/main/java/net/openhft/chronicle/core/cooler/CpuCoolers.java
+++ b/src/main/java/net/openhft/chronicle/core/cooler/CpuCoolers.java
@@ -17,6 +17,7 @@
* different way. The exact way in which the CPU is disturbed is defined by the `disturb()` method
* of each enum constant.
*/
+// TODO Move to Chronicle-Test-Framework in 2026
public enum CpuCoolers implements CpuCooler {
/**
* Causes the CPU to wait without doing work for a very short period of time.
@@ -137,6 +138,9 @@ public void disturb() {
}
},
SERIALIZATION {
+ @SuppressWarnings("unused")
+ private volatile Object lastRead;
+
@Override
public void disturb() {
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -144,7 +148,7 @@ public void disturb() {
oos.writeObject(System.getProperties());
oos.close();
XMLDecoder ois = new XMLDecoder(new ByteArrayInputStream(out.toByteArray()));
- blackhole = ois.readObject();
+ lastRead = ois.readObject();
}
},
MEMORY_COPY {
@@ -167,7 +171,6 @@ public void disturb() {
PAUSE10.disturb();
}
};
- static volatile Object blackhole;
public static void busyWait(double nanos) {
long start = System.nanoTime();
diff --git a/src/main/java/net/openhft/chronicle/core/internal/ClassUtil.java b/src/main/java/net/openhft/chronicle/core/internal/ClassUtil.java
index b95f79af60..b076dee952 100644
--- a/src/main/java/net/openhft/chronicle/core/internal/ClassUtil.java
+++ b/src/main/java/net/openhft/chronicle/core/internal/ClassUtil.java
@@ -14,27 +14,6 @@
import java.lang.reflect.*;
public final class ClassUtil {
- static class SetAccessibleHolder {
- static final MethodHandle setAccessible0_Method = getSetAccessible0Method();
-
- private static MethodHandle getSetAccessible0Method() {
- if (!Bootstrap.isJava9Plus()) {
- return null;
- }
- final MethodType signature = MethodType.methodType(boolean.class, boolean.class);
- try {
- // Access privateLookupIn() reflectively to support compilation with JDK 8
- Method privateLookupIn = MethodHandles.class.getDeclaredMethod("privateLookupIn", Class.class, MethodHandles.Lookup.class);
- MethodHandles.Lookup lookup = (MethodHandles.Lookup) privateLookupIn.invoke(null, AccessibleObject.class, MethodHandles.lookup());
- return lookup.findVirtual(AccessibleObject.class, "setAccessible0", signature);
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException |
- IllegalArgumentException e) {
- Logger logger = LoggerFactory.getLogger(ClassUtil.class);
- logger.error("Chronicle products may require command line arguments to be provided for Java 11 and above. See https://chronicle.software/chronicle-support-java-17");
- return null;
- }
- }
- }
private ClassUtil() {
}
@@ -78,7 +57,7 @@ public static Field getField0(@NotNull final Class> clazz,
*/
@SuppressWarnings("java:S3011") // Justification: centralised, audited accessibility control for Chronicle internals.
public static void setAccessible(@NotNull final AccessibleObject accessibleObject) {
- if (Bootstrap.isJava9Plus())
+ if (Bootstrap.isJava9Plus()) {
try {
if (SetAccessibleHolder.setAccessible0_Method == null)
return;
@@ -87,8 +66,9 @@ public static void setAccessible(@NotNull final AccessibleObject accessibleObjec
} catch (Throwable throwable) {
throw new AssertionError(throwable);
}
- else
+ } else {
accessibleObject.setAccessible(true);
+ }
}
public static Method getMethod0(@NotNull final Class> clazz,
@@ -117,4 +97,26 @@ public static Method getMethod0(@NotNull final Class> clazz,
return null;
}
}
+
+ static class SetAccessibleHolder {
+ static final MethodHandle setAccessible0_Method = getSetAccessible0Method();
+
+ private static MethodHandle getSetAccessible0Method() {
+ if (!Bootstrap.isJava9Plus()) {
+ return null;
+ }
+ final MethodType signature = MethodType.methodType(boolean.class, boolean.class);
+ try {
+ // Access privateLookupIn() reflectively to support compilation with JDK 8
+ Method privateLookupIn = MethodHandles.class.getDeclaredMethod("privateLookupIn", Class.class, MethodHandles.Lookup.class);
+ MethodHandles.Lookup lookup = (MethodHandles.Lookup) privateLookupIn.invoke(null, AccessibleObject.class, MethodHandles.lookup());
+ return lookup.findVirtual(AccessibleObject.class, "setAccessible0", signature);
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException |
+ IllegalArgumentException e) {
+ Logger logger = LoggerFactory.getLogger(ClassUtil.class);
+ logger.error("Chronicle products may require command line arguments to be provided for Java 11 and above. See https://chronicle.software/chronicle-support-java-17");
+ return null;
+ }
+ }
+ }
}
diff --git a/src/main/java/net/openhft/chronicle/core/internal/CloseableUtils.java b/src/main/java/net/openhft/chronicle/core/internal/CloseableUtils.java
index 403d866895..eae67286a7 100644
--- a/src/main/java/net/openhft/chronicle/core/internal/CloseableUtils.java
+++ b/src/main/java/net/openhft/chronicle/core/internal/CloseableUtils.java
@@ -89,14 +89,19 @@ public static void gcAndWaitForCloseablesToClose() {
final BlockingQueue q = new LinkedBlockingQueue<>();
// Anonymous inner class overriding the finalize() method to track finalization.
- new Object() {
- @SuppressWarnings({"deprecation", "removal", "java:S1113"})
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- q.add("finalized");
+ {
+ Object finalizerProbe = new Object() {
+ @SuppressWarnings({"deprecation", "removal", "java:S1113"})
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ q.add("finalized");
+ }
+ };
+ if (finalizerProbe == null) {
+ throw new AssertionError("Finalizer probe unexpectedly null");
}
- };
+ }
try {
// Zing JVM is not always satisfied with a single GC call:
diff --git a/src/main/java/net/openhft/chronicle/core/internal/CpuClass.java b/src/main/java/net/openhft/chronicle/core/internal/CpuClass.java
index 2d1487f87a..e61932f9b6 100644
--- a/src/main/java/net/openhft/chronicle/core/internal/CpuClass.java
+++ b/src/main/java/net/openhft/chronicle/core/internal/CpuClass.java
@@ -10,6 +10,7 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -38,7 +39,7 @@ public final class CpuClass {
try {
final Path path = Paths.get("/proc/cpuinfo");
if (Files.isReadable(path)) {
- model = Files.lines(path)
+ model = Files.lines(path, StandardCharsets.UTF_8)
.filter(line -> line.startsWith("model name"))
.map(removingTag())
.findFirst().orElse(model);
@@ -47,7 +48,8 @@ public final class CpuClass {
Process process = new ProcessBuilder(cmd.split(" "))
.redirectErrorStream(true)
.start();
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
+ try (BufferedReader reader = new BufferedReader(
+ new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
model = reader.lines()
.map(String::trim)
.filter(s -> !"Name".equals(s) && !s.isEmpty())
@@ -56,9 +58,9 @@ public final class CpuClass {
try {
int ret = process.waitFor();
if (ret != 0)
- logger.warn(PROCESS + cmd + " returned " + ret);
+ logger.warn(PROCESS + "{} returned {}", cmd, ret);
} catch (InterruptedException e) {
- logger.warn(PROCESS + cmd + " waitFor threw ", e);
+ logger.warn(PROCESS + "{} waitFor threw ", cmd, e);
// Restore the interrupt state...
Thread.currentThread().interrupt();
}
@@ -70,7 +72,8 @@ public final class CpuClass {
Process process = new ProcessBuilder(cmd.split(" "))
.redirectErrorStream(true)
.start();
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
+ try (BufferedReader reader = new BufferedReader(
+ new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
model = reader.lines()
.map(String::trim)
.filter(s -> s.startsWith("machdep.cpu.brand_string"))
@@ -80,9 +83,9 @@ public final class CpuClass {
try {
int ret = process.waitFor();
if (ret != 0)
- logger.warn(PROCESS + cmd + " returned " + ret);
+ logger.warn(PROCESS + "{} returned {}", cmd, ret);
} catch (InterruptedException e) {
- logger.warn(PROCESS + cmd + " waitFor threw ", e);
+ logger.warn(PROCESS + "{} waitFor threw ", cmd, e);
// Restore the interrupt state...
Thread.currentThread().interrupt();
}
diff --git a/src/main/java/net/openhft/chronicle/core/internal/analytics/ReflectionUtil.java b/src/main/java/net/openhft/chronicle/core/internal/analytics/ReflectionUtil.java
index 7de4f69a82..e221c09b8a 100644
--- a/src/main/java/net/openhft/chronicle/core/internal/analytics/ReflectionUtil.java
+++ b/src/main/java/net/openhft/chronicle/core/internal/analytics/ReflectionUtil.java
@@ -95,6 +95,7 @@ public static Object invokeOrThrow(@NotNull final Method method,
* Create a proxy implementing {@code interf} that forwards calls to {@code delegate}.
*/
@NotNull
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static T reflectiveProxy(@NotNull final Class interf, @NotNull final Object delegate) throws IllegalArgumentException {
requireNonNull(interf);
requireNonNull(delegate);
@@ -110,6 +111,7 @@ public static T reflectiveProxy(@NotNull final Class interf, @NotNull fin
* Create a forwarding proxy with the option to return the proxy itself for fluent APIs.
*/
@NotNull
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static T reflectiveProxy(@NotNull final Class interf,
@NotNull final Object delegate,
final boolean returnProxy) throws IllegalArgumentException {
diff --git a/src/main/java/net/openhft/chronicle/core/internal/util/DirectBufferUtil.java b/src/main/java/net/openhft/chronicle/core/internal/util/DirectBufferUtil.java
index 0ac3c51e2d..672f24a24d 100644
--- a/src/main/java/net/openhft/chronicle/core/internal/util/DirectBufferUtil.java
+++ b/src/main/java/net/openhft/chronicle/core/internal/util/DirectBufferUtil.java
@@ -36,6 +36,7 @@ public static Class> directBufferClass() {
* @param buffer to clean
* @throws NullPointerException if the provided {@code buffer } is {@code null}
*/
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static void cleanIfInstanceOfDirectBuffer(final ByteBuffer buffer) {
requireNonNull(buffer);
if (buffer instanceof DirectBuffer) {
@@ -52,8 +53,11 @@ public static void cleanIfInstanceOfDirectBuffer(final ByteBuffer buffer) {
* @throws ClassCastException if the provided {@code buffer } is not an instance of sun.nio.ch.DirectBuffer
*/
public static long addressOrThrow(final ByteBuffer buffer) {
+ requireNonNull(buffer);
+ if (!(buffer instanceof DirectBuffer)) {
+ throw new ClassCastException("Buffer is not a DirectBuffer: " + buffer.getClass().getName());
+ }
try {
- requireNonNull(buffer);
return ((DirectBuffer) buffer).address();
} catch (IllegalAccessError e) {
throw new ClassCastException(e.toString());
diff --git a/src/main/java/net/openhft/chronicle/core/internal/util/RangeUtil.java b/src/main/java/net/openhft/chronicle/core/internal/util/RangeUtil.java
index 0a90bc2a42..c618e7e7df 100644
--- a/src/main/java/net/openhft/chronicle/core/internal/util/RangeUtil.java
+++ b/src/main/java/net/openhft/chronicle/core/internal/util/RangeUtil.java
@@ -8,12 +8,13 @@
*
* Shared by assertion and invariant helpers to keep error wording consistent.
*/
+@Deprecated(/* to be removed in 2027 */)
public final class RangeUtil {
private RangeUtil() {}
public static final String IS_POSITIVE = " is positive.";
- public static final String IS_NEGATIVE = " is negative.";
+ public static final String IS_NEGATIVE = " is negative.";
public static final String IS_ZERO = " is zero.";
public static final String IS_EQUAL_TO = " is equal to.";
public static final String IS_NOT_POSITIVE = " is not positive.";
diff --git a/src/main/java/net/openhft/chronicle/core/io/AbstractCloseable.java b/src/main/java/net/openhft/chronicle/core/io/AbstractCloseable.java
index bf32ab4394..64377a868e 100644
--- a/src/main/java/net/openhft/chronicle/core/io/AbstractCloseable.java
+++ b/src/main/java/net/openhft/chronicle/core/io/AbstractCloseable.java
@@ -99,6 +99,7 @@ public static void disableCloseableTracing() {
*
* @throws AssertionError If the finalizer does not complete within the specified timeout.
*/
+ @Deprecated(/* to be removed in 2027 */)
public static void gcAndWaitForCloseablesToClose() {
CloseableUtils.gcAndWaitForCloseablesToClose();
}
@@ -421,7 +422,7 @@ public void unmonitor() {
* The Finalizer inner class is used to ensure that resources are properly closed
* when the garbage collector decides to reclaim the memory for the enclosing AbstractCloseable instance.
*/
- @SuppressWarnings("RedundantSuppression")
+ @SuppressWarnings({"RedundantSuppression", "unused"})
class Finalizer {
/**
* Called by the garbage collector when the enclosing AbstractCloseable instance is
diff --git a/src/main/java/net/openhft/chronicle/core/io/AbstractCloseableReferenceCounted.java b/src/main/java/net/openhft/chronicle/core/io/AbstractCloseableReferenceCounted.java
index b43679b07f..4fc7a7cc16 100644
--- a/src/main/java/net/openhft/chronicle/core/io/AbstractCloseableReferenceCounted.java
+++ b/src/main/java/net/openhft/chronicle/core/io/AbstractCloseableReferenceCounted.java
@@ -174,6 +174,7 @@ private void throwClosing() throws ClosedIllegalStateException {
*
* @throws ClosedIllegalStateException If the resource has been released or closed.
*/
+ @Deprecated(/* to be removed in 2027 */)
protected void throwExceptionIfClosedInSetter() throws ClosedIllegalStateException, ThreadingIllegalStateException {
throwExceptionIfClosed0();
throwExceptionIfReleased();
diff --git a/src/main/java/net/openhft/chronicle/core/io/AbstractReferenceCounted.java b/src/main/java/net/openhft/chronicle/core/io/AbstractReferenceCounted.java
index 2734d5543f..0fc0f4a3b9 100644
--- a/src/main/java/net/openhft/chronicle/core/io/AbstractReferenceCounted.java
+++ b/src/main/java/net/openhft/chronicle/core/io/AbstractReferenceCounted.java
@@ -8,8 +8,6 @@
import net.openhft.chronicle.core.internal.ReferenceCountedUtils;
import org.jetbrains.annotations.NotNull;
-import java.util.Set;
-
import static net.openhft.chronicle.core.io.BackgroundResourceReleaser.BG_RELEASER;
/**
@@ -27,11 +25,11 @@
*/
public abstract class AbstractReferenceCounted implements ReferenceCountedTracer, ReferenceOwner, SingleThreadedChecked, Monitorable {
// Constants
+ @Deprecated(/* to be removed in 2026 */)
protected static final long WARN_NS = (long) (Jvm.getDouble("reference.warn.secs", 0.003) * 1e9);
protected static final int WARN_COUNT = Jvm.getInteger("reference.warn.count", Integer.MAX_VALUE);
// Fields
- static volatile Set referenceCountedSet;
protected final transient MonitorReferenceCounted referenceCounted;
private final int referenceId;
private transient volatile Thread usedByThread;
diff --git a/src/main/java/net/openhft/chronicle/core/io/ClosedState.java b/src/main/java/net/openhft/chronicle/core/io/ClosedState.java
index 72306385c9..0800e1eb8e 100644
--- a/src/main/java/net/openhft/chronicle/core/io/ClosedState.java
+++ b/src/main/java/net/openhft/chronicle/core/io/ClosedState.java
@@ -7,6 +7,7 @@
* typically implemented with a lambda or method reference.
*/
@FunctionalInterface
+@Deprecated(/* to be removed in 2027 */)
public interface ClosedState {
/**
diff --git a/src/main/java/net/openhft/chronicle/core/io/IOTools.java b/src/main/java/net/openhft/chronicle/core/io/IOTools.java
index caa81aa939..94a4c66f46 100644
--- a/src/main/java/net/openhft/chronicle/core/io/IOTools.java
+++ b/src/main/java/net/openhft/chronicle/core/io/IOTools.java
@@ -245,7 +245,7 @@ public static void deleteDirWithFilesOrWait(long timeoutMs, @NotNull File dir) {
* @throws IOException If an I/O error occurs
*/
public static void writeFile(@NotNull String filename, byte @NotNull [] bytes) throws IOException {
- try (@NotNull OutputStream out0 = new FileOutputStream(filename)) {
+ try (@NotNull OutputStream out0 = Files.newOutputStream(Paths.get(filename))) {
OutputStream out = out0;
if (filename.endsWith(".gz"))
out = new GZIPOutputStream(out);
@@ -381,6 +381,7 @@ public static String tempName(@NotNull String filename) {
* @param dir The path of the directory to create
* @throws IOException If an I/O error occurs
*/
+ @Deprecated(/* to be removed in 2027 */)
public static void createDirectories(Path dir) throws IOException {
if (dir == null || dir.getNameCount() == 0 || Files.isDirectory(dir))
return;
@@ -460,6 +461,7 @@ public static void unmonitor(final Object t) {
*
* @param bb The ByteBuffer to clean
*/
+ // TODO ensure used in Bytes
public static void clean(ByteBuffer bb) {
CleanerServiceLocator.cleanerService().clean(bb);
}
diff --git a/src/main/java/net/openhft/chronicle/core/io/LimitedInputStream.java b/src/main/java/net/openhft/chronicle/core/io/LimitedInputStream.java
index 0ce82068de..4b0d4feef7 100644
--- a/src/main/java/net/openhft/chronicle/core/io/LimitedInputStream.java
+++ b/src/main/java/net/openhft/chronicle/core/io/LimitedInputStream.java
@@ -23,6 +23,7 @@
*
The class is package-private on purpose; use it through public APIs such as
* {@link Wget} instead of referencing it directly.
*/
+@Deprecated(/* to be removed in 2026, only used in tests */)
final class LimitedInputStream extends FilterInputStream {
/** Remaining budget in bytes. */
diff --git a/src/main/java/net/openhft/chronicle/core/io/TracingReferenceCounted.java b/src/main/java/net/openhft/chronicle/core/io/TracingReferenceCounted.java
index 007381be28..8201e8776b 100644
--- a/src/main/java/net/openhft/chronicle/core/io/TracingReferenceCounted.java
+++ b/src/main/java/net/openhft/chronicle/core/io/TracingReferenceCounted.java
@@ -161,7 +161,7 @@ public void releaseLast(ReferenceOwner id) throws IllegalStateException {
} catch (Exception e) {
e0 = e;
}
- if (references.size() > 0) {
+ if (!references.isEmpty()) {
IllegalStateException ise = new IllegalStateException(type.getName() + " still reserved " + referencesAsString(), createdHere);
synchronized (references) {
references.values().forEach(ise::addSuppressed);
diff --git a/src/main/java/net/openhft/chronicle/core/io/Wget.java b/src/main/java/net/openhft/chronicle/core/io/Wget.java
index 93ce5712b0..eeff328137 100644
--- a/src/main/java/net/openhft/chronicle/core/io/Wget.java
+++ b/src/main/java/net/openhft/chronicle/core/io/Wget.java
@@ -22,65 +22,23 @@
*/
public final class Wget {
- /** Opens a (potentially mocked) connection for the given URL. */
- @FunctionalInterface
- public interface ConnectionProvider { InputStream open(URL url) throws IOException; }
-
- /** Decides which charset to use when decoding the response body. */
- @FunctionalInterface
- public interface CharsetDetector { Charset detect(InputStream response, String contentTypeHeader); }
-
- public static final class Builder {
- private static final ConnectionProvider DEFAULT_PROVIDER = URL::openStream;
-
- private ConnectionProvider connectionProvider = DEFAULT_PROVIDER;
- private CharsetDetector charsetDetector = (in, ct) -> StandardCharsets.UTF_8;
- private int connectTimeoutMs = 10_000;
- private int readTimeoutMs = 10_000;
- private long maxResponseBytes = 10L << 20; // 10 MiB
-
- public Builder connectionProvider(final ConnectionProvider p) { this.connectionProvider = Objects.requireNonNull(p); return this; }
- public Builder charsetDetector (final CharsetDetector d) { this.charsetDetector = Objects.requireNonNull(d); return this; }
- public Builder connectTimeoutMs (final int v) { this.connectTimeoutMs = v; return this; }
- public Builder readTimeoutMs (final int v) { this.readTimeoutMs = v; return this; }
- public Builder maxResponseBytes (final long v) { if (v < 0) throw new IllegalArgumentException("maxResponseBytes must be >= 0"); this.maxResponseBytes = v; return this; }
-
- /** Creates a {@link Wget} with defaults or caller-supplied overrides. */
- public Wget build() {
- ConnectionProvider cp = this.connectionProvider;
- if (cp == DEFAULT_PROVIDER) { // wrap default provider to apply time-outs
- final int ct = connectTimeoutMs;
- final int rt = readTimeoutMs;
- cp = url -> {
- URLConnection conn = url.openConnection();
- conn.setConnectTimeout(ct);
- conn.setReadTimeout(rt);
- if (conn instanceof HttpURLConnection)
- ((HttpURLConnection) conn).setInstanceFollowRedirects(false);
- return conn.getInputStream();
- };
- }
- return new Wget(cp, charsetDetector, maxResponseBytes);
- }
- }
-
+ private static final int MAX_URL_LENGTH = 2_048;
private final ConnectionProvider connectionProvider;
- private final CharsetDetector charsetDetector;
- private final long maxResponseBytes;
+ private final CharsetDetector charsetDetector;
+ private final long maxResponseBytes;
private Wget(final ConnectionProvider cp,
final CharsetDetector cd,
final long maxBytes) {
this.connectionProvider = cp;
- this.charsetDetector = cd;
- this.maxResponseBytes = maxBytes;
+ this.charsetDetector = cd;
+ this.maxResponseBytes = maxBytes;
}
- private static final int MAX_URL_LENGTH = 2_048;
-
/**
* Shortcut that uses the default configuration.
*/
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static void url(final String url, final StringBuilder sb) throws IOException {
if (url.length() > MAX_URL_LENGTH)
throw new IllegalArgumentException("URL too long (" + url.length() + ")");
@@ -95,15 +53,94 @@ public void fetch(final String url, final Appendable out) throws IOException {
if (!"http".equals(scheme) && !"https".equals(scheme))
throw new MalformedURLException("Only http/https allowed, not " + scheme);
- try (InputStream raw = connectionProvider.open(u);
+ try (InputStream raw = connectionProvider.open(u);
InputStream limited = new LimitedInputStream(raw, maxResponseBytes)) {
Charset cs = charsetDetector.detect(raw, null);
if (cs == null) cs = StandardCharsets.UTF_8;
- Reader reader = new BufferedReader(new InputStreamReader(limited, cs));
- for (int ch; (ch = reader.read()) != -1; )
- out.append((char) ch);
+ try (Reader reader = new BufferedReader(new InputStreamReader(limited, cs))) {
+ for (int ch; (ch = reader.read()) != -1; )
+ out.append((char) ch);
+ }
+ }
+ }
+
+ /**
+ * Opens a (potentially mocked) connection for the given URL.
+ */
+ @FunctionalInterface
+ public interface ConnectionProvider {
+ InputStream open(URL url) throws IOException;
+ }
+
+ /**
+ * Decides which charset to use when decoding the response body.
+ */
+ @FunctionalInterface
+ public interface CharsetDetector {
+ Charset detect(InputStream response, String contentTypeHeader);
+ }
+
+ public static final class Builder {
+ private static final ConnectionProvider DEFAULT_PROVIDER = URL::openStream;
+
+ private ConnectionProvider connectionProvider = DEFAULT_PROVIDER;
+ private CharsetDetector charsetDetector = (in, ct) -> StandardCharsets.UTF_8;
+ private int connectTimeoutMs = 10_000;
+ private int readTimeoutMs = 10_000;
+ private long maxResponseBytes = 10L << 20; // 10 MiB
+
+ @Deprecated(/* to be removed in 2027, only used in tests */)
+ public Builder connectionProvider(final ConnectionProvider provider) {
+ this.connectionProvider = Objects.requireNonNull(provider);
+ return this;
+ }
+
+ @Deprecated(/* to be removed in 2027, only used in tests */)
+ public Builder charsetDetector(final CharsetDetector detector) {
+ this.charsetDetector = Objects.requireNonNull(detector);
+ return this;
+ }
+
+ @Deprecated(/* to be removed in 2027, only used in tests */)
+ public Builder connectTimeoutMs(final int timeoutMs) {
+ this.connectTimeoutMs = timeoutMs;
+ return this;
+ }
+
+ @Deprecated(/* to be removed in 2027, only used in tests */)
+ public Builder readTimeoutMs(final int timeoutMs) {
+ this.readTimeoutMs = timeoutMs;
+ return this;
+ }
+
+ @Deprecated(/* to be removed in 2027, only used in tests */)
+ public Builder maxResponseBytes(final long maxResponseBytes) {
+ if (maxResponseBytes < 0)
+ throw new IllegalArgumentException("maxResponseBytes must be >= 0");
+ this.maxResponseBytes = maxResponseBytes;
+ return this;
+ }
+
+ /**
+ * Creates a {@link Wget} with defaults or caller-supplied overrides.
+ */
+ public Wget build() {
+ ConnectionProvider cp = this.connectionProvider;
+ if (cp == DEFAULT_PROVIDER) { // wrap default provider to apply time-outs
+ final int ct = connectTimeoutMs;
+ final int rt = readTimeoutMs;
+ cp = url -> {
+ URLConnection conn = url.openConnection();
+ conn.setConnectTimeout(ct);
+ conn.setReadTimeout(rt);
+ if (conn instanceof HttpURLConnection)
+ ((HttpURLConnection) conn).setInstanceFollowRedirects(false);
+ return conn.getInputStream();
+ };
+ }
+ return new Wget(cp, charsetDetector, maxResponseBytes);
}
}
}
diff --git a/src/main/java/net/openhft/chronicle/core/onoes/ChainedExceptionHandler.java b/src/main/java/net/openhft/chronicle/core/onoes/ChainedExceptionHandler.java
index 8527233845..05cd90c0ae 100644
--- a/src/main/java/net/openhft/chronicle/core/onoes/ChainedExceptionHandler.java
+++ b/src/main/java/net/openhft/chronicle/core/onoes/ChainedExceptionHandler.java
@@ -66,7 +66,7 @@ public void on(@NotNull Class> clazz, @Nullable String message, @Nullable Thro
try {
eh.on(clazz, message, thrown);
} catch (Throwable t) {
- LoggerFactory.getLogger(eh.getClass()).error("Unable to call with message " + message, t);
+ LoggerFactory.getLogger(eh.getClass()).error("Unable to call with message {}", message, t);
}
}
}
@@ -85,7 +85,7 @@ public void on(@NotNull Logger logger, @Nullable String message, Throwable throw
try {
eh.on(logger, message, thrown);
} catch (Throwable t) {
- LoggerFactory.getLogger(eh.getClass()).error("Unable to call with message " + message, t);
+ LoggerFactory.getLogger(eh.getClass()).error("Unable to call with message {}", message, t);
}
}
diff --git a/src/main/java/net/openhft/chronicle/core/onoes/ExceptionKey.java b/src/main/java/net/openhft/chronicle/core/onoes/ExceptionKey.java
index a44e356a2c..e2bd3ab0d4 100644
--- a/src/main/java/net/openhft/chronicle/core/onoes/ExceptionKey.java
+++ b/src/main/java/net/openhft/chronicle/core/onoes/ExceptionKey.java
@@ -80,7 +80,7 @@ public Class> clazz() {
* @return The message.
*/
public String message() {
- return message;
+ return message == null || message.isEmpty() ? throwable.toString() : message;
}
/**
diff --git a/src/main/java/net/openhft/chronicle/core/onoes/ThreadLocalisedExceptionHandler.java b/src/main/java/net/openhft/chronicle/core/onoes/ThreadLocalisedExceptionHandler.java
index 169cb18169..ad2981c2f8 100644
--- a/src/main/java/net/openhft/chronicle/core/onoes/ThreadLocalisedExceptionHandler.java
+++ b/src/main/java/net/openhft/chronicle/core/onoes/ThreadLocalisedExceptionHandler.java
@@ -119,6 +119,7 @@ public ThreadLocalisedExceptionHandler defaultHandler(ExceptionHandler defaultHa
*
* @return the thread-local handler or {@code null}
*/
+ @Deprecated(/* to be removed in 2027 */)
public ExceptionHandler threadLocalHandler() {
return handlerTL.get();
}
diff --git a/src/main/java/net/openhft/chronicle/core/pom/PomProperties.java b/src/main/java/net/openhft/chronicle/core/pom/PomProperties.java
index 908a8b4adb..b30fab978a 100644
--- a/src/main/java/net/openhft/chronicle/core/pom/PomProperties.java
+++ b/src/main/java/net/openhft/chronicle/core/pom/PomProperties.java
@@ -42,6 +42,7 @@ private PomProperties() {
* @return a new instance of Properties for the provided parameters.
*/
@NotNull
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static Properties create(@NotNull final String groupId, @NotNull final String artifactId) {
return InternalPomProperties.create(groupId, artifactId);
}
diff --git a/src/main/java/net/openhft/chronicle/core/pool/ClassLookup.java b/src/main/java/net/openhft/chronicle/core/pool/ClassLookup.java
index 56a127a7b2..6fdbd89bdc 100644
--- a/src/main/java/net/openhft/chronicle/core/pool/ClassLookup.java
+++ b/src/main/java/net/openhft/chronicle/core/pool/ClassLookup.java
@@ -109,6 +109,7 @@ default ClassLookup wrap(@NotNull ClassLoader classLoader) {
* @throws NullPointerException if the provided {@code name} is {@code null}.
* @see #addAlias(Class, String) for how aliases are added to the pool.
*/
+ @Deprecated(/* to be removed in 2027, only used in tests */)
default CharSequence applyAlias(CharSequence name) {
try {
return nameFor(forName(name));
diff --git a/src/main/java/net/openhft/chronicle/core/pool/DynamicEnumClass.java b/src/main/java/net/openhft/chronicle/core/pool/DynamicEnumClass.java
index 7b9ee944a9..b345de44fd 100644
--- a/src/main/java/net/openhft/chronicle/core/pool/DynamicEnumClass.java
+++ b/src/main/java/net/openhft/chronicle/core/pool/DynamicEnumClass.java
@@ -32,13 +32,13 @@
* @param the type of enum instances this class will manage. It must extend {@link CoreDynamicEnum}.
* Example usage:
*
+ * EnumCache c =
+ * EnumCache.of(
+ * YesNo.class);
+ * YesNo maybe =
+ * c.valueOf("Maybe");
+ * }
+ *
*/
public class DynamicEnumClass> extends EnumCache {
@@ -48,9 +48,9 @@ public class DynamicEnumClass> extends EnumCache
private final List eList = new ArrayList<>();
// Fields to reflectively set properties on new instances.
private final Field nameField;
+ private final Field ordinalField;
// An array of enum values
private E[] values = null;
- private final Field ordinalField;
// The function used to create new enum instances
private final Function create = this::create;
diff --git a/src/main/java/net/openhft/chronicle/core/pool/EnumCache.java b/src/main/java/net/openhft/chronicle/core/pool/EnumCache.java
index 93e18b8a14..4e6088cac3 100644
--- a/src/main/java/net/openhft/chronicle/core/pool/EnumCache.java
+++ b/src/main/java/net/openhft/chronicle/core/pool/EnumCache.java
@@ -96,6 +96,7 @@ public Class> type() {
* @param index the ordinal index of the enum instance to retrieve.
* @return the enum instance at the given index.
*/
+ @Deprecated(/* to be removed in 2027 */)
public abstract E forIndex(int index);
/**
diff --git a/src/main/java/net/openhft/chronicle/core/pool/ParsingCache.java b/src/main/java/net/openhft/chronicle/core/pool/ParsingCache.java
index 17581a7600..73a23aa65a 100644
--- a/src/main/java/net/openhft/chronicle/core/pool/ParsingCache.java
+++ b/src/main/java/net/openhft/chronicle/core/pool/ParsingCache.java
@@ -33,6 +33,7 @@
*
* @param The type of object the cache stores. Typically, these are objects created from strings.
*/
+@Deprecated(/* to be removed in 2027, only used in tests */)
public class ParsingCache {
protected final ParsedData[] interner;
protected final int mask;
diff --git a/src/main/java/net/openhft/chronicle/core/pool/StringBuilderPool.java b/src/main/java/net/openhft/chronicle/core/pool/StringBuilderPool.java
index c5e7aff816..6943118bda 100644
--- a/src/main/java/net/openhft/chronicle/core/pool/StringBuilderPool.java
+++ b/src/main/java/net/openhft/chronicle/core/pool/StringBuilderPool.java
@@ -7,8 +7,6 @@
import net.openhft.chronicle.core.scoped.ScopedResourcePool;
import net.openhft.chronicle.core.scoped.ScopedThreadLocal;
-import static java.lang.ThreadLocal.withInitial;
-
/**
* This class provides a pool of StringBuilder objects for efficient string building operations.
* Each thread gets its own StringBuilder instance via a ThreadLocal,
@@ -18,13 +16,6 @@ public final class StringBuilderPool {
private static final int DEFAULT_STRING_BUILDER_POOL_SIZE_PER_THREAD = Jvm.getInteger("chronicle.stringBuilderPool.instancesPerThread", 4);
- /**
- * Thread-local variable that holds a StringBuilder for each thread.
- * The initial capacity for each StringBuilder is 128.
- */
- private final ThreadLocal sbtl = withInitial(
- () -> new StringBuilder(128));
-
/**
* Returns a scoped-thread-local pool of StringBuilders.
*
diff --git a/src/main/java/net/openhft/chronicle/core/pool/StringInterner.java b/src/main/java/net/openhft/chronicle/core/pool/StringInterner.java
index 57159c6bbe..b82bde321d 100644
--- a/src/main/java/net/openhft/chronicle/core/pool/StringInterner.java
+++ b/src/main/java/net/openhft/chronicle/core/pool/StringInterner.java
@@ -63,6 +63,7 @@ public StringInterner(int capacity) throws IllegalArgumentException {
/**
* @return the size of interner[]
*/
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public int capacity() {
return interner.length;
}
@@ -103,6 +104,7 @@ public String intern(@Nullable CharSequence cs) {
* @param onChanged callback invoked when a new value is stored
* @return the slot index or {@code -1} if the text is too long
*/
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public int index(@Nullable CharSequence cs, @Nullable Changed onChanged) {
if (cs == null)
return -1;
@@ -136,6 +138,7 @@ public int index(@Nullable CharSequence cs, @Nullable Changed onChanged) {
* @return the interned string, or {@code null} if no value is stored at that index
*/
@Nullable
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public String get(int index) {
return interner[index];
}
diff --git a/src/main/java/net/openhft/chronicle/core/threads/CleaningThread.java b/src/main/java/net/openhft/chronicle/core/threads/CleaningThread.java
index caeebbca2a..0956200dbe 100644
--- a/src/main/java/net/openhft/chronicle/core/threads/CleaningThread.java
+++ b/src/main/java/net/openhft/chronicle/core/threads/CleaningThread.java
@@ -30,10 +30,6 @@ public class CleaningThread extends Thread {
private static final Field TABLE;
private static final Field VALUE;
- private final boolean inEventLoop;
- @SuppressWarnings("unused")
- private final StackTrace createdHere = isResourceTracing() ? new StackTrace("Created here") : null;
-
// Static block to initialize reflection fields.
static {
THREAD_LOCALS = Jvm.getField(Thread.class, "threadLocals");
@@ -41,6 +37,9 @@ public class CleaningThread extends Thread {
VALUE = Jvm.getField(TABLE.getType().getComponentType(), "value");
}
+ private final boolean inEventLoop;
+ private final StackTrace createdHere = isResourceTracing() ? new StackTrace("Created here") : null;
+
/**
* Constructs a new CleaningThread with the specified target Runnable.
*
@@ -203,4 +202,11 @@ public void run() {
public boolean inEventLoop() {
return inEventLoop;
}
+
+ /**
+ * @return where the Thread was created, if available
+ */
+ public StackTrace createdHere() {
+ return createdHere;
+ }
}
diff --git a/src/main/java/net/openhft/chronicle/core/threads/InterruptedRuntimeException.java b/src/main/java/net/openhft/chronicle/core/threads/InterruptedRuntimeException.java
index 5d6e8b3584..ef54b61d71 100644
--- a/src/main/java/net/openhft/chronicle/core/threads/InterruptedRuntimeException.java
+++ b/src/main/java/net/openhft/chronicle/core/threads/InterruptedRuntimeException.java
@@ -32,6 +32,7 @@ public class InterruptedRuntimeException extends IllegalStateException {
/**
* Constructs an {@code InterruptedRuntimeException} with no detail message or cause.
*/
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public InterruptedRuntimeException() {
}
diff --git a/src/main/java/net/openhft/chronicle/core/threads/ThreadDump.java b/src/main/java/net/openhft/chronicle/core/threads/ThreadDump.java
index 90f437b587..223fc5555b 100644
--- a/src/main/java/net/openhft/chronicle/core/threads/ThreadDump.java
+++ b/src/main/java/net/openhft/chronicle/core/threads/ThreadDump.java
@@ -132,7 +132,7 @@ public void assertNoNewThreads(int delay, @NotNull TimeUnit delayUnit) {
}
throw assertionError;
}
- Jvm.pause(delayMillis + (1L << (i/2)));
+ Jvm.pause(delayMillis + (1L << (i / 2)));
}
}
@@ -153,9 +153,7 @@ private boolean isExtra(String name) {
return false;
if (startsWith(name, "RMI ", "VM JFR ", "JFR ", "JMX ", "ForkJoinPool.commonPool-worker-", "JVMCI"))
return false;
- if (name.startsWith("HttpClient-") && name.endsWith("-SelectorManager"))
- return false;
- return true;
+ return !name.startsWith("HttpClient-") || !name.endsWith("-SelectorManager");
}
private void addThreadErrorDetails(AssertionError assertionError, Thread thread) {
diff --git a/src/main/java/net/openhft/chronicle/core/threads/ThreadLocalHelper.java b/src/main/java/net/openhft/chronicle/core/threads/ThreadLocalHelper.java
index 21ca8b023d..2dc1fce0fe 100644
--- a/src/main/java/net/openhft/chronicle/core/threads/ThreadLocalHelper.java
+++ b/src/main/java/net/openhft/chronicle/core/threads/ThreadLocalHelper.java
@@ -63,6 +63,7 @@ public static T getTL(@NotNull ThreadLocal> threadLocal, @N
* @return Existing or newly created value
*/
@NotNull
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static T getSTL(@NotNull ThreadLocal threadLocal, @NotNull Supplier supplier) {
@Nullable T ret = threadLocal.get();
if (ret == null) {
diff --git a/src/main/java/net/openhft/chronicle/core/time/SetTimeProvider.java b/src/main/java/net/openhft/chronicle/core/time/SetTimeProvider.java
index a69bf8cf59..9aee0f6764 100644
--- a/src/main/java/net/openhft/chronicle/core/time/SetTimeProvider.java
+++ b/src/main/java/net/openhft/chronicle/core/time/SetTimeProvider.java
@@ -60,6 +60,7 @@ public SetTimeProvider(Instant instant) {
*
* @return a new provider initialised to the current time
*/
+ @Deprecated(/* to be removed in 2027 */)
public SetTimeProvider now() {
return new SetTimeProvider(SystemTimeProvider.CLOCK.currentTimeNanos());
}
@@ -125,6 +126,7 @@ public long currentTimeMillis() {
* @param micros new time in microseconds, not less than the current value
* @throws IllegalArgumentException if the time would go backwards
*/
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public void currentTimeMicros(long micros) throws IllegalArgumentException {
currentTimeNanos(TimeUnit.MICROSECONDS.toNanos(micros));
}
@@ -167,6 +169,7 @@ public long currentTimeNanos() {
* @param unit target unit, not {@code null}
* @return the current time in that unit
*/
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public long currentTime(TimeUnit unit) {
return unit.convert(currentTimeNanos(), TimeUnit.NANOSECONDS);
}
diff --git a/src/main/java/net/openhft/chronicle/core/util/ClassMetrics.java b/src/main/java/net/openhft/chronicle/core/util/ClassMetrics.java
index 368e0a876c..49ac996b27 100644
--- a/src/main/java/net/openhft/chronicle/core/util/ClassMetrics.java
+++ b/src/main/java/net/openhft/chronicle/core/util/ClassMetrics.java
@@ -9,6 +9,7 @@
* ClassMetrics is a utility class that holds offset and length metrics of a class.
* It provides methods to access these metrics and overrides equals, hashCode, and toString methods.
*/
+@Deprecated(/* to be removed in 2027, only used in tests */)
public class ClassMetrics {
private final int offset;
private final int length;
diff --git a/src/main/java/net/openhft/chronicle/core/util/CompilerUtils.java b/src/main/java/net/openhft/chronicle/core/util/CompilerUtils.java
index b0e0840f91..094e54fb0c 100644
--- a/src/main/java/net/openhft/chronicle/core/util/CompilerUtils.java
+++ b/src/main/java/net/openhft/chronicle/core/util/CompilerUtils.java
@@ -19,6 +19,7 @@
* Note that this class is intended for use cases where there is a need to load classes into the JVM
* programmatically during runtime.
*/
+@Deprecated(/* to be removed in 2027, only used in tests */)
public final class CompilerUtils {
private static final Method DEFINE_CLASS_METHOD;
diff --git a/src/main/java/net/openhft/chronicle/core/util/GenericReflection.java b/src/main/java/net/openhft/chronicle/core/util/GenericReflection.java
index eb5229d4a1..20e2097207 100644
--- a/src/main/java/net/openhft/chronicle/core/util/GenericReflection.java
+++ b/src/main/java/net/openhft/chronicle/core/util/GenericReflection.java
@@ -142,6 +142,8 @@ public static Class> erase(Type type) {
}
if (type instanceof ParameterizedType)
return erase(((ParameterizedType) type).getRawType());
- return (Class>) type;
+ if (type instanceof Class)
+ return (Class>) type;
+ throw new UnsupportedOperationException("Unsupported type: " + type);
}
}
diff --git a/src/main/java/net/openhft/chronicle/core/util/Histogram.java b/src/main/java/net/openhft/chronicle/core/util/Histogram.java
index f08670e059..4d7db989e8 100644
--- a/src/main/java/net/openhft/chronicle/core/util/Histogram.java
+++ b/src/main/java/net/openhft/chronicle/core/util/Histogram.java
@@ -223,6 +223,7 @@ public double min() {
*
* @return the median value
*/
+ @Deprecated(/* to be removed in 2027 */)
public double typical() {
return percentile(0.5);
}
diff --git a/src/main/java/net/openhft/chronicle/core/util/Ints.java b/src/main/java/net/openhft/chronicle/core/util/Ints.java
index 840b190d5b..bf61fb6971 100644
--- a/src/main/java/net/openhft/chronicle/core/util/Ints.java
+++ b/src/main/java/net/openhft/chronicle/core/util/Ints.java
@@ -68,6 +68,7 @@ public static int requireNonNegative(final int value) {
* @throws AssertionError if the check fails and assertions are enabled both via the {@code -ea} JVM command
* line option and by setting {@link AssertUtil#SKIP_ASSERTIONS} to {@code false}.
*/
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static boolean assertIfEnabled(final IntPredicate requirement,
final int value) {
assert AssertUtil.SKIP_ASSERTIONS || requirement.test(value)
@@ -97,6 +98,7 @@ public static String failDescription(final IntPredicate requirement,
*
* @return a predicate that can test if a value is non-negative (i.e. value >= 0)
*/
+ @Deprecated(/* to be removed in 2027, only used in tests */)
public static IntPredicate nonNegative() {
return IntCondition.NON_NEGATIVE;
}
diff --git a/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java b/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java
index 80737426ab..39cf89cd11 100644
--- a/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java
+++ b/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java
@@ -50,10 +50,6 @@
@SuppressWarnings("unchecked")
public final class ObjectUtils {
- // Suppresses default constructor, ensuring non-instantiability.
- private ObjectUtils() {
- }
-
static final Map, Class>> PRIM_MAP = ofUnmodifiable(
entry(boolean.class, Boolean.class),
entry(byte.class, Byte.class),
@@ -75,9 +71,25 @@ private ObjectUtils() {
entry(float.class, 0.0f),
entry(double.class, 0.0d)
);
-
+ static final ClassLocal> PARSER_CL = ClassLocal.withInitial(new ConversionFunction());
+ static final ClassLocal