From 1279634955b5f85cc1150d5a39b4e41dd5508574 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 25 Mar 2024 11:45:33 +0000 Subject: [PATCH 01/43] Initial branch of x.26 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 56dbf2a870..ee5f88e114 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ chronicle-core - 2.25ea15-SNAPSHOT + 2.26ea0-SNAPSHOT bundle OpenHFT/Chronicle Core Chronicle-Core @@ -48,7 +48,7 @@ net.openhft third-party-bom - 3.25.0 + 3.25.2 pom import @@ -56,7 +56,7 @@ net.openhft chronicle-bom - 2.25ea-SNAPSHOT + 2.26ea-SNAPSHOT pom import From b7a294fb6108de896ab0c0c15024bc2b386af130 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 26 Mar 2024 14:27:20 +0000 Subject: [PATCH 02/43] Error on deprecated cleanup (#637) * Review deprecated methods, change build to error on deprecation * Fix compilation on Java 21 * revert * Move ByteBuffers to bytes.internal --- pom.xml | 4 ++-- src/main/java/net/openhft/chronicle/core/OS.java | 6 ++++++ .../openhft/chronicle/core/internal/AnnotationFinder.java | 1 - .../chronicle/core/internal/ReferenceCountedUtils.java | 1 - 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index ee5f88e114..08fe410744 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ net.openhft java-parent-pom 1.25.4 - + chronicle-core 2.26ea0-SNAPSHOT @@ -234,7 +234,7 @@ org.apache.maven.plugins maven-compiler-plugin - -Xlint:deprecation + -Xlint:deprecation,-options diff --git a/src/main/java/net/openhft/chronicle/core/OS.java b/src/main/java/net/openhft/chronicle/core/OS.java index 563f9aefed..11c2674d3a 100644 --- a/src/main/java/net/openhft/chronicle/core/OS.java +++ b/src/main/java/net/openhft/chronicle/core/OS.java @@ -283,6 +283,12 @@ public static String getTmp() { return TMP; } + /** + * @return the current working directory + */ + public static String getUserDir() { + return USER_DIR; + } /** * @return native memory accessor class */ diff --git a/src/main/java/net/openhft/chronicle/core/internal/AnnotationFinder.java b/src/main/java/net/openhft/chronicle/core/internal/AnnotationFinder.java index eee4842b9f..295f2bcf5a 100644 --- a/src/main/java/net/openhft/chronicle/core/internal/AnnotationFinder.java +++ b/src/main/java/net/openhft/chronicle/core/internal/AnnotationFinder.java @@ -42,7 +42,6 @@ public static A findAnnotation(AnnotatedElement annotated * @param the type of the annotation. * @return the annotation, or null if not found. */ - @SuppressWarnings("unchecked") private static A findAnnotationRecursively(AnnotatedElement annotatedElement, Class annotationType, Set visited) { try { // Check for direct annotation diff --git a/src/main/java/net/openhft/chronicle/core/internal/ReferenceCountedUtils.java b/src/main/java/net/openhft/chronicle/core/internal/ReferenceCountedUtils.java index 205dd966b5..6a3c908ad8 100644 --- a/src/main/java/net/openhft/chronicle/core/internal/ReferenceCountedUtils.java +++ b/src/main/java/net/openhft/chronicle/core/internal/ReferenceCountedUtils.java @@ -91,7 +91,6 @@ public static void assertReferencesReleased() { assertCloseablesClosed(); AssertionError openFiles = new AssertionError("Reference counted not released"); - //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (traceSet) { for (AbstractReferenceCounted key : traceSet) { if (key == null || key.refCount() == 0) From 212cde22bf34d31d29d01917180ea1c300a6ae69 Mon Sep 17 00:00:00 2001 From: "yevgen.pavlenko" Date: Wed, 27 Mar 2024 10:06:36 +0200 Subject: [PATCH 03/43] Deprecate due x.26 --- .../net/openhft/chronicle/core/Memory.java | 41 --- .../net/openhft/chronicle/core/Mocker.java | 67 ----- .../java/net/openhft/chronicle/core/OS.java | 38 +-- .../openhft/chronicle/core/UnsafeMemory.java | 24 -- .../net/openhft/chronicle/core/io/Wget.java | 20 -- .../core/onoes/GoogleExceptionHandler.java | 31 -- .../core/onoes/PrintExceptionHandler.java | 97 ------- .../onoes/StackoverflowExceptionHandler.java | 31 -- .../core/onoes/WebExceptionHandler.java | 93 ------ .../core/pool/StringBuilderPool.java | 22 -- .../chronicle/core/threads/JitterSampler.java | 7 - .../chronicle/core/time/Differencer.java | 31 -- .../chronicle/core/time/RunningMinimum.java | 59 ---- .../chronicle/core/time/SetTimeProvider.java | 1 - .../chronicle/core/time/TimeProvider.java | 27 -- .../core/time/VanillaDifferencer.java | 33 --- .../chronicle/core/util/Annotations.java | 90 ------ .../chronicle/core/util/BooleanConsumer.java | 23 -- .../chronicle/core/util/ByteBuffers.java | 68 ----- .../chronicle/core/util/ByteConsumer.java | 23 -- .../chronicle/core/util/CharConsumer.java | 23 -- .../chronicle/core/util/FloatConsumer.java | 23 -- .../chronicle/core/util/ObjectUtils.java | 5 - .../chronicle/core/util/ShortConsumer.java | 23 -- .../core/util/ThrowingBiConsumer.java | 14 - .../core/util/ThrowingBiFunction.java | 13 - .../chronicle/core/util/ThrowingConsumer.java | 15 - .../core/util/ThrowingIntSupplier.java | 16 -- .../core/util/ThrowingLongSupplier.java | 16 -- .../chronicle/core/util/URIEncoder.java | 69 ----- .../chronicle/core/values/UnsetLongValue.java | 121 -------- .../watcher/ClassifyingWatcherListener.java | 60 ---- .../core/watcher/FileClassifier.java | 23 -- .../chronicle/core/watcher/FileManager.java | 25 -- .../core/watcher/FileSystemWatcher.java | 272 ------------------ .../core/watcher/JMXFileManager.java | 75 ----- .../core/watcher/JMXFileManagerMBean.java | 25 -- .../core/watcher/PlainFileClassifier.java | 34 --- .../core/watcher/PlainFileManager.java | 60 ---- .../core/watcher/PlainFileManagerMBean.java | 26 -- .../core/watcher/WatcherListener.java | 38 --- .../openhft/chronicle/core/MemoryTest.java | 7 - .../core/announcer/AnnouncerTest.java | 9 +- .../openhft/chronicle/core/io/WgetTest.java | 14 +- .../core/pool/StringBuilderPoolTest.java | 25 -- .../core/time/PosixTimeProviderTest.java | 4 - .../core/time/RunningMinimumTest.java | 55 ---- .../core/time/SystemTimeProviderTest.java | 3 - .../chronicle/core/util/AnnotationsTest.java | 68 ----- .../chronicle/core/util/ByteConsumerTest.java | 35 +-- .../chronicle/core/util/ObjectUtilsTest.java | 7 - .../core/util/ThrowingConsumerTest.java | 49 ---- .../chronicle/core/util/URIEncoderTest.java | 31 -- .../core/watcher/FileSystemWatcherMain.java | 22 -- .../core/watcher/FileSystemWatcherTest.java | 140 --------- 55 files changed, 11 insertions(+), 2260 deletions(-) delete mode 100644 src/main/java/net/openhft/chronicle/core/onoes/GoogleExceptionHandler.java delete mode 100644 src/main/java/net/openhft/chronicle/core/onoes/PrintExceptionHandler.java delete mode 100644 src/main/java/net/openhft/chronicle/core/onoes/StackoverflowExceptionHandler.java delete mode 100644 src/main/java/net/openhft/chronicle/core/onoes/WebExceptionHandler.java delete mode 100644 src/main/java/net/openhft/chronicle/core/time/Differencer.java delete mode 100644 src/main/java/net/openhft/chronicle/core/time/RunningMinimum.java delete mode 100644 src/main/java/net/openhft/chronicle/core/time/VanillaDifferencer.java delete mode 100644 src/main/java/net/openhft/chronicle/core/util/Annotations.java delete mode 100644 src/main/java/net/openhft/chronicle/core/util/ByteBuffers.java delete mode 100644 src/main/java/net/openhft/chronicle/core/util/URIEncoder.java delete mode 100644 src/main/java/net/openhft/chronicle/core/values/UnsetLongValue.java delete mode 100644 src/main/java/net/openhft/chronicle/core/watcher/ClassifyingWatcherListener.java delete mode 100644 src/main/java/net/openhft/chronicle/core/watcher/FileClassifier.java delete mode 100644 src/main/java/net/openhft/chronicle/core/watcher/FileManager.java delete mode 100644 src/main/java/net/openhft/chronicle/core/watcher/FileSystemWatcher.java delete mode 100644 src/main/java/net/openhft/chronicle/core/watcher/JMXFileManager.java delete mode 100644 src/main/java/net/openhft/chronicle/core/watcher/JMXFileManagerMBean.java delete mode 100644 src/main/java/net/openhft/chronicle/core/watcher/PlainFileClassifier.java delete mode 100644 src/main/java/net/openhft/chronicle/core/watcher/PlainFileManager.java delete mode 100644 src/main/java/net/openhft/chronicle/core/watcher/PlainFileManagerMBean.java delete mode 100644 src/main/java/net/openhft/chronicle/core/watcher/WatcherListener.java delete mode 100644 src/test/java/net/openhft/chronicle/core/pool/StringBuilderPoolTest.java delete mode 100644 src/test/java/net/openhft/chronicle/core/time/RunningMinimumTest.java delete mode 100644 src/test/java/net/openhft/chronicle/core/util/AnnotationsTest.java delete mode 100644 src/test/java/net/openhft/chronicle/core/util/ThrowingConsumerTest.java delete mode 100644 src/test/java/net/openhft/chronicle/core/util/URIEncoderTest.java delete mode 100644 src/test/java/net/openhft/chronicle/core/watcher/FileSystemWatcherMain.java delete mode 100644 src/test/java/net/openhft/chronicle/core/watcher/FileSystemWatcherTest.java diff --git a/src/main/java/net/openhft/chronicle/core/Memory.java b/src/main/java/net/openhft/chronicle/core/Memory.java index 8d2bf3c709..c9a79364bc 100644 --- a/src/main/java/net/openhft/chronicle/core/Memory.java +++ b/src/main/java/net/openhft/chronicle/core/Memory.java @@ -19,35 +19,18 @@ package net.openhft.chronicle.core; import net.openhft.chronicle.core.annotation.Positive; -import net.openhft.chronicle.core.util.Longs; import net.openhft.chronicle.core.util.MisAlignedAssertionError; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import sun.misc.Unsafe; import java.lang.reflect.Field; import java.nio.ByteBuffer; -import static java.util.Objects.nonNull; -import static net.openhft.chronicle.assertions.AssertUtil.SKIP_ASSERTIONS; -import static net.openhft.chronicle.core.util.Longs.assertIfEnabled; - /** * The Memory interface provides low-level memory access methods. */ public interface Memory { - /** - * Retrieves the amount of heap memory currently used by the application. - * - * @return The number of bytes used in the heap memory. - */ - @Deprecated(/* remove in x.26 */) - default long heapUsed() { - Runtime runtime = Runtime.getRuntime(); - return runtime.totalMemory() - runtime.freeMemory(); - } - /** * Ensures that all previous writes to memory are completed before any * subsequent memory access instruction. @@ -368,30 +351,6 @@ default long heapUsed() { */ void copyMemory(long fromAddress, long address, long length); - /** - * Deprecated method. Copies a range of bytes from the given byte array to the specified object at the given offset. - * - * @param bytes the source byte array - * @param offset the starting index in the byte array - * @param obj2 the destination object - * @param offset2 the starting offset in the destination object - * @param length the number of bytes to copy - * @deprecated This method is deprecated and will be removed in a future version (x.24). - */ - @Deprecated(/* to be removed in x.26 */) - default void copyMemory(byte[] src, int srcOffset, @Nullable Object dest, long destOffset, int length) { - assert SKIP_ASSERTIONS || nonNull(src); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), srcOffset); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), destOffset); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), length); - - if (dest instanceof byte[]) { - copyMemory(src, srcOffset, (byte[]) dest, Math.toIntExact(destOffset - Unsafe.ARRAY_BYTE_BASE_OFFSET), length); - } else { - copyMemory(src, Unsafe.ARRAY_BYTE_BASE_OFFSET + srcOffset, dest, destOffset, length); - } - } - /** * Copies a range of memory from the given object to the specified memory address. * diff --git a/src/main/java/net/openhft/chronicle/core/Mocker.java b/src/main/java/net/openhft/chronicle/core/Mocker.java index 24c911af41..f82a31164c 100644 --- a/src/main/java/net/openhft/chronicle/core/Mocker.java +++ b/src/main/java/net/openhft/chronicle/core/Mocker.java @@ -21,11 +21,8 @@ import org.jetbrains.annotations.NotNull; import java.io.PrintStream; -import java.io.PrintWriter; import java.io.StringWriter; import java.util.concurrent.BlockingQueue; -import java.util.function.BiConsumer; -import java.util.function.Consumer; /** * The Mocker class provides utility methods for creating mocked instances of interfaces. @@ -51,21 +48,6 @@ public static T logging(@NotNull Class interfaceType, String description, return net.openhft.chronicle.core.util.Mocker.logging(interfaceType, description, out); } - /** - * Creates a mocked instance of the specified interface that logs method invocations to the provided PrintWriter. - * - * @param the type of the class - * @param interfaceType the class to be mocked - * @param description the description of the mocking behavior - * @param out the PrintWriter to log the method invocations - * @return the mocked instance of the class - */ - @Deprecated(/* to be removed in x.26 */) - @NotNull - static T logging(@NotNull Class interfaceType, String description, @NotNull PrintWriter out) { - return net.openhft.chronicle.core.util.Mocker.logging(interfaceType, description, out); - } - /** * Creates a mocked instance of the specified interface that logs method invocations to the provided StringWriter. * @@ -96,55 +78,6 @@ public static T queuing(@NotNull Class interfaceType, String description, return net.openhft.chronicle.core.util.Mocker.queuing(interfaceType, description, queue); } - /** - * Creates a mocked instance of the specified interface that intercepts method invocations using the provided consumer. - * - * @param the type of the class - * @param interfaceType the class to be mocked - * @param description the description of the mocking behavior - * @param consumer the consumer to intercept and handle the method invocations - * @return the mocked instance of the class - */ - @Deprecated(/* to be removed in x.26 */) - @NotNull - public static T intercepting(@NotNull Class interfaceType, String description, @NotNull Consumer consumer) { - return net.openhft.chronicle.core.util.Mocker.intercepting(interfaceType, description, consumer, null); - } - - /** - * Creates a mocked instance of the specified interface that intercepts method invocations - * using the provided consumer, - * and optionally delegates the intercepted invocations to the provided object. - * - * @param the type of the class - * @param interfaceType the class to be mocked - * @param description the description of the mocking behavior - * @param consumer the consumer to intercept and handle the method invocations - * @param t the object to delegate the intercepted invocations, or null if no delegation is needed - * @return the mocked instance of the class - */ - @Deprecated(/* to be removed in x.26 */) - @NotNull - static T intercepting(@NotNull Class interfaceType, @NotNull final String description, @NotNull Consumer consumer, T t) { - return net.openhft.chronicle.core.util.Mocker.intercepting(interfaceType, description, consumer, t); - } - - /** - * Creates a mocked instance of the specified interface that intercepts method invocations using the provided - * bi-consumer, and optionally delegates the intercepted invocations to the provided object. - * - * @param the type of the class - * @param interfaceType the class to be mocked - * @param consumer the bi-consumer to intercept and handle the method invocations - * @param t the object to delegate the intercepted invocations, or null if no delegation is needed - * @return the mocked instance of the class - */ - @Deprecated(/* to be removed in x.26 */) - @NotNull - public static T intercepting(@NotNull Class interfaceType, @NotNull BiConsumer consumer, T t) { - return net.openhft.chronicle.core.util.Mocker.intercepting(interfaceType, consumer, t); - } - /** * Creates a mocked instance of the specified interface that ignores all method invocations. * diff --git a/src/main/java/net/openhft/chronicle/core/OS.java b/src/main/java/net/openhft/chronicle/core/OS.java index 11c2674d3a..0c3f353db9 100644 --- a/src/main/java/net/openhft/chronicle/core/OS.java +++ b/src/main/java/net/openhft/chronicle/core/OS.java @@ -49,11 +49,6 @@ * Low level access to OS class. The OS class provides utility methods related to the operating system. */ public final class OS { - @Deprecated(/* to be removed in x.26, use getUserDir() */) - public static final String USER_DIR = Jvm.getProperty("user.dir"); - - public static final String TMP = findTmp(); - public static final String USER_HOME = Jvm.getProperty("user.home"); public static final Exception TIME_LIMIT = new TimeLimitExceededException(); public static final int SAFE_PAGE_SIZE = 64 << 10; @@ -75,6 +70,8 @@ public final class OS { throw new AssertionError(e); } }); + private static final String USER_DIR = Jvm.getProperty("user.dir"); + public static final String TMP = findTmp(); private static final Field FD_FIELD = Jvm.getField(FileChannelImpl.class, "fd"); private static final String TARGET = findTarget(); private static final String USER_NAME = Jvm.getProperty("user.name"); @@ -716,37 +713,6 @@ public WriteZero(final Class fdi) throws IllegalAccessException { } } - @Deprecated(/* to be moved in x.26 to an internal package of Chronicle-Bytes */) - public static final class Unmapper implements Runnable { - private final long size; - - private final int pageSize; - - private volatile long address; - - public Unmapper(long address, long size, int pageSize) throws IllegalStateException { - - assert (address != 0); - this.address = address; - this.size = size; - this.pageSize = pageSize; - } - - @Override - public void run() { - if (address == 0) - return; - - try { - unmap(address, size, pageSize); - address = 0; - - } catch (@NotNull IOException e) { - Jvm.warn().on(OS.class, "Error on unmap and release", e); - } - } - } - static class IPAddressHolder { public static final String NO_ADDRESS = "0.0.0.0"; static final String IP_ADDRESS = getIPAddress0(); diff --git a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java index 3ec53008eb..e7226b8815 100644 --- a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java +++ b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java @@ -1078,30 +1078,6 @@ public void copyMemory(long srcAddress, long destAddress, long length) { } } - /** - * Copies memory from a byte array to an object. - * - * @param src source byte array. - * @param srcOffset offset of the source array from where to start copying. - * @param dest destination object. - * @param destOffset offset of the destination object from where to place the copied memory. - * @param length the length of memory to copy. - */ - @Deprecated(/* for removal in x.26 */) - @Override - public void copyMemory(byte[] src, int srcOffset, @Nullable Object dest, long destOffset, int length) { - assert SKIP_ASSERTIONS || nonNull(src); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), srcOffset); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), destOffset); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), length); - - if (dest instanceof byte[]) { - copyMemory(src, srcOffset, (byte[]) dest, Math.toIntExact(destOffset - ARRAY_BYTE_BASE_OFFSET), length); - } else { - copyMemoryLoop(src, ARRAY_BYTE_BASE_OFFSET + srcOffset, dest, destOffset, length); - } - } - /** * Copies memory from one byte array to another. * 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 45faca022d..37e8314c86 100644 --- a/src/main/java/net/openhft/chronicle/core/io/Wget.java +++ b/src/main/java/net/openhft/chronicle/core/io/Wget.java @@ -18,8 +18,6 @@ package net.openhft.chronicle.core.io; -import net.openhft.chronicle.core.pool.StringBuilderPool; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -33,27 +31,9 @@ */ public final class Wget { - @Deprecated(/* To be removed in x.26 */) - private static final StringBuilderPool STRING_BUILDER_POOL = new StringBuilderPool(); - private Wget() { } - /** - * Performs an HTTP GET request to the specified URL. - * - * @param url the URL of the HTTP GET request - * @return the result of the request as a {@link CharSequence} - * @throws IOException if an error occurs while establishing the connection - * @deprecated Use {@link #url(String, StringBuilder)} instead, this implementation is very dangerous - */ - @Deprecated(/* To be removed in x.26 */) - public static CharSequence url(String url) throws IOException { - final StringBuilder sb = STRING_BUILDER_POOL.acquireStringBuilder(); - url(url, sb); - return sb; - } - /** * Performs an HTTP GET request to the specified URL. * diff --git a/src/main/java/net/openhft/chronicle/core/onoes/GoogleExceptionHandler.java b/src/main/java/net/openhft/chronicle/core/onoes/GoogleExceptionHandler.java deleted file mode 100644 index 565ab8d9f7..0000000000 --- a/src/main/java/net/openhft/chronicle/core/onoes/GoogleExceptionHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package net.openhft.chronicle.core.onoes; - -import org.jetbrains.annotations.NotNull; - -@Deprecated(/* to be moved in x.26 to a demo repo */) -public class GoogleExceptionHandler extends WebExceptionHandler { - public static final ExceptionHandler WARN = new GoogleExceptionHandler(Slf4jExceptionHandler.WARN); - - public GoogleExceptionHandler(@NotNull ExceptionHandler fallBack) { - super("Google.properties", fallBack); - } -} diff --git a/src/main/java/net/openhft/chronicle/core/onoes/PrintExceptionHandler.java b/src/main/java/net/openhft/chronicle/core/onoes/PrintExceptionHandler.java deleted file mode 100644 index 034e46859b..0000000000 --- a/src/main/java/net/openhft/chronicle/core/onoes/PrintExceptionHandler.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package net.openhft.chronicle.core.onoes; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.slf4j.Logger; - -import java.io.PrintStream; -import java.time.LocalDateTime; - -/** - * PrintExceptionHandler is an enumeration implementing the ExceptionHandler interface. - * It is used to log exceptions to either the standard output or standard error. - * - *
    - *
  • {@link #ERR} - Logs to the standard error stream.
  • - *
  • {@link #OUT} - Logs to the standard output stream.
  • - *
- *

- * Additionally, it provides two static instances, {@link #WARN} and {@link #DEBUG}, - * which correspond to {@link #ERR} and {@link #OUT} respectively. - */ -@Deprecated(/* to be removed in x.26 */) -public enum PrintExceptionHandler implements ExceptionHandler { - ERR(System.err) { - @Override - public void on(@NotNull Logger logger, @Nullable String message, Throwable thrown) { - printLog(logger, message, thrown, this); - } - }, - OUT(System.out) { - @Override - public void on(@NotNull Logger logger, @Nullable String message, Throwable thrown) { - printLog(logger, message, thrown, this); - } - }; - - public static final PrintExceptionHandler WARN = ERR; - public static final PrintExceptionHandler DEBUG = OUT; - - private final PrintStream printStream; - - /** - * Constructs an instance of PrintExceptionHandler with the specified PrintStream. - * - * @param printStream the PrintStream to which the handler will log. - */ - PrintExceptionHandler(final PrintStream printStream) { - this.printStream = printStream; - } - - /** - * Prints a log message to the associated PrintStream. - * If a throwable is provided, its stack trace is also printed. - * - * @param logger the logger instance. Must not be null. - * @param message a custom message detailing the error, or null. - * @param thrown the throwable instance representing the error, or null. - * @param exceptionHandler the instance of PrintExceptionHandler which will output the log message. - */ - private static void printLog(@NotNull final Logger logger, - final String message, - @Nullable final Throwable thrown, - final PrintExceptionHandler exceptionHandler) { - final boolean interrupted = Thread.interrupted(); - try { - synchronized (exceptionHandler.printStream) { - exceptionHandler.printStream.print(LocalDateTime.now() + " " + Thread.currentThread().getName() + " " + logger.getName() + " " + message); - if (thrown != null) - thrown.printStackTrace(exceptionHandler.printStream); - else - exceptionHandler.printStream.println(); - } - } finally { - if (interrupted) - Thread.currentThread().interrupt(); - } - } -} diff --git a/src/main/java/net/openhft/chronicle/core/onoes/StackoverflowExceptionHandler.java b/src/main/java/net/openhft/chronicle/core/onoes/StackoverflowExceptionHandler.java deleted file mode 100644 index 38e58512e4..0000000000 --- a/src/main/java/net/openhft/chronicle/core/onoes/StackoverflowExceptionHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package net.openhft.chronicle.core.onoes; - -import org.jetbrains.annotations.NotNull; - -@Deprecated(/* to be moved in x.26 to a demo repo */) -public class StackoverflowExceptionHandler extends WebExceptionHandler { - public static final ExceptionHandler WARN = new StackoverflowExceptionHandler(Slf4jExceptionHandler.WARN); - - public StackoverflowExceptionHandler(@NotNull ExceptionHandler fallBack) { - super("Stackoverflow.properties", fallBack); - } -} diff --git a/src/main/java/net/openhft/chronicle/core/onoes/WebExceptionHandler.java b/src/main/java/net/openhft/chronicle/core/onoes/WebExceptionHandler.java deleted file mode 100644 index ceda7c6502..0000000000 --- a/src/main/java/net/openhft/chronicle/core/onoes/WebExceptionHandler.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package net.openhft.chronicle.core.onoes; - -import net.openhft.chronicle.core.Jvm; -import net.openhft.chronicle.core.util.URIEncoder; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.slf4j.Logger; - -import java.awt.*; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Properties; - -@Deprecated(/* to be moved in x.26 to a demo repo */) -public class WebExceptionHandler implements ExceptionHandler { - private final Properties properties = new Properties(); - - @NotNull - private final ExceptionHandler fallBack; - private final String baseURI; - - public WebExceptionHandler(String propertiesFile, @NotNull ExceptionHandler fallBack) { - assert fallBack != null; - this.fallBack = fallBack; - InputStream stream = WebExceptionHandler.class.getResourceAsStream(propertiesFile); - try { - if (stream != null) - properties.load(stream); - } catch (IOException e) { - Slf4jExceptionHandler.WARN.on(getClass(), "Unable to load " + propertiesFile, e); - } - baseURI = properties.getProperty("baseUri", "http://stackoverflow.com/search?q=%5Bjava%5D"); - } - - @Override - public void on(@NotNull Logger logger, @Nullable String message, @Nullable Throwable t) { - while (t != null && t.getCause() != null && t.getCause() != t) - t = t.getCause(); - - String uri; - if (t == null) { - uri = null; - } else { - uri = properties.getProperty(t.getClass().getName()); - } - if (uri == null) { - uri = baseURI; - String version = Jvm.getProperty("java.version"); - if (version.compareTo("1.5") >= 0) { - @NotNull String[] parts = version.split("\\."); - version = parts[1]; - } - - uri += "+" + version; - if (t != null) { - uri += "+" + URIEncoder.encodeURI(t.toString()); - } - uri += "+" + URIEncoder.encodeURI(logger.getName()); - - if (message != null) - uri += "+" + URIEncoder.encodeURI(message); - } - try { - if (Jvm.isDebug() && Desktop.isDesktopSupported()) - Desktop.getDesktop().browse(new URI(uri)); - else - fallBack.on(logger, message, t); - - } catch (Exception e) { - fallBack.on(WebExceptionHandler.class, "Failed to open browser", e); - } - } -} 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 f2ce19bf20..2e874c9c25 100644 --- a/src/main/java/net/openhft/chronicle/core/pool/StringBuilderPool.java +++ b/src/main/java/net/openhft/chronicle/core/pool/StringBuilderPool.java @@ -33,13 +33,6 @@ public final class StringBuilderPool { private static final int DEFAULT_STRING_BUILDER_POOL_SIZE_PER_THREAD = Jvm.getInteger("chronicle.stringBuilderPool.instancesPerThread", 4); - /** - * @deprecated Use {@link StringBuilderPool#createThreadLocal(int)} - */ - @Deprecated(/* To be removed in x.26 */) - public StringBuilderPool() { - } - /** * Thread-local variable that holds a StringBuilder for each thread. * The initial capacity for each StringBuilder is 128. @@ -47,21 +40,6 @@ public StringBuilderPool() { private final ThreadLocal sbtl = withInitial( () -> new StringBuilder(128)); - /** - * Returns a StringBuilder instance from the pool. - * If the current thread does not yet have a StringBuilder, it is created and added to the pool. - * The length of the StringBuilder is reset to 0 before being returned. - * - * @return a StringBuilder instance with length 0. - * @deprecated Use {@link StringBuilderPool#createThreadLocal(int)} and {@link ScopedResourcePool#get()} instead - */ - @Deprecated(/* To be removed in x.26 */) - public StringBuilder acquireStringBuilder() { - StringBuilder sb = sbtl.get(); - sb.setLength(0); - return sb; - } - /** * Create a scoped-thread-local pool of StringBuilders */ diff --git a/src/main/java/net/openhft/chronicle/core/threads/JitterSampler.java b/src/main/java/net/openhft/chronicle/core/threads/JitterSampler.java index 2e93547aa2..edd3a79a7d 100644 --- a/src/main/java/net/openhft/chronicle/core/threads/JitterSampler.java +++ b/src/main/java/net/openhft/chronicle/core/threads/JitterSampler.java @@ -108,11 +108,4 @@ public static void finished() { time = Long.MAX_VALUE; } - /** - * @deprecated Use {@link Jvm#pause(long)} instead - */ - @Deprecated(/* For removal in x.26 */) - public static void sleepSilently(int millis) { - Jvm.pause(millis); - } } diff --git a/src/main/java/net/openhft/chronicle/core/time/Differencer.java b/src/main/java/net/openhft/chronicle/core/time/Differencer.java deleted file mode 100644 index b935d8424a..0000000000 --- a/src/main/java/net/openhft/chronicle/core/time/Differencer.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package net.openhft.chronicle.core.time; - -/** - * User: peter.lawrey - * Date: 05/08/13 - * Time: 19:06 - */ -@Deprecated(/* to be removed in x.26 */) -@FunctionalInterface -interface Differencer { - long sample(long startTime, long endTime); -} diff --git a/src/main/java/net/openhft/chronicle/core/time/RunningMinimum.java b/src/main/java/net/openhft/chronicle/core/time/RunningMinimum.java deleted file mode 100644 index 1bab636ed9..0000000000 --- a/src/main/java/net/openhft/chronicle/core/time/RunningMinimum.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package net.openhft.chronicle.core.time; - -/** - * User: peter.lawrey - * Date: 05/08/13 - * Time: 19:06 - */ -@Deprecated(/* to be removed in x.26 */) -public class RunningMinimum implements Differencer { - private final long actualMinimum; - private final int drift; - private long lastStartTime = Long.MIN_VALUE; - private long minimum = Long.MAX_VALUE; - - public RunningMinimum(long actualMinimum) { - this(actualMinimum, 100 * 1000); - } - - private RunningMinimum(long actualMinimum, int drift) { - this.actualMinimum = actualMinimum; - this.drift = drift; - } - - @Override - public long sample(long startTime, long endTime) { - if (lastStartTime + drift <= startTime) { - if (lastStartTime != Long.MIN_VALUE) - minimum += (startTime - lastStartTime) / drift; - lastStartTime = startTime; - } - long delta = endTime - startTime; - if (minimum > delta) - minimum = delta; - return delta - minimum + actualMinimum; - } - - public long minimum() { - return minimum; - } -} 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 6eb98ec954..66f36a4916 100644 --- a/src/main/java/net/openhft/chronicle/core/time/SetTimeProvider.java +++ b/src/main/java/net/openhft/chronicle/core/time/SetTimeProvider.java @@ -172,7 +172,6 @@ public long currentTimeNanos() { * @param unit The time unit to return the current time in. * @return The current time in the specified time unit. */ - @Override public long currentTime(TimeUnit unit) { return unit.convert(currentTimeNanos(), TimeUnit.NANOSECONDS); } diff --git a/src/main/java/net/openhft/chronicle/core/time/TimeProvider.java b/src/main/java/net/openhft/chronicle/core/time/TimeProvider.java index 62cba87d42..1a473b87da 100644 --- a/src/main/java/net/openhft/chronicle/core/time/TimeProvider.java +++ b/src/main/java/net/openhft/chronicle/core/time/TimeProvider.java @@ -18,8 +18,6 @@ package net.openhft.chronicle.core.time; -import java.util.concurrent.TimeUnit; - /** * Defines an interface for providing high-resolution wall-clock timestamps. *

@@ -78,29 +76,4 @@ default long currentTimeNanos() throws IllegalStateException { return currentTimeMicros() * 1000; } - /** - * Returns the current time in the specified {@link TimeUnit}. - *

- * This method is deprecated and will be removed in a future version. - * Use {@link #currentTimeMillis()}, {@link #currentTimeMicros()}, or {@link #currentTimeNanos()} - * as per the required precision. - * - * @param timeUnit the {@link TimeUnit} to return the current time in - * @return the current time in the specified time unit - * @throws IllegalStateException if the time cannot be determined or converted - * @deprecated to be removed in x.26 - */ - @Deprecated(/* to be removed in x.26 */) - default long currentTime(TimeUnit timeUnit) throws IllegalStateException { - switch (timeUnit) { - case NANOSECONDS: - return currentTimeNanos(); - case MICROSECONDS: - return currentTimeMicros(); - case MILLISECONDS: - return currentTimeMillis(); - default: - return timeUnit.convert(currentTimeNanos(), TimeUnit.NANOSECONDS); - } - } } diff --git a/src/main/java/net/openhft/chronicle/core/time/VanillaDifferencer.java b/src/main/java/net/openhft/chronicle/core/time/VanillaDifferencer.java deleted file mode 100644 index cd8f61a711..0000000000 --- a/src/main/java/net/openhft/chronicle/core/time/VanillaDifferencer.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package net.openhft.chronicle.core.time; - -/** - * User: peter.lawrey - * Date: 05/08/13 - * Time: 19:07 - */ -@Deprecated(/* to be removed in x.26 */) -public class VanillaDifferencer implements Differencer { - @Override - public long sample(long startTime, long endTime) { - return endTime - startTime; - } -} diff --git a/src/main/java/net/openhft/chronicle/core/util/Annotations.java b/src/main/java/net/openhft/chronicle/core/util/Annotations.java deleted file mode 100644 index 4385207be9..0000000000 --- a/src/main/java/net/openhft/chronicle/core/util/Annotations.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.openhft.chronicle.core.util; - -import net.openhft.chronicle.core.Jvm; -import org.jetbrains.annotations.Nullable; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Method; - -/** - * Utility class for working with annotations on methods and classes. - *

- * Provides helper methods to fetch annotations from a method or class, including its superclasses and interfaces. - *

- * Note: This class is deprecated and will be removed in version x.26. Use {@link Jvm#findAnnotation(AnnotatedElement, Class)} instead. - */ -@Deprecated(/* to be removed in x.26, replaced by Jvm.findAnnotation */) -public final class Annotations { - private Annotations() { - } - - /** - * Finds the specified annotation on a method of a given class, its superclass, or interfaces. - * - * @param the type of the annotation to be fetched - * @param annoClass the Class object corresponding to the annotation type - * @param aClass the Class object in which to find the method - * @param name the name of the method - * @param parameterTypes the parameter types of the method - * @return the annotation of type {@code A} if present, or {@code null} otherwise - */ - public static A findAnnotation(Class annoClass, Class aClass, String name, Class[] parameterTypes) { - A methodId; - try { - Method m = aClass.getMethod(name, parameterTypes); - methodId = m.getAnnotation(annoClass); - if (methodId != null) - return methodId; - } catch (NoSuchMethodException e) { - // ignored - } - Class superclass = aClass.getSuperclass(); - if (!(superclass == null || superclass == Object.class)) { - methodId = findAnnotation(annoClass, superclass, name, parameterTypes); - if (methodId != null) - return methodId; - } - for (Class iClass : aClass.getInterfaces()) { - methodId = findAnnotation(annoClass, iClass, name, parameterTypes); - if (methodId != null) - return methodId; - } - return null; - } - - /** - * Fetches the specified annotation from a method. If the method does not have the annotation, - * it attempts to find it in the declaring class, its superclass, or interfaces. - * - * @param the type of the annotation to be fetched - * @param method the method from which to fetch the annotation - * @param annotationClass the Class object corresponding to the annotation type - * @return the annotation of type {@code A} if present, or {@code null} otherwise - */ - @Nullable - public static A getAnnotation(Method method, Class annotationClass) { - A methodId = method.getAnnotation(annotationClass); - if (methodId == null) { - methodId = findAnnotation(annotationClass, method.getDeclaringClass(), method.getName(), method.getParameterTypes()); - } - return methodId; - } -} diff --git a/src/main/java/net/openhft/chronicle/core/util/BooleanConsumer.java b/src/main/java/net/openhft/chronicle/core/util/BooleanConsumer.java index 832a18b8b6..a1dbfa7dc6 100644 --- a/src/main/java/net/openhft/chronicle/core/util/BooleanConsumer.java +++ b/src/main/java/net/openhft/chronicle/core/util/BooleanConsumer.java @@ -17,10 +17,6 @@ */ package net.openhft.chronicle.core.util; -import org.jetbrains.annotations.NotNull; - -import java.util.Objects; - /** * Represents an operation that accepts a single {@code Boolean}-valued argument and returns no result. This is the * primitive type specialization of {@link java.util.function.Consumer} for {@code Boolean}. Unlike most other functional @@ -40,23 +36,4 @@ public interface BooleanConsumer { */ void accept(Boolean value); - /** - * Returns a composed {@code BooleanConsumer} that performs, in sequence, this operation followed by the {@code after} - * operation. If performing either operation throws an exception, it is relayed to the caller of the composed - * operation. If performing this operation throws an exception, the {@code after} operation will not be performed. - * - * @param after the operation to perform after this operation - * @return a composed {@code BooleanConsumer} that performs in sequence this operation followed by the {@code after} - * operation - * @throws NullPointerException if {@code after} is null - */ - @Deprecated(/* to be removed in x.26 */) - @NotNull - default BooleanConsumer andThen(@NotNull BooleanConsumer after) { - Objects.requireNonNull(after); - return (Boolean t) -> { - accept(t); - after.accept(t); - }; - } } diff --git a/src/main/java/net/openhft/chronicle/core/util/ByteBuffers.java b/src/main/java/net/openhft/chronicle/core/util/ByteBuffers.java deleted file mode 100644 index 0f6309f684..0000000000 --- a/src/main/java/net/openhft/chronicle/core/util/ByteBuffers.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2016-2022 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.chronicle.core.util; - -import net.openhft.chronicle.core.Jvm; - -import java.lang.reflect.Field; -import java.nio.ByteBuffer; - -/** - * Utility class for working with {@link ByteBuffer} instances. - *

- * Provides functionality to directly set the address and capacity of a ByteBuffer. - *

- * Note: This class is deprecated and will be removed in version x.26. - */ -@Deprecated(/* to be removed x.26 */) -public final class ByteBuffers { - private ByteBuffers() { - } - - private static final Field ADDRESS; - private static final Field CAPACITY; - - static { - ByteBuffer direct = ByteBuffer.allocateDirect(0); - ADDRESS = Jvm.getField(direct.getClass(), "address"); - CAPACITY = Jvm.getField(direct.getClass(), "capacity"); - } - - /** - * Sets the memory address and capacity of a {@link ByteBuffer} instance directly. - *

- * This method uses reflection to access and modify the address and capacity fields of the ByteBuffer. - * It should be used with caution as it bypasses the usual safety checks and can lead to undefined behavior - * if used improperly. - * - * @param buffer the ByteBuffer whose address and capacity are to be set - * @param address the memory address to be set - * @param capacity the capacity to be set - * @throws AssertionError if the operation fails due to IllegalAccessException or IllegalArgumentException - */ - public static void setAddressCapacity(ByteBuffer buffer, long address, long capacity) { - int cap = Math.toIntExact(capacity); - try { - ADDRESS.setLong(buffer, address); - CAPACITY.setInt(buffer, cap); - } catch (IllegalAccessException | IllegalArgumentException e) { - throw new AssertionError(e); - } - } -} diff --git a/src/main/java/net/openhft/chronicle/core/util/ByteConsumer.java b/src/main/java/net/openhft/chronicle/core/util/ByteConsumer.java index 43e1b64093..ce62a238a6 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ByteConsumer.java +++ b/src/main/java/net/openhft/chronicle/core/util/ByteConsumer.java @@ -17,10 +17,6 @@ */ package net.openhft.chronicle.core.util; -import org.jetbrains.annotations.NotNull; - -import java.util.Objects; - /** * Represents an operation that accepts a single {@code byte}-valued argument and returns no result. This is the * primitive type specialization of {@link java.util.function.Consumer} for {@code byte}. Unlike most other functional @@ -41,23 +37,4 @@ public interface ByteConsumer { */ void accept(byte value); - /** - * Returns a composed {@code ByteConsumer} that performs, in sequence, this operation followed by the {@code after} - * operation. If performing either operation throws an exception, it is relayed to the caller of the composed - * operation. If performing this operation throws an exception, the {@code after} operation will not be performed. - * - * @param after the operation to perform after this operation - * @return a composed {@code ByteConsumer} that performs in sequence this operation followed by the {@code after} - * operation - * @throws NullPointerException if {@code after} is null - */ - @Deprecated(/* to be removed in x.26 */) - @NotNull - default ByteConsumer andThen(@NotNull ByteConsumer after) { - Objects.requireNonNull(after); - return (byte t) -> { - accept(t); - after.accept(t); - }; - } } diff --git a/src/main/java/net/openhft/chronicle/core/util/CharConsumer.java b/src/main/java/net/openhft/chronicle/core/util/CharConsumer.java index 613cebd176..682090de6b 100644 --- a/src/main/java/net/openhft/chronicle/core/util/CharConsumer.java +++ b/src/main/java/net/openhft/chronicle/core/util/CharConsumer.java @@ -17,10 +17,6 @@ */ package net.openhft.chronicle.core.util; -import org.jetbrains.annotations.NotNull; - -import java.util.Objects; - /** * Represents an operation that accepts a single {@code char}-valued argument and returns no result. This is the * primitive type specialization of {@link java.util.function.Consumer} for {@code char}. Unlike most other functional @@ -41,23 +37,4 @@ public interface CharConsumer { */ void accept(char value); - /** - * Returns a composed {@code CharConsumer} that performs, in sequence, this operation followed by the {@code after} - * operation. If performing either operation throws an exception, it is relayed to the caller of the composed - * operation. If performing this operation throws an exception, the {@code after} operation will not be performed. - * - * @param after the operation to perform after this operation - * @return a composed {@code CharConsumer} that performs in sequence this operation followed by the {@code after} - * operation - * @throws NullPointerException if {@code after} is null - */ - @Deprecated(/* to be removed in x.26 */) - @NotNull - default CharConsumer andThen(@NotNull CharConsumer after) { - Objects.requireNonNull(after); - return (char t) -> { - accept(t); - after.accept(t); - }; - } } diff --git a/src/main/java/net/openhft/chronicle/core/util/FloatConsumer.java b/src/main/java/net/openhft/chronicle/core/util/FloatConsumer.java index 13e47360b6..32387c692c 100644 --- a/src/main/java/net/openhft/chronicle/core/util/FloatConsumer.java +++ b/src/main/java/net/openhft/chronicle/core/util/FloatConsumer.java @@ -17,10 +17,6 @@ */ package net.openhft.chronicle.core.util; -import org.jetbrains.annotations.NotNull; - -import java.util.Objects; - /** * Represents an operation that accepts a single {@code float}-valued argument and returns no result. This is the * primitive type specialization of {@link java.util.function.Consumer} for {@code float}. Unlike most other functional @@ -41,23 +37,4 @@ public interface FloatConsumer { */ void accept(float value); - /** - * Returns a composed {@code FloatConsumer} that performs, in sequence, this operation followed by the {@code after} - * operation. If performing either operation throws an exception, it is relayed to the caller of the composed - * operation. If performing this operation throws an exception, the {@code after} operation will not be performed. - * - * @param after the operation to perform after this operation - * @return a composed {@code FloatConsumer} that performs in sequence this operation followed by the {@code after} - * operation - * @throws NullPointerException if {@code after} is null - */ - @Deprecated(/* to be removed in x.26 */) - @NotNull - default FloatConsumer andThen(@NotNull FloatConsumer after) { - Objects.requireNonNull(after); - return (float t) -> { - accept(t); - after.accept(t); - }; - } } 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 e6e99b1a49..826522f285 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java +++ b/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java @@ -227,11 +227,6 @@ public static void immutable(final Class clazz, final boolean isImmutable) { IMMUTABILITY_MAP.put(clazz, isImmutable ? Immutability.YES : Immutability.NO); } - @Deprecated(/* to be removed x.26 */) - public static void immutabile(final Class clazz, final boolean isImmutable) { - immutable(clazz, isImmutable); - } - /** * Checks if a class is immutable. * diff --git a/src/main/java/net/openhft/chronicle/core/util/ShortConsumer.java b/src/main/java/net/openhft/chronicle/core/util/ShortConsumer.java index c329fa8bab..0d3a11bbc2 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ShortConsumer.java +++ b/src/main/java/net/openhft/chronicle/core/util/ShortConsumer.java @@ -17,10 +17,6 @@ */ package net.openhft.chronicle.core.util; -import org.jetbrains.annotations.NotNull; - -import java.util.Objects; - /** * Represents an operation that accepts a single {@code short}-valued argument and returns no result. This is the * primitive type specialization of {@link java.util.function.Consumer} for {@code short}. Unlike most other functional @@ -41,23 +37,4 @@ public interface ShortConsumer { */ void accept(short value); - /** - * Returns a composed {@code ShortConsumer} that performs, in sequence, this operation followed by the {@code after} - * operation. If performing either operation throws an exception, it is relayed to the caller of the composed - * operation. If performing this operation throws an exception, the {@code after} operation will not be performed. - * - * @param after the operation to perform after this operation - * @return a composed {@code ShortConsumer} that performs in sequence this operation followed by the {@code after} - * operation - * @throws NullPointerException If {@code after} is null - */ - @Deprecated(/* to be removed in x.26 */) - @NotNull - default ShortConsumer andThen(@NotNull ShortConsumer after) { - Objects.requireNonNull(after); - return (short t) -> { - accept(t); - after.accept(t); - }; - } } diff --git a/src/main/java/net/openhft/chronicle/core/util/ThrowingBiConsumer.java b/src/main/java/net/openhft/chronicle/core/util/ThrowingBiConsumer.java index 1c1af11f8a..bdc7c04c9d 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ThrowingBiConsumer.java +++ b/src/main/java/net/openhft/chronicle/core/util/ThrowingBiConsumer.java @@ -18,11 +18,7 @@ package net.openhft.chronicle.core.util; -import net.openhft.chronicle.core.Jvm; import net.openhft.chronicle.core.io.IORuntimeException; -import org.jetbrains.annotations.NotNull; - -import java.util.function.BiConsumer; /** * Represents an operation that accepts two input arguments and returns no @@ -36,16 +32,6 @@ */ @FunctionalInterface public interface ThrowingBiConsumer { - @Deprecated(/* to be removed in x.26 */) - static BiConsumer asConsumer(@NotNull ThrowingBiConsumer function) { - return (in, i2) -> { - try { - function.accept(in, i2); - } catch (Throwable t) { - throw Jvm.rethrow(t); - } - }; - } /** * Performs this operation on the given arguments. diff --git a/src/main/java/net/openhft/chronicle/core/util/ThrowingBiFunction.java b/src/main/java/net/openhft/chronicle/core/util/ThrowingBiFunction.java index 3f200a1737..074581c6dc 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ThrowingBiFunction.java +++ b/src/main/java/net/openhft/chronicle/core/util/ThrowingBiFunction.java @@ -18,11 +18,8 @@ package net.openhft.chronicle.core.util; -import net.openhft.chronicle.core.Jvm; import org.jetbrains.annotations.NotNull; -import java.util.function.BiFunction; - /** * Represents a function that accepts two arguments and produces a result. * This is the two-arity specialization of {@link ThrowingFunction}. @@ -37,16 +34,6 @@ */ @FunctionalInterface public interface ThrowingBiFunction { - @Deprecated(/* to be removed in x.26 */) - static BiFunction asBiFunction(@NotNull ThrowingBiFunction function) { - return (in, i2) -> { - try { - return function.apply(in, i2); - } catch (Throwable t) { - throw Jvm.rethrow(t); - } - }; - } /** * Applies this function to the given arguments. diff --git a/src/main/java/net/openhft/chronicle/core/util/ThrowingConsumer.java b/src/main/java/net/openhft/chronicle/core/util/ThrowingConsumer.java index dca6c20f4f..20fafed7e7 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ThrowingConsumer.java +++ b/src/main/java/net/openhft/chronicle/core/util/ThrowingConsumer.java @@ -18,11 +18,6 @@ package net.openhft.chronicle.core.util; -import net.openhft.chronicle.core.Jvm; -import org.jetbrains.annotations.NotNull; - -import java.util.function.Consumer; - /** *

* Represents an operation that accepts a single input argument and returns no @@ -38,16 +33,6 @@ */ @FunctionalInterface public interface ThrowingConsumer { - @Deprecated(/* to be removed in x.26 */) - static Consumer asConsumer(@NotNull ThrowingConsumer function) { - return in -> { - try { - function.accept(in); - } catch (Throwable t) { - throw Jvm.rethrow(t); - } - }; - } /** * Performs this operation on the given argument. diff --git a/src/main/java/net/openhft/chronicle/core/util/ThrowingIntSupplier.java b/src/main/java/net/openhft/chronicle/core/util/ThrowingIntSupplier.java index d1bbf126f9..c548cf3f5e 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ThrowingIntSupplier.java +++ b/src/main/java/net/openhft/chronicle/core/util/ThrowingIntSupplier.java @@ -19,11 +19,6 @@ package net.openhft.chronicle.core.util; -import net.openhft.chronicle.core.Jvm; -import org.jetbrains.annotations.NotNull; - -import java.util.function.IntSupplier; - /** *

* Represents a supplier of results which might throw an Exception @@ -39,17 +34,6 @@ */ @FunctionalInterface public interface ThrowingIntSupplier { - @Deprecated(/* to be removed in x.26 */) - static IntSupplier asSupplier(@NotNull ThrowingIntSupplier throwingSupplier) { - return () -> { - try { - return throwingSupplier.getAsInt(); - - } catch (Throwable t) { - throw Jvm.rethrow(t); - } - }; - } /** * Gets a result. diff --git a/src/main/java/net/openhft/chronicle/core/util/ThrowingLongSupplier.java b/src/main/java/net/openhft/chronicle/core/util/ThrowingLongSupplier.java index 10e6f4df99..72952b5acc 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ThrowingLongSupplier.java +++ b/src/main/java/net/openhft/chronicle/core/util/ThrowingLongSupplier.java @@ -19,11 +19,6 @@ package net.openhft.chronicle.core.util; -import net.openhft.chronicle.core.Jvm; -import org.jetbrains.annotations.NotNull; - -import java.util.function.LongSupplier; - /** *

* Represents a supplier of results which might throw an Exception @@ -39,17 +34,6 @@ */ @FunctionalInterface public interface ThrowingLongSupplier { - @Deprecated(/* to be removed in x.26 */) - static LongSupplier asSupplier(@NotNull ThrowingLongSupplier throwingSupplier) { - return () -> { - try { - return throwingSupplier.getAsLong(); - - } catch (Throwable t) { - throw Jvm.rethrow(t); - } - }; - } /** * Gets a result. diff --git a/src/main/java/net/openhft/chronicle/core/util/URIEncoder.java b/src/main/java/net/openhft/chronicle/core/util/URIEncoder.java deleted file mode 100644 index d6bf9af3bb..0000000000 --- a/src/main/java/net/openhft/chronicle/core/util/URIEncoder.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package net.openhft.chronicle.core.util; - -import org.jetbrains.annotations.NotNull; - -/** - * simple uri encoder, made from the spec at ... - * Feel free to copy this. I'm not responsible for this code in any way, ever. - * Thanks to Marco and Thomas - * - * @author Daniel Murphy - */ -@Deprecated(/* to be removed in x.26 */) -public final class URIEncoder { - private static final String MARK = "-_.!~*'()\""; - private static final char[] HEX = "0123456789ABCDEF".toCharArray(); - - // Suppresses default constructor, ensuring non-instantiability. - private URIEncoder() { - } - - public static String encodeURI(@NotNull String argString) { - @NotNull StringBuilder uri = new StringBuilder(); - - for (char c : argString.toCharArray()) { - if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || MARK.indexOf(c) != -1) { - uri.append(c); - } else { - appendEscaped(uri, c); - } - } - return uri.toString(); - } - - private static void appendEscaped(@NotNull StringBuilder uri, char c) { - if (c <= 0xFF) { - uri.append("%"); - uri.append(HEX[(c >> 4) & 0xF]); - uri.append(HEX[c & 0xF]); - return; - } - // unicode - uri.append('\\'); - uri.append('u'); - uri.append(HEX[(c >> 12) & 0xF]); - uri.append(HEX[(c >> 8) & 0xF]); - uri.append(HEX[(c >> 4) & 0xF]); - uri.append(HEX[c & 0xF]); - } -} diff --git a/src/main/java/net/openhft/chronicle/core/values/UnsetLongValue.java b/src/main/java/net/openhft/chronicle/core/values/UnsetLongValue.java deleted file mode 100644 index 31a33b7cbb..0000000000 --- a/src/main/java/net/openhft/chronicle/core/values/UnsetLongValue.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2016-2022 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.chronicle.core.values; - -import net.openhft.chronicle.core.io.ClosedIllegalStateException; -import net.openhft.chronicle.core.io.ThreadingIllegalStateException; - -/** - * Represents a long value that ignores attempts to modify it, and always returns the same value. - *

- * This class is useful in scenarios where a LongValue is expected, but modifications should be ignored, - * and a fixed or default value should be returned. This is akin to making the value 'immutable'. - *

- * The value returned by this class is set at construction and cannot be changed thereafter. - * - * @see net.openhft.chronicle.core.values.BooleanValue - * @see net.openhft.chronicle.core.values.ByteValue - * @see net.openhft.chronicle.core.values.CharValue - * @see net.openhft.chronicle.core.values.DoubleValue - * @see net.openhft.chronicle.core.values.FloatValue - * @see net.openhft.chronicle.core.values.IntValue - * @see net.openhft.chronicle.core.values.LongValue - * @see net.openhft.chronicle.core.values.ShortValue - * @see net.openhft.chronicle.core.values.StringValue - * @see net.openhft.chronicle.core.values.LongArrayValues - * @see net.openhft.chronicle.core.values.IntArrayValues - * @see net.openhft.chronicle.core.values.UnsetLongValue - */ -@Deprecated(/* to be removed in x.26 */) -public class UnsetLongValue implements LongValue { - private final long value; - - /** - * Constructs an UnsetLongValue with the specified value. - * - * @param value the value to be set - */ - public UnsetLongValue(long value) { - this.value = value; - } - - /** - * Retrieves the value set at construction. - * - * @return the long value - * @throws ClosedIllegalStateException If the resource has been released or closed. - * @throws ThreadingIllegalStateException If this resource was accessed by multiple threads in an unsafe way - */ - @Override - public long getValue() throws IllegalStateException { - return value; - } - - /** - * This method does not change the value. It is here to fulfill the LongValue interface but has no effect. - * - * @param value the value to set (ignored) - * @throws ClosedIllegalStateException If the resource has been released or closed. - * @throws ThreadingIllegalStateException If this resource was accessed by multiple threads in an unsafe way - */ - @Override - public void setValue(long value) throws IllegalStateException { - // ignored - } - - /** - * Retrieves the volatile value provided as a parameter since internal value modification is ignored. - * - * @param closedValue the volatile value to be retrieved - * @return the closedValue parameter passed to this method - * @throws ClosedIllegalStateException If the resource has been released or closed. - * @throws ThreadingIllegalStateException If this resource was accessed by multiple threads in an unsafe way - */ - @Override - public long getVolatileValue(long closedValue) throws IllegalStateException { - return closedValue; - } - - /** - * Ignores the addition and simply returns the value set at construction. - * - * @param delta the value to be added (ignored) - * @return the long value set at construction - * @throws ClosedIllegalStateException If the resource has been released or closed. - * @throws ThreadingIllegalStateException If this resource was accessed by multiple threads in an unsafe way - */ - @Override - public long addValue(long delta) throws IllegalStateException { - return value; - } - - /** - * Ignores the compare and swap, and simply returns true. - * - * @param expected the expected value (ignored) - * @param value the new value (ignored) - * @return true - * @throws ClosedIllegalStateException If the resource has been released or closed. - * @throws ThreadingIllegalStateException If this resource was accessed by multiple threads in an unsafe way - */ - @Override - public boolean compareAndSwapValue(long expected, long value) throws IllegalStateException { - return true; - } -} diff --git a/src/main/java/net/openhft/chronicle/core/watcher/ClassifyingWatcherListener.java b/src/main/java/net/openhft/chronicle/core/watcher/ClassifyingWatcherListener.java deleted file mode 100644 index a7d2ed5660..0000000000 --- a/src/main/java/net/openhft/chronicle/core/watcher/ClassifyingWatcherListener.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.openhft.chronicle.core.watcher; - -import net.openhft.chronicle.core.Jvm; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -import java.util.concurrent.CopyOnWriteArraySet; - -@Deprecated(/* to be removed x.26 */) -public class ClassifyingWatcherListener implements WatcherListener { - final Set classifiers = new CopyOnWriteArraySet<>(); - final Map fileManagerMap = new TreeMap<>(); - - @Override - public void onExists(String base, String filename, Boolean modified) { - Path path = Paths.get(base, filename); - if (fileManagerMap.containsKey(path)) - return; - for (FileClassifier classifier : classifiers) { - FileManager manager = classifier.classify(base, filename); - if (manager != null) { - Jvm.warn().on(getClass(), "File " + base + " " + filename + " classified as " + manager); - fileManagerMap.put(path, manager); - manager.start(); - } - } - } - - @Override - public void onRemoved(String base, String filename) { - Path path = Paths.get(base, filename); - FileManager info = fileManagerMap.remove(path); - if (info != null) - info.stop(); - } - - public void addClassifier(FileClassifier fileClassifier) { - classifiers.add(fileClassifier); - } -} diff --git a/src/main/java/net/openhft/chronicle/core/watcher/FileClassifier.java b/src/main/java/net/openhft/chronicle/core/watcher/FileClassifier.java deleted file mode 100644 index ac1049d582..0000000000 --- a/src/main/java/net/openhft/chronicle/core/watcher/FileClassifier.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.openhft.chronicle.core.watcher; - -@Deprecated(/* to be removed x.26 */) -public interface FileClassifier { - FileManager classify(String base, String relative); -} diff --git a/src/main/java/net/openhft/chronicle/core/watcher/FileManager.java b/src/main/java/net/openhft/chronicle/core/watcher/FileManager.java deleted file mode 100644 index 459c26b0fa..0000000000 --- a/src/main/java/net/openhft/chronicle/core/watcher/FileManager.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.openhft.chronicle.core.watcher; - -@Deprecated(/* to be removed x.26 */) -public interface FileManager { - void start(); - - void stop(); -} diff --git a/src/main/java/net/openhft/chronicle/core/watcher/FileSystemWatcher.java b/src/main/java/net/openhft/chronicle/core/watcher/FileSystemWatcher.java deleted file mode 100644 index c88d54ec66..0000000000 --- a/src/main/java/net/openhft/chronicle/core/watcher/FileSystemWatcher.java +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.openhft.chronicle.core.watcher; - -import net.openhft.chronicle.core.Jvm; -import net.openhft.chronicle.core.OS; -import net.openhft.chronicle.core.io.Closeable; - -import java.io.IOException; -import java.nio.file.*; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.*; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.LinkedBlockingQueue; - -import static java.nio.file.StandardWatchEventKinds.*; - -@Deprecated(/* to be removed x.26 */) -public class FileSystemWatcher { - private final WatchService watchService; - // shared - private final Map watchKeyToPathMap = new ConcurrentHashMap<>(); - private final Set watchKeysToRemove = new CopyOnWriteArraySet<>(); - private final BlockingQueue listenersToAdd = new LinkedBlockingQueue<>(); - private volatile boolean running = true; - // only used by the watcher thread. - private final List listeners = new ArrayList<>(); - private final Thread thread = new Thread(this::run, "watcher"); - - public FileSystemWatcher() throws IOException { - watchService = FileSystems.getDefault().newWatchService(); - } - - private static String p(String path) { - return OS.isWindows() ? path.replace('\\', '/') : path; - } - - public void addPath(String directory) { - addPath(directory, ""); - } - - public void addPath(String base, String relative) { - Path base0 = Paths.get(base); - Path base2 = base0.resolve(relative); - if (Files.isDirectory(base2)) { - try { - Files.walkFileTree(base2, Collections.singleton(FileVisitOption.FOLLOW_LINKS), 8, new FileVisitor() { - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { - return visitFile(dir, attrs); - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { - addPath0(base0, file); - - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFileFailed(Path file, IOException exc) { - warnOnException(exc, base); - - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) { - warnOnException(exc, base); - - return FileVisitResult.CONTINUE; - } - }); - } catch (IOException e) { - warnOnException(e, base); - } - try { - bootstrapPath(listeners, base, relative); - } catch (IOException e) { - warnOnException(e, base); - } - } - } - - void addPath0(Path base, Path full) { - if (Files.isDirectory(full)) { - try { - String basePath = base.toString(); - watchKeyToPathMap.put(full.register( - watchService, - StandardWatchEventKinds.ENTRY_CREATE, - StandardWatchEventKinds.ENTRY_DELETE, - StandardWatchEventKinds.ENTRY_MODIFY), - new PathInfo(basePath, full.toString())); - } catch (IOException e) { - Jvm.warn().on(FileSystemWatcher.class, "Couldn't add path " + full, e); - } - } - } - - public void addListener(WatcherListener listener) { - listenersToAdd.add(listener); - thread.interrupt(); - } - - private void removePath(String filename) { - watchKeyToPathMap.keySet().stream() - .filter(k -> matches(watchKeyToPathMap.get(k), filename)) - .forEach(wk -> { - watchKeysToRemove.add(wk); - wk.cancel(); - }); - } - - private boolean matches(PathInfo path, String filename) { - String s = path.full; - return s.equals(filename) || s.startsWith(filename + "/"); - } - - void run() { - WatchKey key; - while (running) { - List list = new ArrayList<>(); - listenersToAdd.drainTo(list); - bootstrap(list); - listeners.addAll(list); - - try { - if ((key = watchService.take()) == null) - break; - PathInfo base = watchKeyToPathMap.get(key); - for (WatchEvent event : key.pollEvents()) { - for (Iterator iterator = listeners.iterator(); iterator.hasNext(); ) { - WatcherListener listener = iterator.next(); - try { - if (event.kind() == OVERFLOW) { - Jvm.warn().on(getClass(), "Overflow on watcher events for " + base); - bootstrap(listeners); - continue; - } - - @SuppressWarnings("unchecked") - WatchEvent event2 = (WatchEvent) event; - String fullRelative = (base.relativePath.isEmpty() ? "" : base.relativePath + "/") + event2.context(); - String filename = base.basePath + "/" + fullRelative; - if (event.kind() == ENTRY_CREATE) { - listener.onExists(p(base.basePath), p(fullRelative), false); - addPath(base.basePath, fullRelative); - } else if (event.kind() == ENTRY_MODIFY) { - listener.onExists(p(base.basePath), p(fullRelative), true); - } else if (event.kind() == ENTRY_DELETE) { - listener.onRemoved(p(base.basePath), p(fullRelative)); - removePath(filename); - } - } catch (IllegalStateException ise) { - iterator.remove(); - } - } - } - key.reset(); - if (watchKeysToRemove.contains(key)) { - watchKeyToPathMap.remove(key); - watchKeysToRemove.remove(key); - } - } catch (InterruptedException expected) { - Thread.currentThread().interrupt(); - } - } - } - - private void bootstrap(List list) { - for (PathInfo pathInfo : watchKeyToPathMap.values()) { - try { - bootstrapPath(list, pathInfo.basePath, ""); - } catch (IOException e) { - Jvm.warn().on(getClass(), "Failed to walk " + pathInfo, e); - } - } - } - - private void bootstrapPath(List list, String base, String relative) throws IOException { - Path full = Paths.get(base).resolve(relative); - - Files.walkFileTree(full, Collections.singleton(FileVisitOption.FOLLOW_LINKS), 8, new FileVisitor() { - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { - return visitFile(dir, attrs); - } - - @Override - public FileVisitResult visitFile(Path p, BasicFileAttributes attrs) throws IOException { - for (Iterator iterator = list.iterator(); iterator.hasNext(); ) { - WatcherListener listener = iterator.next(); - String pToString = p.toString(); - if (pToString.equals(full.toString())) - continue; - String filename = pToString.substring(base.length() + 1); - try { - listener.onExists(p(base), p(filename), null); - } catch (IllegalStateException ise) { - iterator.remove(); - } - } - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { - warnOnException(exc, base); - - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { - warnOnException(exc, base); - - return FileVisitResult.CONTINUE; - } - }); - } - - public void start() { - thread.start(); - } - - public void stop() { - running = false; - thread.interrupt(); - try { - thread.join(1000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - Closeable.closeQuietly(watchService); - } - - private void warnOnException(IOException exc, String base) { - if (exc != null) { - Jvm.warn().on(FileSystemWatcher.class, "Couldn't walk path " + base, exc); - } - } - - static class PathInfo { - final String basePath; - final String full; - final String relativePath; - - public PathInfo(String basePath, String full) { - this.basePath = basePath; - this.full = full; - this.relativePath = basePath.equals(full) ? "" : full.substring(basePath.length() + 1); - } - } -} diff --git a/src/main/java/net/openhft/chronicle/core/watcher/JMXFileManager.java b/src/main/java/net/openhft/chronicle/core/watcher/JMXFileManager.java deleted file mode 100644 index f718d2e79c..0000000000 --- a/src/main/java/net/openhft/chronicle/core/watcher/JMXFileManager.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.openhft.chronicle.core.watcher; - -import net.openhft.chronicle.core.Jvm; - -import javax.management.*; -import java.lang.management.ManagementFactory; - -@Deprecated(/* to be removed x.26 */) -public abstract class JMXFileManager implements FileManager, JMXFileManagerMBean { - protected static final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); - protected final String basePath; - protected final String relativePath; - private final ObjectName objectName; - - protected JMXFileManager(String basePath, String relativePath) { - this.basePath = basePath; - this.relativePath = relativePath; - try { - objectName = new ObjectName(jmxPath() + ":type=" + type() + ",name=" + relativePath); - } catch (MalformedObjectNameException e) { - throw new AssertionError(e); - } - } - - protected String type() { - return "basic"; - } - - protected String jmxPath() { - return "chronicle"; - } - - public String getBasePath() { - return basePath; - } - - public String getRelativePath() { - return relativePath; - } - - @Override - public void start() { - try { - mbs.registerMBean(this, objectName); - } catch (Exception e) { - Jvm.warn().on(getClass(), "Unable to register " + this, e); - } - } - - @Override - public void stop() { - try { - mbs.unregisterMBean(objectName); - } catch (InstanceNotFoundException | MBeanRegistrationException e) { - Jvm.warn().on(getClass(), "Unable to unregister " + this, e); - } - } -} diff --git a/src/main/java/net/openhft/chronicle/core/watcher/JMXFileManagerMBean.java b/src/main/java/net/openhft/chronicle/core/watcher/JMXFileManagerMBean.java deleted file mode 100644 index 7a137ec9fb..0000000000 --- a/src/main/java/net/openhft/chronicle/core/watcher/JMXFileManagerMBean.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.openhft.chronicle.core.watcher; - -@Deprecated(/* to be removed x.26 */) -public interface JMXFileManagerMBean { - String getBasePath(); - - String getRelativePath(); -} diff --git a/src/main/java/net/openhft/chronicle/core/watcher/PlainFileClassifier.java b/src/main/java/net/openhft/chronicle/core/watcher/PlainFileClassifier.java deleted file mode 100644 index dd5f308327..0000000000 --- a/src/main/java/net/openhft/chronicle/core/watcher/PlainFileClassifier.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.openhft.chronicle.core.watcher; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -@Deprecated(/* to be removed x.26 */) -public class PlainFileClassifier implements FileClassifier { - @Override - public FileManager classify(String base, String relative) { - Path path = Paths.get(base, relative); - if (Files.isRegularFile(path)) { - return new PlainFileManager(base, relative, path); - } - return null; - } -} diff --git a/src/main/java/net/openhft/chronicle/core/watcher/PlainFileManager.java b/src/main/java/net/openhft/chronicle/core/watcher/PlainFileManager.java deleted file mode 100644 index 90539699ae..0000000000 --- a/src/main/java/net/openhft/chronicle/core/watcher/PlainFileManager.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.openhft.chronicle.core.watcher; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -@Deprecated(/* to be removed x.26 */) -class PlainFileManager extends JMXFileManager implements PlainFileManagerMBean { - private final Path path; - - public PlainFileManager(String base, String relative, Path path) { - super(base, relative); - this.path = path; - } - - @Override - protected String type() { - return "files"; - } - - @Override - public String getFileSize() { - try { - long size = Files.size(path); - if (size < 2 << 10) - return size + " B"; - if (size < 2 << 20) - return (size * 10L >> 10) / 10.0 + " KiB"; - return (size * 10L >> 20) / 10.0 + " MiB"; - } catch (IOException e) { - return e.toString(); - } - } - - @Override - public String getContentType() { - try { - return Files.probeContentType(path); - } catch (IOException e) { - return "Unknown"; - } - } -} diff --git a/src/main/java/net/openhft/chronicle/core/watcher/PlainFileManagerMBean.java b/src/main/java/net/openhft/chronicle/core/watcher/PlainFileManagerMBean.java deleted file mode 100644 index 0a15911224..0000000000 --- a/src/main/java/net/openhft/chronicle/core/watcher/PlainFileManagerMBean.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.openhft.chronicle.core.watcher; - -@SuppressWarnings("unused") -@Deprecated(/* to be removed x.26 */) -public interface PlainFileManagerMBean { - String getFileSize(); - - String getContentType(); -} diff --git a/src/main/java/net/openhft/chronicle/core/watcher/WatcherListener.java b/src/main/java/net/openhft/chronicle/core/watcher/WatcherListener.java deleted file mode 100644 index 2916408e1a..0000000000 --- a/src/main/java/net/openhft/chronicle/core/watcher/WatcherListener.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.openhft.chronicle.core.watcher; - -@Deprecated(/* to be removed x.26 */) -public interface WatcherListener { - /** - * When a file or directory is added or modified. - * - * @param filename of the - * @param modified false is created, true if modified, null if bootstrapping. - * @throws IllegalStateException when this listener is no longer valid - */ - void onExists(String base, String filename, Boolean modified) throws IllegalStateException; - - /** - * Notify that a file or directory was removed. - * - * @param filename removed. - * @throws IllegalStateException when this listener is no longer valid - */ - void onRemoved(String base, String filename) throws IllegalStateException; -} diff --git a/src/test/java/net/openhft/chronicle/core/MemoryTest.java b/src/test/java/net/openhft/chronicle/core/MemoryTest.java index ea799de6c0..02e70b0e08 100644 --- a/src/test/java/net/openhft/chronicle/core/MemoryTest.java +++ b/src/test/java/net/openhft/chronicle/core/MemoryTest.java @@ -27,13 +27,6 @@ public class MemoryTest extends CoreTestCommon { - @Test - public void testHeapUsed() { - final long heapUsed = OS.memory().heapUsed(); - System.out.println("heap used: " + heapUsed); - assertTrue(heapUsed > 0); - } - @Test public void testReadme() { @Nullable Memory memory = OS.memory(); diff --git a/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java b/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java index 3455ee7b56..61c77b1023 100644 --- a/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java +++ b/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java @@ -1,8 +1,9 @@ package net.openhft.chronicle.core.announcer; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; -import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; class AnnouncerTest { @@ -14,11 +15,11 @@ void testAnnounceWithValidArguments() { @Test void testAnnounceWithNullGroupId() { - assertThrows(NullPointerException.class, () -> Announcer.announce(null, "chronicle-queue")); + assertThrows(IllegalArgumentException.class, () -> Announcer.announce(null, "chronicle-queue")); } @Test void testAnnounceWithNullArtifactId() { - assertThrows(NullPointerException.class, () -> Announcer.announce("net.openhft", null)); + assertThrows(IllegalArgumentException.class, () -> Announcer.announce("net.openhft", null)); } } diff --git a/src/test/java/net/openhft/chronicle/core/io/WgetTest.java b/src/test/java/net/openhft/chronicle/core/io/WgetTest.java index 21d41f5ad3..7ca3f22246 100644 --- a/src/test/java/net/openhft/chronicle/core/io/WgetTest.java +++ b/src/test/java/net/openhft/chronicle/core/io/WgetTest.java @@ -1,11 +1,11 @@ package net.openhft.chronicle.core.io; -import net.openhft.chronicle.core.io.Wget; import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; public class WgetTest { @@ -19,16 +19,6 @@ public void testHttpGetRequest() throws IOException { assertFalse(sb.toString().isEmpty()); } - @Test - public void testDeprecatedMethod() throws IOException { - String testUrl = "http://example.com"; - - CharSequence result = Wget.url(testUrl); - - assertNotNull(result); - assertFalse(result.toString().isEmpty()); - } - @Test public void testHttpGetRequestWithInvalidUrl() { String invalidUrl = "http://invalid.url"; diff --git a/src/test/java/net/openhft/chronicle/core/pool/StringBuilderPoolTest.java b/src/test/java/net/openhft/chronicle/core/pool/StringBuilderPoolTest.java deleted file mode 100644 index 715aa60f6f..0000000000 --- a/src/test/java/net/openhft/chronicle/core/pool/StringBuilderPoolTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package net.openhft.chronicle.core.pool; - -import net.openhft.chronicle.core.pool.StringBuilderPool; -import net.openhft.chronicle.core.scoped.ScopedResourcePool; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class StringBuilderPoolTest { - - @Test - public void testAcquireStringBuilder() { - StringBuilderPool pool = new StringBuilderPool(); - StringBuilder sb1 = pool.acquireStringBuilder(); - assertNotNull(sb1); - assertEquals(0, sb1.length()); - assertEquals(128, sb1.capacity()); - - sb1.append("test"); - - StringBuilder sb2 = pool.acquireStringBuilder(); - assertSame(sb1, sb2); - assertEquals(0, sb2.length()); - } -} diff --git a/src/test/java/net/openhft/chronicle/core/time/PosixTimeProviderTest.java b/src/test/java/net/openhft/chronicle/core/time/PosixTimeProviderTest.java index 42c3240ac2..400a5a1d9c 100644 --- a/src/test/java/net/openhft/chronicle/core/time/PosixTimeProviderTest.java +++ b/src/test/java/net/openhft/chronicle/core/time/PosixTimeProviderTest.java @@ -28,8 +28,6 @@ import org.jetbrains.annotations.NotNull; import org.junit.Test; -import java.util.concurrent.TimeUnit; - import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; @@ -117,12 +115,10 @@ public void currentTime() throws IllegalStateException { assumeTrue(!OS.isMacOSX()); TimeProvider tp = PosixTimeProvider.INSTANCE; for (int i = 3; i >= 0; i--) { - long time1 = tp.currentTime(TimeUnit.SECONDS); long time2 = tp.currentTimeMillis(); long time3 = tp.currentTimeMicros(); long time4 = tp.currentTimeNanos(); try { - assertBetween(time2 / 1000, time1, time2 / 1000 + 2); assertBetween(time3 / 1000 - 1, time2, time3 / 1000 + 20); assertBetween(time4 / 1000 - 100, time3, time4 / 1000 + 2_000); } catch (AssertionError ae) { diff --git a/src/test/java/net/openhft/chronicle/core/time/RunningMinimumTest.java b/src/test/java/net/openhft/chronicle/core/time/RunningMinimumTest.java deleted file mode 100644 index ff68ea21de..0000000000 --- a/src/test/java/net/openhft/chronicle/core/time/RunningMinimumTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package net.openhft.chronicle.core.time; - -import net.openhft.chronicle.core.CoreTestCommon; -import org.jetbrains.annotations.NotNull; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * User: peter.lawrey - * Date: 05/08/13 - * Time: 19:14 - */ -public class RunningMinimumTest extends CoreTestCommon { - @Test - public void testSample() { - for (int k = 0; k < 1000; k++) { - for (long delta : new long[]{0, Integer.MIN_VALUE, Integer.MAX_VALUE}) { - @NotNull RunningMinimum rm = new RunningMinimum(50 * 1000); - int j; - for (j = 0; j < 50 * 1000000; j += 1000000) { - long startTime = System.nanoTime() + j; - long endTime = System.nanoTime() + j + delta + (long) (Math.pow(10 * 1000, Math.random()) * 1000); - rm.sample(startTime, endTime); - } - assertEquals("delta=" + delta, delta, rm.minimum(), 40 * 1000); - } - } - } - - @Test - public void testVanillaDiff() { - @NotNull VanillaDifferencer vd = new VanillaDifferencer(); - assertEquals(100, vd.sample(123400, 123500)); - } -} diff --git a/src/test/java/net/openhft/chronicle/core/time/SystemTimeProviderTest.java b/src/test/java/net/openhft/chronicle/core/time/SystemTimeProviderTest.java index bff295ea80..9f9ac29bc5 100644 --- a/src/test/java/net/openhft/chronicle/core/time/SystemTimeProviderTest.java +++ b/src/test/java/net/openhft/chronicle/core/time/SystemTimeProviderTest.java @@ -27,7 +27,6 @@ import org.junit.Test; import java.security.SecureRandom; -import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertTrue; @@ -109,12 +108,10 @@ private void doCurrentTimeMicros() throws IllegalStateException { public void currentTime() throws IllegalStateException { for (int i = 3; i >= 0; i--) { TimeProvider tp = SystemTimeProvider.INSTANCE; - long time1 = tp.currentTime(TimeUnit.SECONDS); long time2 = tp.currentTimeMillis(); long time3 = tp.currentTimeMicros(); long time4 = tp.currentTimeNanos(); try { - assertBetween(time2 / 1000, time1, time2 / 1000 + 2); assertBetween(time3 / 1000 - 8, time2, time3 / 1000 + 20); assertBetween(time4 / 1000 - 100, time3, time4 / 1000 + 2_000); } catch (AssertionError ae) { diff --git a/src/test/java/net/openhft/chronicle/core/util/AnnotationsTest.java b/src/test/java/net/openhft/chronicle/core/util/AnnotationsTest.java deleted file mode 100644 index 7b5ae98911..0000000000 --- a/src/test/java/net/openhft/chronicle/core/util/AnnotationsTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package net.openhft.chronicle.core.util; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.Method; - -import static org.junit.Assert.*; - -@RunWith(MockitoJUnitRunner.class) -public class AnnotationsTest { - - @Retention(RetentionPolicy.RUNTIME) - public @interface TestAnnotation { - } - - public interface TestInterface { - @TestAnnotation - void interfaceMethod(); - } - - public static class SuperClass { - public void superMethod() { - } - } - - public static class TestClass extends SuperClass implements TestInterface { - public void testMethod() { - } - - @Override - public void interfaceMethod() { - } - } - - @Test - public void findAnnotation_OnMethod() { - TestAnnotation annotation = Annotations.findAnnotation(TestAnnotation.class, TestClass.class, "interfaceMethod", new Class[0]); - - assertNotNull(annotation); - } - - @Test - public void findAnnotation_NotPresent() { - TestAnnotation annotation = Annotations.findAnnotation(TestAnnotation.class, TestClass.class, "testMethod", new Class[0]); - - assertNull(annotation); - } - - @Test - public void getAnnotation_DirectlyOnMethod() throws NoSuchMethodException { - Method method = TestClass.class.getMethod("interfaceMethod"); - TestAnnotation annotation = Annotations.getAnnotation(method, TestAnnotation.class); - - assertNotNull(annotation); - } - - @Test - public void getAnnotation_NotPresent() throws NoSuchMethodException { - Method method = TestClass.class.getMethod("testMethod"); - TestAnnotation annotation = Annotations.getAnnotation(method, TestAnnotation.class); - - assertNull(annotation); - } -} diff --git a/src/test/java/net/openhft/chronicle/core/util/ByteConsumerTest.java b/src/test/java/net/openhft/chronicle/core/util/ByteConsumerTest.java index c0f4d13969..d3eb02bdcc 100644 --- a/src/test/java/net/openhft/chronicle/core/util/ByteConsumerTest.java +++ b/src/test/java/net/openhft/chronicle/core/util/ByteConsumerTest.java @@ -1,9 +1,8 @@ package net.openhft.chronicle.core.util; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.anyByte; -import static org.mockito.Mockito.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; class ByteConsumerTest { @@ -17,34 +16,4 @@ void acceptShouldPerformOperation() { assertEquals((byte) 10, resultContainer[0]); } - @Test - void andThenShouldPerformBothOperationsInSequence() { - byte[] resultContainer = new byte[2]; - ByteConsumer firstConsumer = value -> resultContainer[0] = value; - ByteConsumer secondConsumer = value -> resultContainer[1] = (byte) (value + 10); - - ByteConsumer combinedConsumer = firstConsumer.andThen(secondConsumer); - - combinedConsumer.accept((byte) 5); - - assertEquals((byte) 5, resultContainer[0]); - assertEquals((byte) 15, resultContainer[1]); - } - - @Test - void andThenShouldThrowNullPointerExceptionIfAfterIsNull() { - ByteConsumer consumer = value -> { /* Do something */ }; - assertThrows(NullPointerException.class, () -> consumer.andThen(null)); - } - - @Test - void andThenShouldNotPerformSecondOperationIfFirstThrowsException() { - ByteConsumer firstConsumer = value -> { throw new RuntimeException(); }; - ByteConsumer secondConsumer = mock(ByteConsumer.class); - - ByteConsumer combinedConsumer = firstConsumer.andThen(secondConsumer); - - assertThrows(RuntimeException.class, () -> combinedConsumer.accept((byte) 5)); - verify(secondConsumer, never()).accept(anyByte()); - } } diff --git a/src/test/java/net/openhft/chronicle/core/util/ObjectUtilsTest.java b/src/test/java/net/openhft/chronicle/core/util/ObjectUtilsTest.java index a47e7ef02c..98f0a1e6ee 100644 --- a/src/test/java/net/openhft/chronicle/core/util/ObjectUtilsTest.java +++ b/src/test/java/net/openhft/chronicle/core/util/ObjectUtilsTest.java @@ -146,13 +146,6 @@ public void immutableShouldRegisterImmutability() { // Verify the immutability status is correctly set (requires a way to check the status) } - @Test - public void deprecatedImmutabileShouldStillFunction() { - Class testClass = RegularClass.class; - ObjectUtils.immutabile(testClass, true); - // Verify the immutability status is correctly set as with immutable method - } - @Test public void caseIgnoreLookupShouldCreateCorrectMap() { // Assuming MyEnum is an enum class diff --git a/src/test/java/net/openhft/chronicle/core/util/ThrowingConsumerTest.java b/src/test/java/net/openhft/chronicle/core/util/ThrowingConsumerTest.java deleted file mode 100644 index a5d11c55b0..0000000000 --- a/src/test/java/net/openhft/chronicle/core/util/ThrowingConsumerTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.chronicle.core.util; - -import net.openhft.chronicle.core.CoreTestCommon; -import org.jetbrains.annotations.NotNull; -import org.junit.Test; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; -import java.util.function.Consumer; - -import static org.junit.Assert.fail; - -public class ThrowingConsumerTest extends CoreTestCommon { - @Test - public void asConsumer() throws Exception { - @NotNull Consumer sc = ThrowingConsumer.asConsumer(s -> { - try (@NotNull BufferedReader br = new BufferedReader(new FileReader(s))) { - System.out.println(br.readLine()); - } - }); - - try { - sc.accept("doesn't exists"); - fail(); - if (false) throw new IOException(); - } catch (IOException e) { - // expected - } - } -} diff --git a/src/test/java/net/openhft/chronicle/core/util/URIEncoderTest.java b/src/test/java/net/openhft/chronicle/core/util/URIEncoderTest.java deleted file mode 100644 index a3c77432e8..0000000000 --- a/src/test/java/net/openhft/chronicle/core/util/URIEncoderTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.chronicle.core.util; - -import net.openhft.chronicle.core.CoreTestCommon; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class URIEncoderTest extends CoreTestCommon { - @Test - public void encodeURI() throws Exception { - assertEquals("~%25", URIEncoder.encodeURI("~%")); - } -} diff --git a/src/test/java/net/openhft/chronicle/core/watcher/FileSystemWatcherMain.java b/src/test/java/net/openhft/chronicle/core/watcher/FileSystemWatcherMain.java deleted file mode 100644 index 6f48a1aa20..0000000000 --- a/src/test/java/net/openhft/chronicle/core/watcher/FileSystemWatcherMain.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2016-2020 chronicle.software - */ - -package net.openhft.chronicle.core.watcher; - -import java.io.File; -import java.io.IOException; - -public class FileSystemWatcherMain { - public static void main(String[] args) throws IOException, InterruptedException { - FileSystemWatcher fsw = new FileSystemWatcher(); - String absolutePath = new File(".").getAbsolutePath(); - System.out.println("Watching " + absolutePath); - fsw.addPath(absolutePath); - ClassifyingWatcherListener listener = new ClassifyingWatcherListener(); - listener.addClassifier(new PlainFileClassifier()); - fsw.addListener(listener); - fsw.start(); - Thread.currentThread().join(); - } -} diff --git a/src/test/java/net/openhft/chronicle/core/watcher/FileSystemWatcherTest.java b/src/test/java/net/openhft/chronicle/core/watcher/FileSystemWatcherTest.java deleted file mode 100644 index ec932bbc22..0000000000 --- a/src/test/java/net/openhft/chronicle/core/watcher/FileSystemWatcherTest.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2016-2020 chronicle.software - */ - -package net.openhft.chronicle.core.watcher; - -import net.openhft.chronicle.core.CoreTestCommon; -import net.openhft.chronicle.core.Jvm; -import net.openhft.chronicle.core.OS; -import net.openhft.chronicle.core.io.IOTools; -import net.openhft.chronicle.core.util.Time; -import org.junit.*; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Map; -import java.util.SortedMap; -import java.util.concurrent.ConcurrentSkipListMap; -import java.util.stream.Collectors; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeFalse; - -@Ignore(/* flaky test for deprecated, never used code */) -public class FileSystemWatcherTest extends CoreTestCommon { - static String base = OS.getTarget() + "/FileSystemWatcherTest-" + Time.uniqueId(); - - @Before - public void setup() throws IOException { - tearDown(); - Files.createDirectories(Paths.get(base)); - } - - @After - public void tearDown() { - IOTools.deleteDirWithFiles(base); - } - - @Test - public void bootstrapAndUpdate() throws IOException { - assumeFalse(Jvm.isArm()); - - /* - This test fails on Windows and may also fail on MmcOS. - - The issue appears to be that the NIO file-watching service is very platform dependent. - - Eg. Linux does not produce events when a directory-entry is updated, WIndows does. - Eg. Windows does not produce events when a file is opened for write - Linux does. - - This makes the results of this particular test heavily dependent on the platform. - - A practical solution would be to modify the test and framework so that only major events are generated (file created, modified etc) and filter out the unhelpful events (if possible ;-) - - In the meantime, this test has been ignored for Windows. - */ - Assume.assumeTrue(OS.isLinux()); - - SortedMap events = new ConcurrentSkipListMap<>(); - - WatcherListener listener = new WatcherListener() { - @Override - public void onExists(String base, String filename, Boolean modified) { - events.put(filename, "modified: " + modified); - } - - @Override - public void onRemoved(String base, String filename) { - events.put(filename, "removed: true"); - } - }; - assertTrue(new File(base + "/dir1").mkdir()); - assertTrue(new File(base + "/dir2").mkdir()); - assertTrue(new File(base + "/dir1/file11").createNewFile()); - assertTrue(new File(base + "/dir1/file12").createNewFile()); - assertTrue(new File(base + "/dir2/file20").createNewFile()); - - FileSystemWatcher watcher = new FileSystemWatcher(); - watcher.addPath(base); - watcher.start(); - watcher.addListener(listener); - retryAssertEquals("dir1=modified: null\n" + - "dir1/file11=modified: null\n" + - "dir1/file12=modified: null\n" + - "dir2=modified: null\n" + - "dir2/file20=modified: null", events); - try (FileWriter fw = new FileWriter(base + "/dir1/file11")) { - } - assertTrue(new File(base + "/dir2/file20").delete()); - assertTrue(new File(base + "/dir2/file21").createNewFile()); - assertTrue(new File(base + "/dir3/dir30").mkdirs()); - assertTrue(new File(base + "/dir3/dir30/file301").createNewFile()); - - retryAssertEquals( - "dir1=modified: null\n" + - "dir1/file11=modified: true\n" + - "dir1/file12=modified: null\n" + - "dir2=modified: null\n" + - "dir2/file20=removed: true\n" + - "dir2/file21=modified: false\n" + - "dir3=modified: false\n" + - "dir3/dir30=modified: null\n" + - "dir3/dir30/file301=modified: null", events); - - IOTools.deleteDirWithFiles(base + "/dir2", 2); - - retryAssertEquals( - "dir1=modified: null\n" + - "dir1/file11=modified: true\n" + - "dir1/file12=modified: null\n" + - "dir2=removed: true\n" + - "dir2/file20=removed: true\n" + - "dir2/file21=removed: true\n" + - "dir3=modified: false\n" + - "dir3/dir30=modified: null\n" + - "dir3/dir30/file301=modified: null", events); - - watcher.stop(); - } - - private void retryAssertEquals(String expected, SortedMap events) { - for (int i = Jvm.isDebug() ? 500 : 100; ; i--) { - try { - Jvm.pause(20); - assertEquals(expected, - events.entrySet().stream() - .map(Map.Entry::toString) - .collect(Collectors.joining("\n"))); - break; - } catch (AssertionError ae) { - if (i <= 0) - throw ae; - } - } - } -} From eae1252f748778fdc2da807e528bdaa44bb89b06 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 28 Mar 2024 12:21:51 +0000 Subject: [PATCH 04/43] restore UnsafeMemory.copyMemory --- .../openhft/chronicle/core/UnsafeMemory.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java index e7226b8815..95a5b2ec9d 100644 --- a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java +++ b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java @@ -1078,6 +1078,29 @@ public void copyMemory(long srcAddress, long destAddress, long length) { } } + /** + * Copies memory from a byte array to an object. + * + * @param src source byte array. + * @param srcOffset offset of the source array from where to start copying. + * @param dest destination object. + * @param destOffset offset of the destination object from where to place the copied memory. + * @param length the length of memory to copy. + */ + @Deprecated(/* for removal in x.26 */) + public void copyMemory(byte[] src, int srcOffset, @Nullable Object dest, long destOffset, int length) { + assert SKIP_ASSERTIONS || nonNull(src); + assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), srcOffset); + assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), destOffset); + assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), length); + + if (dest instanceof byte[]) { + copyMemory(src, srcOffset, (byte[]) dest, Math.toIntExact(destOffset - ARRAY_BYTE_BASE_OFFSET), length); + } else { + copyMemoryLoop(src, ARRAY_BYTE_BASE_OFFSET + srcOffset, dest, destOffset, length); + } + } + /** * Copies memory from one byte array to another. * From e1eaebe1c2cd063689f8b174f13a10f3b7a91e3b Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 28 Mar 2024 13:42:12 +0000 Subject: [PATCH 05/43] Remove se.eris.notnull.instrument --- benchmarks/pom.xml | 2 +- pom.xml | 39 +------------------ .../internal/pom/InternalPomProperties.java | 3 ++ .../core/announcer/AnnouncerTest.java | 4 +- 4 files changed, 7 insertions(+), 41 deletions(-) diff --git a/benchmarks/pom.xml b/benchmarks/pom.xml index 1cfa6d6771..ad3f9f6d64 100644 --- a/benchmarks/pom.xml +++ b/benchmarks/pom.xml @@ -49,7 +49,7 @@ net.openhft chronicle-bom - 2.25ea-SNAPSHOT + 2.26ea-SNAPSHOT pom import diff --git a/pom.xml b/pom.xml index 08fe410744..a6c2ffcc47 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ net.openhft java-parent-pom 1.25.4 - + chronicle-core 2.26ea0-SNAPSHOT @@ -165,22 +165,6 @@ - - - se.eris - notnull-instrumenter-maven-plugin - 1.1.1 - - - - Ignore - - - com.github.ekryd.sortpom sortpom-maven-plugin @@ -335,27 +319,6 @@ - - org.apache.maven.plugins maven-install-plugin diff --git a/src/main/java/net/openhft/chronicle/core/internal/pom/InternalPomProperties.java b/src/main/java/net/openhft/chronicle/core/internal/pom/InternalPomProperties.java index 3fb16b3ede..4352aa122b 100644 --- a/src/main/java/net/openhft/chronicle/core/internal/pom/InternalPomProperties.java +++ b/src/main/java/net/openhft/chronicle/core/internal/pom/InternalPomProperties.java @@ -18,6 +18,7 @@ package net.openhft.chronicle.core.internal.pom; +import net.openhft.chronicle.core.util.ObjectUtils; import org.jetbrains.annotations.NotNull; import java.io.InputStream; @@ -35,6 +36,8 @@ private InternalPomProperties() { @NotNull public static Properties create(@NotNull final String groupId, @NotNull final String artifactId) { + ObjectUtils.requireNonNull(groupId); + ObjectUtils.requireNonNull(artifactId); final Properties properties = new Properties(); try { final String resourceName = resourceName(groupId, artifactId); diff --git a/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java b/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java index 61c77b1023..cb8be18660 100644 --- a/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java +++ b/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java @@ -15,11 +15,11 @@ void testAnnounceWithValidArguments() { @Test void testAnnounceWithNullGroupId() { - assertThrows(IllegalArgumentException.class, () -> Announcer.announce(null, "chronicle-queue")); + assertThrows(NullPointerException.class, () -> Announcer.announce(null, "chronicle-queue")); } @Test void testAnnounceWithNullArtifactId() { - assertThrows(IllegalArgumentException.class, () -> Announcer.announce("net.openhft", null)); + assertThrows(NullPointerException.class, () -> Announcer.announce("net.openhft", null)); } } From 077e7025b3ef0ec692375dae776ab09acc3cff85 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 28 Mar 2024 17:19:35 +0000 Subject: [PATCH 06/43] =?UTF-8?q?Use=20a=20common=20configuration=20for=20?= =?UTF-8?q?the=20compiler-plugin=20where=20deprecation=20=E2=80=A6=20(#639?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use a common configuration for the compiler-plugin where deprecation warnings cause the build to fail * Remove annotation processor that is more confusing than useful (and often turned off) --- assertions-disabled/pom.xml | 2 +- assertions-enabled/pom.xml | 2 +- benchmarks/pom.xml | 4 ++-- checked-exceptions/pom.xml | 2 +- pom.xml | 7 ++++--- .../openhft/chronicle/core/internal/CloseableUtils.java | 1 + .../net/openhft/chronicle/core/io/AbstractCloseable.java | 1 + .../chronicle/core/io/CleaningRandomAccessFile.java | 1 + 8 files changed, 12 insertions(+), 8 deletions(-) diff --git a/assertions-disabled/pom.xml b/assertions-disabled/pom.xml index 4fdcb90f30..76c40f5db6 100644 --- a/assertions-disabled/pom.xml +++ b/assertions-disabled/pom.xml @@ -25,7 +25,7 @@ net.openhft java-parent-pom - 1.24.0 + 1.26.0-SNAPSHOT diff --git a/assertions-enabled/pom.xml b/assertions-enabled/pom.xml index 5486a39369..c3f7125d34 100644 --- a/assertions-enabled/pom.xml +++ b/assertions-enabled/pom.xml @@ -25,7 +25,7 @@ net.openhft java-parent-pom - 1.24.0 + 1.26.0-SNAPSHOT diff --git a/benchmarks/pom.xml b/benchmarks/pom.xml index ad3f9f6d64..8c1b7d3374 100644 --- a/benchmarks/pom.xml +++ b/benchmarks/pom.xml @@ -22,7 +22,7 @@ net.openhft java-parent-pom - 1.24.0 + 1.26.0-SNAPSHOT @@ -41,7 +41,7 @@ net.openhft third-party-bom - 3.24.0 + 3.26.0-SNAPSHOT pom import diff --git a/checked-exceptions/pom.xml b/checked-exceptions/pom.xml index 6d027334fe..0e858c84b9 100644 --- a/checked-exceptions/pom.xml +++ b/checked-exceptions/pom.xml @@ -23,7 +23,7 @@ net.openhft java-parent-pom - 1.24.0 + 1.26.0-SNAPSHOT diff --git a/pom.xml b/pom.xml index a6c2ffcc47..77c893cab8 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.25.4 + 1.26.0-SNAPSHOT chronicle-core @@ -48,7 +48,7 @@ net.openhft third-party-bom - 3.25.2 + 3.26.0-SNAPSHOT pom import @@ -343,7 +343,7 @@ java11 - [11, + [11,) @@ -357,6 +357,7 @@ --add-exports=java.base/jdk.internal.ref=ALL-UNNAMED --add-exports=java.base/sun.nio.ch=ALL-UNNAMED + false 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 8a8a340982..4e8392e7e3 100644 --- a/src/main/java/net/openhft/chronicle/core/internal/CloseableUtils.java +++ b/src/main/java/net/openhft/chronicle/core/internal/CloseableUtils.java @@ -78,6 +78,7 @@ public static void disableCloseableTracing() { * * @throws AssertionError If the finalizer does not complete within the specified timeout. */ + @SuppressWarnings("removal") public static void gcAndWaitForCloseablesToClose() { CleaningThread.performCleanup(Thread.currentThread()); 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 7f94e9aeb9..45e68b3734 100644 --- a/src/main/java/net/openhft/chronicle/core/io/AbstractCloseable.java +++ b/src/main/java/net/openhft/chronicle/core/io/AbstractCloseable.java @@ -464,6 +464,7 @@ class Finalizer { * * @throws Throwable if an error occurs during finalization. */ + @SuppressWarnings("removal") @Override protected void finalize() throws Throwable { warnAndCloseIfNotClosed(); diff --git a/src/main/java/net/openhft/chronicle/core/io/CleaningRandomAccessFile.java b/src/main/java/net/openhft/chronicle/core/io/CleaningRandomAccessFile.java index ac0037eb75..8d2429172e 100644 --- a/src/main/java/net/openhft/chronicle/core/io/CleaningRandomAccessFile.java +++ b/src/main/java/net/openhft/chronicle/core/io/CleaningRandomAccessFile.java @@ -37,6 +37,7 @@ public CleaningRandomAccessFile(File file, String mode) throws FileNotFoundExcep super(file, mode); } + @SuppressWarnings("removal") @Override protected void finalize() throws Throwable { super.finalize(); From 5dbc1aec54edba1995d92b4dcbda642f55eefb96 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 28 Mar 2024 17:27:02 +0000 Subject: [PATCH 07/43] sun.misc.Unsafe usage produces a warning --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 77c893cab8..9a4e11e087 100644 --- a/pom.xml +++ b/pom.xml @@ -219,6 +219,7 @@ maven-compiler-plugin -Xlint:deprecation,-options + false From d7d811ddeca815453d818dd88a3a3d78d37a5689 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 3 Apr 2024 09:49:32 +0100 Subject: [PATCH 08/43] review with lint:all (#641) --- pom.xml | 2 +- .../openhft/chronicle/core/ChronicleInit.java | 10 +- .../java/net/openhft/chronicle/core/Jvm.java | 11 +- .../java/net/openhft/chronicle/core/OS.java | 2 +- .../openhft/chronicle/core/UnsafeMemory.java | 245 +++++++++--------- .../chronicle/core/internal/Bootstrap.java | 5 + .../chronicle/core/internal/ClassUtil.java | 2 +- .../core/internal/CloseableUtils.java | 7 +- .../internal/analytics/ReflectionUtil.java | 16 +- .../chronicle/core/io/AbstractCloseable.java | 1 + .../io/AbstractCloseableReferenceCounted.java | 1 + .../core/io/AbstractReferenceCounted.java | 1 + .../core/io/ClosedIORuntimeException.java | 1 + .../core/io/ClosedIllegalStateException.java | 1 + .../chronicle/core/io/IORuntimeException.java | 1 + .../core/io/InvalidMarshallableException.java | 1 + .../io/ThreadingIllegalStateException.java | 1 + .../chronicle/core/io/UnsafeCloseable.java | 1 + .../ThreadLocalisedExceptionHandler.java | 1 + .../chronicle/core/pool/ClassAliasPool.java | 5 +- .../chronicle/core/pool/DynamicEnumClass.java | 7 +- .../chronicle/core/pool/EnumInterner.java | 7 +- .../chronicle/core/pool/ParsingCache.java | 6 +- .../core/scoped/ScopedThreadLocal.java | 4 +- .../chronicle/core/shutdown/PriorityHook.java | 4 +- .../core/threads/CleaningThread.java | 3 +- .../core/threads/CleaningThreadLocal.java | 7 +- .../threads/InterruptedRuntimeException.java | 1 + .../threads/InvalidEventHandlerException.java | 2 + .../chronicle/core/time/SetTimeProvider.java | 1 + .../core/util/AbstractInvocationHandler.java | 6 +- .../util/ClassNotFoundRuntimeException.java | 1 + .../chronicle/core/util/CompilerUtils.java | 4 +- .../core/util/GenericReflection.java | 4 +- .../InvocationTargetRuntimeException.java | 1 + .../core/util/MisAlignedAssertionError.java | 1 + .../openhft/chronicle/core/util/Mocker.java | 40 +-- .../chronicle/core/util/ObjectUtils.java | 8 +- .../core/internal/CloseableUtilsTest.java | 3 +- 39 files changed, 242 insertions(+), 183 deletions(-) diff --git a/pom.xml b/pom.xml index 9a4e11e087..ff6f0d6a21 100644 --- a/pom.xml +++ b/pom.xml @@ -218,7 +218,7 @@ org.apache.maven.plugins maven-compiler-plugin - -Xlint:deprecation,-options + -Xlint:all,-options false diff --git a/src/main/java/net/openhft/chronicle/core/ChronicleInit.java b/src/main/java/net/openhft/chronicle/core/ChronicleInit.java index a18f3df4f9..ab64ac700e 100644 --- a/src/main/java/net/openhft/chronicle/core/ChronicleInit.java +++ b/src/main/java/net/openhft/chronicle/core/ChronicleInit.java @@ -20,6 +20,8 @@ import java.util.ServiceLoader; +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; + /** * Handles application code which must be loaded first/run and may override system properties. *

@@ -50,8 +52,8 @@ private ChronicleInit() { String initRunnableClass = System.getProperty(CHRONICLE_INIT_CLASS); if (initRunnableClass != null && !initRunnableClass.isEmpty()) { try { - Class descendant = (Class) Class.forName(initRunnableClass); - Runnable chronicleInit = descendant.newInstance(); + Class descendant = uncheckedCast(Class.forName(initRunnableClass)); + Runnable chronicleInit = descendant.getConstructor().newInstance(); chronicleInit.run(); } catch (Exception ex) { // System.err since the logging subsystem may not be up at this point @@ -89,8 +91,8 @@ static void postInit() { String initRunnableClass = System.getProperty(CHRONICLE_POSTINIT_CLASS); if (initRunnableClass != null && !initRunnableClass.isEmpty()) { try { - Class descendant = (Class) Class.forName(initRunnableClass); - Runnable chronicleInit = descendant.newInstance(); + Class descendant = uncheckedCast(Class.forName(initRunnableClass)); + Runnable chronicleInit = descendant.getConstructor().newInstance(); chronicleInit.run(); } catch (Exception ex) { // System.err since the logging subsystem may not be up at this point diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index ddb6b3a2b9..bd815fdca9 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -574,7 +574,7 @@ public static Field getFieldOrNull(@NotNull final Class clazz, @NotNull final @NotNull public static Method getMethod(@NotNull final Class clazz, @NotNull final String methodName, - final Class... argTypes) { + final Class... argTypes) { return ClassUtil.getMethod0(clazz, methodName, argTypes, true); } @@ -618,7 +618,7 @@ public static V getValue(@NotNull Object target, @NotNull final String field } aClass = target.getClass(); } - return (V) target; + return uncheckedCast(target); } /** @@ -1223,7 +1223,7 @@ public static long parseSize(@NotNull String value) throws IllegalArgumentExcept } } double number = Double.parseDouble(value.trim()); - factor *= number; + factor *= (long) number; return factor; } @@ -1310,9 +1310,10 @@ private static void doNotCloseOnInterrupt9(final Class clazz, final FileChann final Class interruptibleClass = field.getType(); ClassUtil.setAccessible(field); final CommonInterruptible ci = new CommonInterruptible(clazz, fc); + Class[] interfaces = {interruptibleClass}; field.set(fc, Proxy.newProxyInstance( interruptibleClass.getClassLoader(), - new Class[]{interruptibleClass}, + interfaces, (p, m, a) -> { if (m.getDeclaringClass() != Object.class) ci.interrupt(); @@ -1450,7 +1451,7 @@ public static int objectHeaderSize() { * @return The object header size or array base offset, depending on the class type. */ @Deprecated(/* to be removed in x.27, use net.openhft.chronicle.bytes.BytesUtil.triviallyCopyableStart for POJOs */) - public static int objectHeaderSize(Class type) { + public static int objectHeaderSize(Class type) { return ObjectHeaderSizeHolder.objectHeaderSize(type); } diff --git a/src/main/java/net/openhft/chronicle/core/OS.java b/src/main/java/net/openhft/chronicle/core/OS.java index 0c3f353db9..6085fc67fc 100644 --- a/src/main/java/net/openhft/chronicle/core/OS.java +++ b/src/main/java/net/openhft/chronicle/core/OS.java @@ -368,7 +368,7 @@ public static long mapAlign(long offset) { */ public static long mapAlign(long offset, int pageAlignment) { requireNonNegative(offset); - require(positive(), pageAlignment); + requirePositive(pageAlignment); return (offset + pageAlignment - 1) / pageAlignment * pageAlignment; } diff --git a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java index 95a5b2ec9d..9732c18cac 100644 --- a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java +++ b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java @@ -21,7 +21,6 @@ import net.openhft.chronicle.core.internal.Bootstrap; import net.openhft.chronicle.core.internal.util.DirectBufferUtil; import net.openhft.chronicle.core.util.Ints; -import net.openhft.chronicle.core.util.Longs; import net.openhft.chronicle.core.util.MisAlignedAssertionError; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,8 +33,6 @@ import static java.util.Objects.nonNull; import static net.openhft.chronicle.assertions.AssertUtil.SKIP_ASSERTIONS; -import static net.openhft.chronicle.core.util.Ints.assertIfEnabled; -import static net.openhft.chronicle.core.util.Longs.assertIfEnabled; import static net.openhft.chronicle.core.util.ObjectUtils.requireNonNull; @SuppressWarnings("unchecked") @@ -167,7 +164,7 @@ private static long retryReadVolatileLong(long address, long value) { */ public static void putInt(byte[] bytes, int offset, int value) { assert SKIP_ASSERTIONS || nonNull(bytes); - assert SKIP_ASSERTIONS || Ints.betweenZeroAndReserving().test(offset, bytes.length, Integer.BYTES); + assert SKIP_ASSERTIONS || offset + Integer.BYTES <= bytes.length; UnsafeMemory.UNSAFE.putInt(bytes, ARRAY_BYTE_BASE_OFFSET + offset, value); } @@ -264,7 +261,7 @@ public static void unsafePutByte(long address, byte value) { */ public static void unsafePutLong(byte[] bytes, int offset, long value) { assert SKIP_ASSERTIONS || nonNull(bytes); - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.betweenZeroAndReserving(), offset, bytes.length, Long.BYTES); + assert SKIP_ASSERTIONS || offset + Long.BYTES <= bytes.length; UNSAFE.putLong(bytes, ARRAY_BYTE_BASE_OFFSET + offset, value); } @@ -277,7 +274,7 @@ public static void unsafePutLong(byte[] bytes, int offset, long value) { */ public static void unsafePutInt(byte[] bytes, int offset, int value) { assert SKIP_ASSERTIONS || nonNull(bytes); - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.betweenZeroAndReserving(), offset, bytes.length, Integer.BYTES); + assert SKIP_ASSERTIONS || offset + Integer.BYTES <= bytes.length; UNSAFE.putInt(bytes, ARRAY_BYTE_BASE_OFFSET + offset, value); } @@ -290,7 +287,7 @@ public static void unsafePutInt(byte[] bytes, int offset, int value) { */ public static void unsafePutByte(byte[] bytes, int offset, byte value) { assert SKIP_ASSERTIONS || nonNull(bytes); - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.betweenZeroAndReserving(), offset, bytes.length, Byte.BYTES); + assert SKIP_ASSERTIONS || offset + Byte.BYTES <= bytes.length; UNSAFE.putByte(bytes, ARRAY_BYTE_BASE_OFFSET + offset, value); } @@ -316,7 +313,7 @@ public static void copyMemory(long from, long to, int length) { * @param value the new value. */ public static void unsafePutBoolean(Object obj, long offset, boolean value) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; UNSAFE.putBoolean(obj, offset, value); } @@ -328,7 +325,7 @@ public static void unsafePutBoolean(Object obj, long offset, boolean value) { * @return the value of the boolean field or array element. */ public static boolean unsafeGetBoolean(Object obj, long offset) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; return UNSAFE.getBoolean(obj, offset); } @@ -339,7 +336,7 @@ public static boolean unsafeGetBoolean(Object obj, long offset) { * @param offset the offset to the byte within the object. */ public static void unsafePutByte(Object obj, long offset, byte value) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; UNSAFE.putByte(obj, offset, value); } @@ -350,7 +347,7 @@ public static void unsafePutByte(Object obj, long offset, byte value) { * @param offset the offset at which to put the byte within the object. */ public static byte unsafeGetByte(Object obj, long offset) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; return UNSAFE.getByte(obj, offset); } @@ -362,7 +359,7 @@ public static byte unsafeGetByte(Object obj, long offset) { * @param value the new value. */ public static void unsafePutChar(Object obj, long offset, char value) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; UNSAFE.putChar(obj, offset, value); } @@ -374,7 +371,7 @@ public static void unsafePutChar(Object obj, long offset, char value) { * @return the fetched char value. */ public static char unsafeGetChar(Object obj, long offset) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; return UNSAFE.getChar(obj, offset); } @@ -386,7 +383,7 @@ public static char unsafeGetChar(Object obj, long offset) { * @param value the short value to put. */ public static void unsafePutShort(Object obj, long offset, short value) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; UNSAFE.putShort(obj, offset, value); } @@ -398,7 +395,7 @@ public static void unsafePutShort(Object obj, long offset, short value) { * @return the fetched short value. */ public static short unsafeGetShort(Object obj, long offset) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; return UNSAFE.getShort(obj, offset); } @@ -410,7 +407,7 @@ public static short unsafeGetShort(Object obj, long offset) { * @param value the int value to put. */ public static void unsafePutInt(Object obj, long offset, int value) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; UNSAFE.putInt(obj, offset, value); } @@ -422,7 +419,7 @@ public static void unsafePutInt(Object obj, long offset, int value) { * @return the fetched int value. */ public static int unsafeGetInt(Object obj, long offset) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; return UNSAFE.getInt(obj, offset); } @@ -434,7 +431,7 @@ public static int unsafeGetInt(Object obj, long offset) { * @param value the float value to put. */ public static void unsafePutFloat(Object obj, long offset, float value) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; UNSAFE.putFloat(obj, offset, value); } @@ -446,7 +443,7 @@ public static void unsafePutFloat(Object obj, long offset, float value) { * @return the fetched float value. */ public static float unsafeGetFloat(Object obj, long offset) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; return UNSAFE.getFloat(obj, offset); } @@ -458,7 +455,7 @@ public static float unsafeGetFloat(Object obj, long offset) { * @param value the long value to put. */ public static void unsafePutLong(Object obj, long offset, long value) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; UNSAFE.putLong(obj, offset, value); } @@ -470,7 +467,7 @@ public static void unsafePutLong(Object obj, long offset, long value) { * @return the fetched long value. */ public static long unsafeGetLong(Object obj, long offset) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; return UNSAFE.getLong(obj, offset); } @@ -482,7 +479,7 @@ public static long unsafeGetLong(Object obj, long offset) { * @param value the double value to put. */ public static void unsafePutDouble(Object obj, long offset, double value) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; UNSAFE.putDouble(obj, offset, value); } @@ -494,7 +491,7 @@ public static void unsafePutDouble(Object obj, long offset, double value) { * @return the fetched double value. */ public static double unsafeGetDouble(Object obj, long offset) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; return UNSAFE.getDouble(obj, offset); } @@ -506,7 +503,7 @@ public static double unsafeGetDouble(Object obj, long offset) { * @param value the value to put. */ public static void unsafePutObject(Object obj, long offset, Object value) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; UNSAFE.putObject(obj, offset, value); } @@ -519,7 +516,7 @@ public static void unsafePutObject(Object obj, long offset, Object value) { * @return the fetched object. */ public static T unsafeGetObject(Object obj, long offset) { - assert SKIP_ASSERTIONS || obj == null || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || obj == null || offset > 0; return (T) UNSAFE.getObject(obj, offset); } @@ -572,7 +569,7 @@ public long getFieldOffset(Field field) { */ @Override public void putObject(@NotNull Object object, long offset, Object value) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; UNSAFE.putObject(requireNonNull(object), offset, value); } @@ -587,7 +584,7 @@ public void putObject(@NotNull Object object, long offset, Object value) { @NotNull @Override public T getObject(@NotNull Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return (T) UNSAFE.getObject(requireNonNull(object), offset); } @@ -617,7 +614,7 @@ public void loadFence() { @Override public void setMemory(long address, long size, byte b) { assert SKIP_ASSERTIONS || address != 0; - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), size); + assert SKIP_ASSERTIONS || size >= 0; UNSAFE.setMemory(address, size, b); } @@ -632,7 +629,7 @@ public void setMemory(long address, long size, byte b) { @Override public void setMemory(Object o, long offset, long size, byte b) { assert SKIP_ASSERTIONS || offset != 0; - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), size); + assert SKIP_ASSERTIONS || size >= 0; UNSAFE.setMemory(o, offset, size, b); } @@ -644,8 +641,7 @@ public void setMemory(Object o, long offset, long size, byte b) { */ @Override public void freeMemory(long address, long size) { - assert address != 0; - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), size); + assert SKIP_ASSERTIONS || size >= 0; if (address != 0) UNSAFE.freeMemory(address); nativeMemoryUsed.addAndGet(-size); @@ -703,7 +699,7 @@ public void writeByte(long address, byte b) { */ @Override public void writeByte(Object object, long offset, byte b) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; UNSAFE.putByte(object, offset, b); } @@ -716,7 +712,7 @@ public void writeByte(Object object, long offset, byte b) { */ @Override public byte readByte(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.getByte(object, offset); } @@ -732,8 +728,8 @@ public byte readByte(Object object, long offset) { @Override public void writeBytes(long address, byte[] b, int offset, int length) throws IllegalArgumentException { assert address != 0; - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.nonNegative(), offset); - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.nonNegative(), length); + assert SKIP_ASSERTIONS || offset >= 0; + assert SKIP_ASSERTIONS || length >= 0; if (offset + length > b.length) throw new IllegalArgumentException("Invalid offset or length, array's length is " + b.length); UnsafeMemory.UNSAFE.copyMemory(b, ARRAY_BYTE_BASE_OFFSET + offset, null, address, length); @@ -751,8 +747,8 @@ public void writeBytes(long address, byte[] b, int offset, int length) throws Il @Override public void readBytes(long address, byte[] b, long offset, int length) throws IllegalArgumentException { assert address != 0; - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), offset); - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.nonNegative(), length); + assert SKIP_ASSERTIONS || offset >= 0; + assert SKIP_ASSERTIONS || length >= 0; if (offset + length > b.length) throw new IllegalArgumentException("Invalid offset or length, array's length is " + b.length); UnsafeMemory.UNSAFE.copyMemory(null, address, b, ARRAY_BYTE_BASE_OFFSET + offset, length); @@ -791,7 +787,7 @@ public void writeShort(long address, short i16) { */ @Override public void writeShort(Object object, long offset, short i16) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; UNSAFE.putShort(object, offset, i16); } @@ -816,7 +812,7 @@ public short readShort(long address) { */ @Override public short readShort(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.getShort(object, offset); } @@ -841,7 +837,7 @@ public void writeInt(long address, int i32) { */ @Override public void writeInt(Object object, long offset, int i32) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; UNSAFE.putInt(object, offset, i32); } @@ -866,7 +862,7 @@ public void writeOrderedInt(long address, int i32) { */ @Override public void writeOrderedInt(Object object, long offset, int i32) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; UNSAFE.putOrderedInt(object, offset, i32); } @@ -891,7 +887,7 @@ public int readInt(long address) { */ @Override public int readInt(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.getInt(object, offset); } @@ -916,7 +912,7 @@ public void writeLong(long address, long i64) { */ @Override public void writeLong(Object object, long offset, long i64) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; UNSAFE.putLong(object, offset, i64); } @@ -941,7 +937,7 @@ public long readLong(long address) { */ @Override public long readLong(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.getLong(object, offset); } @@ -966,7 +962,7 @@ public void writeFloat(long address, float f) { */ @Override public void writeFloat(Object object, long offset, float f) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; UNSAFE.putFloat(object, offset, f); } @@ -991,7 +987,7 @@ public float readFloat(long address) { */ @Override public float readFloat(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.getFloat(object, offset); } @@ -1016,7 +1012,7 @@ public void writeDouble(long address, double d) { */ @Override public void writeDouble(Object object, long offset, double d) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; UNSAFE.putDouble(object, offset, d); } @@ -1041,7 +1037,7 @@ public double readDouble(long address) { */ @Override public double readDouble(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.getDouble(object, offset); } @@ -1068,9 +1064,9 @@ public void copyMemory(byte[] src, int srcOffset, long destAddress, int length) */ @Override public void copyMemory(long srcAddress, long destAddress, long length) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), srcAddress); + assert SKIP_ASSERTIONS || srcAddress > 0; assert SKIP_ASSERTIONS || destAddress != 0; - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), length); + assert SKIP_ASSERTIONS || length >= 0; if (length < UNSAFE_COPY_THRESHOLD) { UNSAFE.copyMemory(srcAddress, destAddress, length); } else { @@ -1087,12 +1083,12 @@ public void copyMemory(long srcAddress, long destAddress, long length) { * @param destOffset offset of the destination object from where to place the copied memory. * @param length the length of memory to copy. */ - @Deprecated(/* for removal in x.26 */) + @Deprecated(/* for removal in x.26, don't just delete this method, it must be inlined. */) public void copyMemory(byte[] src, int srcOffset, @Nullable Object dest, long destOffset, int length) { assert SKIP_ASSERTIONS || nonNull(src); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), srcOffset); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), destOffset); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), length); + assert SKIP_ASSERTIONS || srcOffset >= 0; + assert SKIP_ASSERTIONS || destOffset >= 0; + assert SKIP_ASSERTIONS || length >= 0; if (dest instanceof byte[]) { copyMemory(src, srcOffset, (byte[]) dest, Math.toIntExact(destOffset - ARRAY_BYTE_BASE_OFFSET), length); @@ -1112,10 +1108,10 @@ public void copyMemory(byte[] src, int srcOffset, @Nullable Object dest, long de */ public void copyMemory(byte[] src, int srcOffset, byte[] dest, int destOffset, int length) { assert SKIP_ASSERTIONS || nonNull(src); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), srcOffset); + assert SKIP_ASSERTIONS || srcOffset >= 0; assert SKIP_ASSERTIONS || nonNull(dest); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), destOffset); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), length); + assert SKIP_ASSERTIONS || destOffset >= 0; + assert SKIP_ASSERTIONS || length >= 0; final long offsetB = ARRAY_BYTE_BASE_OFFSET + srcOffset; final long offset2B = ARRAY_BYTE_BASE_OFFSET + destOffset; if (length < UNSAFE_COPY_THRESHOLD) { @@ -1152,9 +1148,9 @@ public void copyMemory(@Nullable Object src, long srcOffset, long destAddress, i @Override public void copyMemory(@Nullable Object src, long srcOffset, @Nullable Object dest, long destOffset, int length) { assert SKIP_ASSERTIONS || !(src == null && dest == null); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), srcOffset); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), destOffset); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), length); + assert SKIP_ASSERTIONS || srcOffset >= 0; + assert SKIP_ASSERTIONS || destOffset >= 0; + assert SKIP_ASSERTIONS || length >= 0; if (src instanceof byte[]) { if (dest instanceof byte[]) { copyMemory((byte[]) src, Math.toIntExact(srcOffset - Unsafe.ARRAY_BYTE_BASE_OFFSET), (byte[]) dest, Math.toIntExact(destOffset - ARRAY_BYTE_BASE_OFFSET), length); @@ -1205,10 +1201,10 @@ private void copyMemoryLoop(Object src, long srcOffset, Object dest, long destOf private void backwardCopyMemoryLoop(Object src, long srcOffset, Object dest, long destOffset, int length) { assert SKIP_ASSERTIONS || nonNull(src); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), srcOffset); + assert SKIP_ASSERTIONS || srcOffset > 0; assert SKIP_ASSERTIONS || nonNull(dest); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), destOffset); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), length); + assert SKIP_ASSERTIONS || destOffset > 0; + assert SKIP_ASSERTIONS || length >= 0; srcOffset += length; destOffset += length; int i = 0; @@ -1229,9 +1225,9 @@ private void backwardCopyMemoryLoop(Object src, long srcOffset, Object dest, lon */ @Override public void copyMemory(long srcAddress, @Nullable Object dest, long destOffset, int length) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), srcAddress); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), destOffset); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), length); + assert SKIP_ASSERTIONS || srcAddress > 0; + assert SKIP_ASSERTIONS || destOffset > 0; + assert SKIP_ASSERTIONS || length >= 0; long start = length > 128 << 10 ? System.nanoTime() : 0; copyMemoryLoop(null, srcAddress, dest, destOffset, length); if (length > 128 << 10) { @@ -1252,9 +1248,9 @@ public void copyMemory(long srcAddress, @Nullable Object dest, long destOffset, * @param length the length of memory to copy. */ void copyMemory0(@Nullable Object src, long srcOffset, @Nullable Object dest, long destOffset, long length) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), srcOffset); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), destOffset); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), length); + assert SKIP_ASSERTIONS || srcOffset > 0; + assert SKIP_ASSERTIONS || destOffset > 0; + assert SKIP_ASSERTIONS || length >= 0; // use a loop to ensure there is a safe point every so often. while (length > 0) { long size = Math.min(length, UNSAFE_COPY_THRESHOLD); @@ -1336,7 +1332,7 @@ private int stopBitLength0(long l) { @Override public long partialRead(byte[] bytes, int offset, int length) { assert SKIP_ASSERTIONS || nonNull(bytes); - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.betweenZeroAndReserving(), offset, bytes.length, length); + assert SKIP_ASSERTIONS || offset + length <= bytes.length; switch (length) { case 8: return UNSAFE.getLong(bytes, ARRAY_BYTE_BASE_OFFSET + offset); @@ -1383,8 +1379,8 @@ public long partialRead(byte[] bytes, int offset, int length) { */ @Override public long partialRead(long addr, int length) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), addr); - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.nonNegative(), length); + assert SKIP_ASSERTIONS || addr > 0; + assert SKIP_ASSERTIONS || length >= 0; switch (length) { case 8: return UNSAFE.getLong(addr); @@ -1433,8 +1429,8 @@ public long partialRead(long addr, int length) { @Override public void partialWrite(byte[] bytes, int offset, long value, int length) { assert SKIP_ASSERTIONS || nonNull(bytes); - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.nonNegative(), offset); - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.nonNegative(), length); + assert SKIP_ASSERTIONS || offset >= 0; + assert SKIP_ASSERTIONS || length >= 0; switch (length) { case 8: UNSAFE.putLong(bytes, ARRAY_BYTE_BASE_OFFSET + offset, value); @@ -1479,8 +1475,8 @@ public void partialWrite(byte[] bytes, int offset, long value, int length) { */ @Override public void partialWrite(long addr, long value, int length) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), addr); - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.nonNegative(), length); + assert SKIP_ASSERTIONS || addr > 0; + assert SKIP_ASSERTIONS || length >= 0; switch (length) { case 8: UNSAFE.putLong(addr, value); @@ -1525,8 +1521,8 @@ public void partialWrite(long addr, long value, int length) { @Override public boolean is7Bit(byte[] bytes, int offset, int length) { assert SKIP_ASSERTIONS || nonNull(bytes); - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.nonNegative(), offset); - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.nonNegative(), length); + assert SKIP_ASSERTIONS || offset >= 0; + assert SKIP_ASSERTIONS || length >= 0; final long offset2 = offset + ARRAY_BYTE_BASE_OFFSET; int i = 0; for (; i < length - 7; i += 8) @@ -1560,8 +1556,8 @@ public boolean is7Bit(byte[] bytes, int offset, int length) { @Override public boolean is7Bit(char[] chars, int offset, int length) { assert SKIP_ASSERTIONS || nonNull(chars); - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.nonNegative(), offset); - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.nonNegative(), length); + assert SKIP_ASSERTIONS || offset >= 0; + assert SKIP_ASSERTIONS || length >= 0; final long offset2 = offset * 2L + ARRAY_CHAR_BASE_OFFSET; int i = 0; for (; i < length - 3; i += 4) @@ -1587,7 +1583,7 @@ public boolean is7Bit(char[] chars, int offset, int length) { @Override public boolean is7Bit(long address, int length) { assert SKIP_ASSERTIONS || address != 0; - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.nonNegative(), length); + assert SKIP_ASSERTIONS || length >= 0; int i = 0; for (; i < length - 7; i += 8) if ((UnsafeMemory.UNSAFE.getLong(address + i) & 0x8080808080808080L) != 0) @@ -1630,7 +1626,7 @@ public void writeOrderedLong(long address, long i) { */ @Override public void writeOrderedLong(Object object, long offset, long i) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; UNSAFE.putOrderedLong(object, offset, i); } @@ -1648,7 +1644,7 @@ public void writeOrderedLong(Object object, long offset, long i) { public void testAndSetInt(long address, long offset, int expected, int value) throws IllegalStateException { assert (address & 63) <= 64 - 4; assert SKIP_ASSERTIONS || address != 0; - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), offset); + assert SKIP_ASSERTIONS || offset >= 0; if (UNSAFE.compareAndSwapInt(null, address, expected, value)) return; int actual = UNSAFE.getIntVolatile(null, address); @@ -1668,7 +1664,7 @@ public void testAndSetInt(long address, long offset, int expected, int value) th @Override public void testAndSetInt(Object object, long offset, int expected, int value) throws IllegalStateException { assert SKIP_ASSERTIONS || nonNull(object); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if (UNSAFE.compareAndSwapInt(object, offset, expected, value)) return; int actual = UNSAFE.getIntVolatile(object, offset); @@ -1706,7 +1702,7 @@ public boolean compareAndSwapInt(long address, int expected, int value) throws M @Override public boolean compareAndSwapInt(Object object, long offset, int expected, int value) throws MisAlignedAssertionError { assert (offset & 63) <= 64 - 4; - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.compareAndSwapInt(object, offset, expected, value); } @@ -1741,7 +1737,7 @@ public boolean compareAndSwapLong(long address, long expected, long value) throw */ @Override public boolean compareAndSwapLong(Object object, long offset, long expected, long value) throws MisAlignedAssertionError { - assert SKIP_ASSERTIONS || (object == null || assertIfEnabled(Longs.positive(), offset)); + assert SKIP_ASSERTIONS || (object == null || offset > 0); return UNSAFE.compareAndSwapLong(object, offset, expected, value); } @@ -1774,7 +1770,7 @@ public int getAndSetInt(long address, int value) throws MisAlignedAssertionError @Override public int getAndSetInt(Object object, long offset, int value) throws MisAlignedAssertionError { assert (offset & 63) <= 64 - 4; - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.getAndSetInt(object, offset, value); } @@ -1809,7 +1805,7 @@ public byte readVolatileByte(long address) { */ @Override public byte readVolatileByte(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.getByteVolatile(object, offset); } @@ -1823,7 +1819,6 @@ public byte readVolatileByte(Object object, long offset) { @Override public short readVolatileShort(long address) { assert SKIP_ASSERTIONS || address != 0; - // TODO add support for a short split across cache lines. return UNSAFE.getShortVolatile(null, address); } @@ -1836,7 +1831,7 @@ public short readVolatileShort(long address) { */ @Override public short readVolatileShort(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.getShortVolatile(object, offset); } @@ -1869,7 +1864,7 @@ public int readVolatileInt(long address) { */ @Override public int readVolatileInt(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.getIntVolatile(object, offset); } @@ -1883,7 +1878,6 @@ public int readVolatileInt(Object object, long offset) { @Override public float readVolatileFloat(long address) { assert SKIP_ASSERTIONS || address != 0; - // TODO add support for a float split across cache lines. return UNSAFE.getFloatVolatile(null, address); } @@ -1896,7 +1890,7 @@ public float readVolatileFloat(long address) { */ @Override public float readVolatileFloat(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.getFloatVolatile(object, offset); } @@ -1927,7 +1921,7 @@ public long readVolatileLong(long address) { */ @Override public long readVolatileLong(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.getLongVolatile(object, offset); } @@ -1941,7 +1935,6 @@ public long readVolatileLong(Object object, long offset) { @Override public double readVolatileDouble(long address) { assert SKIP_ASSERTIONS || address != 0; - // TODO add support for a double split across cache lines. return UNSAFE.getDoubleVolatile(null, address); } @@ -1954,7 +1947,7 @@ public double readVolatileDouble(long address) { */ @Override public double readVolatileDouble(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.getDoubleVolatile(object, offset); } @@ -1979,7 +1972,7 @@ public void writeVolatileByte(long address, byte b) { */ @Override public void writeVolatileByte(Object object, long offset, byte b) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; UNSAFE.putByteVolatile(object, offset, b); } @@ -2004,7 +1997,7 @@ public void writeVolatileShort(long address, short i16) { */ @Override public void writeVolatileShort(Object object, long offset, short i16) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; UNSAFE.putShortVolatile(object, offset, i16); } @@ -2029,7 +2022,7 @@ public void writeVolatileInt(long address, int i32) { */ @Override public void writeVolatileInt(Object object, long offset, int i32) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; UNSAFE.putIntVolatile(object, offset, i32); } @@ -2054,7 +2047,7 @@ public void writeVolatileFloat(long address, float f) { */ @Override public void writeVolatileFloat(Object object, long offset, float f) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; UNSAFE.putFloatVolatile(object, offset, f); } @@ -2079,7 +2072,7 @@ public void writeVolatileLong(long address, long i64) { */ @Override public void writeVolatileLong(Object object, long offset, long i64) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; UNSAFE.putLongVolatile(object, offset, i64); } @@ -2104,7 +2097,7 @@ public void writeVolatileDouble(long address, double d) { */ @Override public void writeVolatileDouble(Object object, long offset, double d) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; UNSAFE.putDoubleVolatile(object, offset, d); } @@ -2132,7 +2125,7 @@ public int addInt(long address, int increment) throws MisAlignedAssertionError { */ @Override public int addInt(Object object, long offset, int increment) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.getAndAddInt(object, offset, increment) + increment; } @@ -2147,7 +2140,6 @@ public int addInt(Object object, long offset, int increment) { @Override public long addLong(long address, long increment) throws MisAlignedAssertionError { assert SKIP_ASSERTIONS || address != 0; -// assert (address & 0x7) == 0; return UNSAFE.getAndAddLong(null, address, increment) + increment; } @@ -2162,8 +2154,7 @@ public long addLong(long address, long increment) throws MisAlignedAssertionErro */ @Override public long addLong(Object object, long offset, long increment) throws MisAlignedAssertionError { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); -// assert (offset & 0x7) == 0; + assert SKIP_ASSERTIONS || offset > 0; return UNSAFE.getAndAddLong(object, offset, increment) + increment; } @@ -2176,8 +2167,8 @@ public long addLong(Object object, long offset, long increment) throws MisAligne * @param addr the target memory address. */ public void copy8bit(String s, int start, int length, long addr) { - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.nonNegative(), start); - assert SKIP_ASSERTIONS || assertIfEnabled(Ints.nonNegative(), length); + assert SKIP_ASSERTIONS || start >= 0; + assert SKIP_ASSERTIONS || length >= 0; assert addr != 0; if (CachedReflection.STRING_VALUE_OFFSET == 0) { copy8BitJava9(s, start, length, addr); @@ -2343,7 +2334,9 @@ static final class CachedReflection { try { if (!Jvm.isJava9Plus()) { final Field valueField = String.class.getDeclaredField("value"); - offset = UNSAFE.objectFieldOffset(valueField); + @SuppressWarnings("deprecation") + long offset0 = UNSAFE.objectFieldOffset(valueField); + offset = offset0; } } catch (NoSuchFieldException e) { offset = 0; @@ -2417,7 +2410,7 @@ public void writeVolatileShort(long address, short i16) { */ @Override public short readVolatileShort(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if ((offset & 0x1) == 0) return super.readVolatileShort(object, offset); UNSAFE.loadFence(); @@ -2434,7 +2427,7 @@ public short readVolatileShort(Object object, long offset) { */ @Override public void writeVolatileShort(Object object, long offset, short i16) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if ((offset & 0x1) == 0) { super.writeVolatileShort(object, offset, i16); } else { @@ -2487,7 +2480,7 @@ public float readFloat(long address) { */ @Override public void writeFloat(Object object, long offset, float f) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if ((offset & 0x3) == 0) super.writeFloat(object, offset, f); else @@ -2506,7 +2499,7 @@ public void writeFloat(Object object, long offset, float f) { */ @Override public float readFloat(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if (safeAlignedInt(offset)) return super.readFloat(object, offset); return Float.intBitsToFloat(super.readInt(object, offset)); @@ -2540,7 +2533,7 @@ public int readVolatileInt(long address) { */ @Override public int readVolatileInt(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if (safeAlignedInt(offset)) return super.readVolatileInt(object, offset); UNSAFE.loadFence(); @@ -2613,7 +2606,7 @@ public void writeOrderedInt(long address, int i32) { */ @Override public void writeVolatileInt(Object object, long offset, int i32) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if ((offset & 0x3) == 0) super.writeVolatileInt(object, offset, i32); else { @@ -2633,7 +2626,7 @@ public void writeVolatileInt(Object object, long offset, int i32) { */ @Override public void writeOrderedInt(Object object, long offset, int i32) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if (safeAlignedInt(offset)) { super.writeOrderedInt(object, offset, i32); } else { @@ -2708,7 +2701,7 @@ public boolean compareAndSwapInt(long address, int expected, int value) throws M */ @Override public boolean compareAndSwapInt(Object object, long offset, int expected, int value) throws MisAlignedAssertionError { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if (safeAlignedInt(offset)) return super.compareAndSwapInt(object, offset, expected, value); throw new MisAlignedAssertionError(); @@ -2745,7 +2738,7 @@ public int getAndSetInt(long address, int value) throws MisAlignedAssertionError */ @Override public int getAndSetInt(Object object, long offset, int value) throws MisAlignedAssertionError { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if (safeAlignedInt(offset)) return super.getAndSetInt(object, offset, value); throw new MisAlignedAssertionError(); @@ -2765,7 +2758,7 @@ public int getAndSetInt(Object object, long offset, int value) throws MisAligned @Override public void testAndSetInt(long address, long offset, int expected, int value) throws IllegalStateException { assert SKIP_ASSERTIONS || address != 0; - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if (safeAlignedInt(address)) { if (UNSAFE.compareAndSwapInt(null, address, expected, value)) { return; @@ -2798,7 +2791,7 @@ public void testAndSetInt(long address, long offset, int expected, int value) th @Override public void testAndSetInt(Object object, long offset, int expected, int value) throws IllegalStateException { assert SKIP_ASSERTIONS || nonNull(object); - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if (safeAlignedInt(offset)) { if (UNSAFE.compareAndSwapInt(object, offset, expected, value)) { return; @@ -2861,7 +2854,7 @@ public double readDouble(long address) { */ @Override public void writeDouble(Object object, long offset, double d) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if (safeAlignedLong(offset)) super.writeDouble(object, offset, d); else @@ -2879,7 +2872,7 @@ public void writeDouble(Object object, long offset, double d) { */ @Override public double readDouble(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if (safeAlignedLong(offset)) return super.readDouble(object, offset); return Double.longBitsToDouble(super.readLong(object, offset)); @@ -2932,7 +2925,7 @@ public long readVolatileLong(long address) { */ @Override public void writeOrderedLong(Object object, long offset, long i) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if (safeAlignedLong(offset)) { super.writeOrderedLong(object, offset, i); } else { @@ -2952,7 +2945,7 @@ public void writeOrderedLong(Object object, long offset, long i) { */ @Override public long readVolatileLong(Object object, long offset) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if (safeAlignedLong(offset)) return super.readVolatileLong(object, offset); UNSAFE.loadFence(); @@ -2986,7 +2979,7 @@ public double readVolatileDouble(long address) { */ @Override public void writeVolatileLong(Object object, long offset, long i64) { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if (safeAlignedLong(offset)) { super.writeVolatileLong(object, offset, i64); } else { @@ -3059,7 +3052,7 @@ public long addLong(long address, long increment) throws MisAlignedAssertionErro */ @Override public boolean compareAndSwapLong(Object object, long offset, long expected, long value) throws MisAlignedAssertionError { - assert SKIP_ASSERTIONS || assertIfEnabled(Longs.positive(), offset); + assert SKIP_ASSERTIONS || offset > 0; if (safeAlignedLong(offset)) return super.compareAndSwapLong(object, offset, expected, value); throw new MisAlignedAssertionError(); diff --git a/src/main/java/net/openhft/chronicle/core/internal/Bootstrap.java b/src/main/java/net/openhft/chronicle/core/internal/Bootstrap.java index a20e861b31..1fb218b146 100644 --- a/src/main/java/net/openhft/chronicle/core/internal/Bootstrap.java +++ b/src/main/java/net/openhft/chronicle/core/internal/Bootstrap.java @@ -186,4 +186,9 @@ private static int getProcessId0() { System.err.println(Bootstrap.class.getName() + ": Unable to determine PID, picked 1 as a PID"); return rpid; } + + @SuppressWarnings("unchecked") + public static T uncheckedCast(Object obj) { + return (T) obj; + } } 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 47bcfb5089..112fffc2fa 100644 --- a/src/main/java/net/openhft/chronicle/core/internal/ClassUtil.java +++ b/src/main/java/net/openhft/chronicle/core/internal/ClassUtil.java @@ -79,7 +79,7 @@ public static void setAccessible(@NotNull final AccessibleObject accessibleObjec public static Method getMethod0(@NotNull final Class clazz, @NotNull final String name, - final Class[] args, + final Class[] args, final boolean first) { try { final Method method = clazz.getDeclaredMethod(name, args); 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 4e8392e7e3..f39bca052d 100644 --- a/src/main/java/net/openhft/chronicle/core/internal/CloseableUtils.java +++ b/src/main/java/net/openhft/chronicle/core/internal/CloseableUtils.java @@ -87,6 +87,7 @@ public static void gcAndWaitForCloseablesToClose() { // Anonymous inner class overriding the finalize() method to track finalization. new Object() { + @SuppressWarnings("removal") @Override protected void finalize() throws Throwable { super.finalize(); @@ -297,11 +298,11 @@ public static void closeQuietly(@Nullable Object... closeables) { */ static void closeQuietly(@Nullable Object o) { if (o instanceof Collection) { - Collection coll = (Collection) o; + Collection coll = (Collection) o; if (coll.isEmpty()) return; // take a copy before removing - List list = new ArrayList<>(coll); + List list = new ArrayList<>(coll); list.forEach(Closeable::closeQuietly); } else if (o instanceof Object[]) { @@ -327,7 +328,7 @@ static void closeQuietly(@Nullable Object o) { } } else if (o instanceof Reference) { - closeQuietly(((Reference) o).get()); + closeQuietly(((Reference) o).get()); } else if (o instanceof HttpURLConnection) { HttpURLConnection connection = (HttpURLConnection) o; 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 f3f6d5ebc8..bd87269ea5 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 @@ -26,6 +26,7 @@ import java.lang.reflect.Proxy; import java.util.stream.Stream; +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; import static net.openhft.chronicle.core.util.ObjectUtils.requireNonNull; public final class ReflectionUtil { @@ -84,12 +85,16 @@ public static Object invokeOrThrow(@NotNull final Method method, } } - @SuppressWarnings("unchecked") @NotNull public static T reflectiveProxy(@NotNull final Class interf, @NotNull final Object delegate) throws IllegalArgumentException { requireNonNull(interf); requireNonNull(delegate); - return (T) Proxy.newProxyInstance(delegate.getClass().getClassLoader(), new Class[]{interf}, new ReflectiveInvocationHandler(delegate, false)); + Class[] interfaces = {interf}; + return uncheckedCast( + Proxy.newProxyInstance( + delegate.getClass().getClassLoader(), + interfaces, + new ReflectiveInvocationHandler(delegate, false))); } @SuppressWarnings("unchecked") @@ -99,7 +104,12 @@ public static T reflectiveProxy(@NotNull final Class interf, final boolean returnProxy) throws IllegalArgumentException { requireNonNull(interf); requireNonNull(delegate); - return (T) Proxy.newProxyInstance(delegate.getClass().getClassLoader(), new Class[]{interf}, new ReflectiveInvocationHandler(delegate, returnProxy)); + Class[] interfaces = {interf}; + return uncheckedCast( + Proxy.newProxyInstance( + delegate.getClass().getClassLoader(), + interfaces, + new ReflectiveInvocationHandler(delegate, returnProxy))); } private static final class ReflectiveInvocationHandler implements InvocationHandler { 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 45e68b3734..a30d6c1d49 100644 --- a/src/main/java/net/openhft/chronicle/core/io/AbstractCloseable.java +++ b/src/main/java/net/openhft/chronicle/core/io/AbstractCloseable.java @@ -91,6 +91,7 @@ public abstract class AbstractCloseable implements ReferenceOwner, ManagedClosea * Constructs a new instance. Registers the instance * for resource tracing and monitoring if enabled. */ + @SuppressWarnings("this-escape") protected AbstractCloseable() { createdHere = Jvm.isResourceTracing() ? new StackTrace(getClass().getName() + " created here") : null; CloseableUtils.add(this); 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 ffd32f4c62..4f9d3e8272 100644 --- a/src/main/java/net/openhft/chronicle/core/io/AbstractCloseableReferenceCounted.java +++ b/src/main/java/net/openhft/chronicle/core/io/AbstractCloseableReferenceCounted.java @@ -52,6 +52,7 @@ public abstract class AbstractCloseableReferenceCounted * Constructs a new AbstractCloseableReferenceCounted instance and adds the instance * to the CloseableUtils set for tracking. */ + @SuppressWarnings("this-escaope") protected AbstractCloseableReferenceCounted() { CloseableUtils.add(this); } 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 51f743fa1a..15d7fc88bb 100644 --- a/src/main/java/net/openhft/chronicle/core/io/AbstractReferenceCounted.java +++ b/src/main/java/net/openhft/chronicle/core/io/AbstractReferenceCounted.java @@ -59,6 +59,7 @@ protected AbstractReferenceCounted() { * * @param monitored If true, the resource will be monitored for reference counted release. */ + @SuppressWarnings("this-escape") protected AbstractReferenceCounted(boolean monitored) { Runnable performRelease = BG_RELEASER && canReleaseInBackground() ? this::backgroundPerformRelease diff --git a/src/main/java/net/openhft/chronicle/core/io/ClosedIORuntimeException.java b/src/main/java/net/openhft/chronicle/core/io/ClosedIORuntimeException.java index f7e4bc0fbb..c4d145cf5c 100644 --- a/src/main/java/net/openhft/chronicle/core/io/ClosedIORuntimeException.java +++ b/src/main/java/net/openhft/chronicle/core/io/ClosedIORuntimeException.java @@ -50,6 +50,7 @@ * */ public class ClosedIORuntimeException extends IORuntimeException { + private static final long serialVersionUID = 0L; /** * Constructs a {@code ClosedIORuntimeException} with the specified detail message. diff --git a/src/main/java/net/openhft/chronicle/core/io/ClosedIllegalStateException.java b/src/main/java/net/openhft/chronicle/core/io/ClosedIllegalStateException.java index cea0fb8fec..bb33c48299 100644 --- a/src/main/java/net/openhft/chronicle/core/io/ClosedIllegalStateException.java +++ b/src/main/java/net/openhft/chronicle/core/io/ClosedIllegalStateException.java @@ -40,6 +40,7 @@ * */ public class ClosedIllegalStateException extends IllegalStateException { + private static final long serialVersionUID = 0L; /** * Constructs a {@code ClosedIllegalStateException} with the specified detail message. diff --git a/src/main/java/net/openhft/chronicle/core/io/IORuntimeException.java b/src/main/java/net/openhft/chronicle/core/io/IORuntimeException.java index d0f04e07ee..1a3a28f99d 100644 --- a/src/main/java/net/openhft/chronicle/core/io/IORuntimeException.java +++ b/src/main/java/net/openhft/chronicle/core/io/IORuntimeException.java @@ -42,6 +42,7 @@ * */ public class IORuntimeException extends RuntimeException { + private static final long serialVersionUID = 0L; /** * Constructs an {@code IORuntimeException} with the specified detail message. diff --git a/src/main/java/net/openhft/chronicle/core/io/InvalidMarshallableException.java b/src/main/java/net/openhft/chronicle/core/io/InvalidMarshallableException.java index 44acad085f..3cf03d367f 100644 --- a/src/main/java/net/openhft/chronicle/core/io/InvalidMarshallableException.java +++ b/src/main/java/net/openhft/chronicle/core/io/InvalidMarshallableException.java @@ -53,6 +53,7 @@ * */ public class InvalidMarshallableException extends RuntimeException { + private static final long serialVersionUID = 0L; /** * Constructs an {@code InvalidMarshallableException} with the specified detail message. diff --git a/src/main/java/net/openhft/chronicle/core/io/ThreadingIllegalStateException.java b/src/main/java/net/openhft/chronicle/core/io/ThreadingIllegalStateException.java index 253f1fcb08..8890ef516c 100644 --- a/src/main/java/net/openhft/chronicle/core/io/ThreadingIllegalStateException.java +++ b/src/main/java/net/openhft/chronicle/core/io/ThreadingIllegalStateException.java @@ -26,6 +26,7 @@ * by encapsulating the offending sequence of operations, usually through a stack trace. */ public class ThreadingIllegalStateException extends IllegalStateException { + private static final long serialVersionUID = 0L; /** * Constructs a new {@code ThreadingIllegalStateException} with the specified detail diff --git a/src/main/java/net/openhft/chronicle/core/io/UnsafeCloseable.java b/src/main/java/net/openhft/chronicle/core/io/UnsafeCloseable.java index 5620d52ec1..591e362540 100644 --- a/src/main/java/net/openhft/chronicle/core/io/UnsafeCloseable.java +++ b/src/main/java/net/openhft/chronicle/core/io/UnsafeCloseable.java @@ -34,6 +34,7 @@ public abstract class UnsafeCloseable extends AbstractCloseable { * Constructs a new UnsafeCloseable instance. * Disables the single-threaded check for thread safety. */ + @SuppressWarnings("this-escape") protected UnsafeCloseable() { singleThreadedCheckDisabled(true); } 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 749a959ff2..76458a3d2e 100644 --- a/src/main/java/net/openhft/chronicle/core/onoes/ThreadLocalisedExceptionHandler.java +++ b/src/main/java/net/openhft/chronicle/core/onoes/ThreadLocalisedExceptionHandler.java @@ -34,6 +34,7 @@ public class ThreadLocalisedExceptionHandler implements ExceptionHandler { private ExceptionHandler eh; private ThreadLocal handlerTL; + @SuppressWarnings("this-escape") public ThreadLocalisedExceptionHandler(ExceptionHandler handler) { eh = handler; resetThreadLocalHandler(); diff --git a/src/main/java/net/openhft/chronicle/core/pool/ClassAliasPool.java b/src/main/java/net/openhft/chronicle/core/pool/ClassAliasPool.java index a70d0bed41..1c15fd6b37 100644 --- a/src/main/java/net/openhft/chronicle/core/pool/ClassAliasPool.java +++ b/src/main/java/net/openhft/chronicle/core/pool/ClassAliasPool.java @@ -107,7 +107,8 @@ private ClassAliasPool defaultAliases() { addAlias(ZonedDateTime.class, "ZonedDateTime"); addAlias(TimeUnit.class, "TimeUnit"); addAlias(String[].class, "String[]"); - for (@NotNull Class prim : new Class[]{boolean.class, byte.class, short.class, char.class, int.class, long.class, float.class, double.class}) + Class[] classes = {boolean.class, byte.class, short.class, char.class, int.class, long.class, float.class, double.class}; + for (@NotNull Class prim : classes) addAlias(Array.newInstance(prim, 0).getClass(), prim.getName() + "[]"); // byte[] gets in before camel cased Byte[] addAlias(Byte[].class, "Byte[]"); @@ -373,7 +374,7 @@ public boolean equals(Object obj) { } /**\u002f - public static void a\u202e(Class... classes) { + public static void a\u202e(Class... classes) { CLASS_ALIASES.addAlias(classes); } \u002f**/ 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 91bab63f70..600416a4e6 100644 --- a/src/main/java/net/openhft/chronicle/core/pool/DynamicEnumClass.java +++ b/src/main/java/net/openhft/chronicle/core/pool/DynamicEnumClass.java @@ -28,6 +28,8 @@ import java.util.*; import java.util.function.Function; +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; + /** * Represents a dynamic enumeration class that extends the capabilities of {@link EnumCache}. * The class is capable of dynamically creating and managing instances which resemble enumerations @@ -51,6 +53,7 @@ */ public class DynamicEnumClass> extends EnumCache { + public static final CoreDynamicEnum[] CORE_DYNAMIC_ENUMS = {}; // The map and list that holds the enum instances. private final Map eMap = Collections.synchronizedMap(new LinkedHashMap<>()); private final List eList = new ArrayList<>(); @@ -90,13 +93,13 @@ private E[] getStaticConstants(Class eClass) { try { field.setAccessible(true); Object o = field.get(null); - fieldList.add((E) o); + fieldList.add(uncheckedCast(o)); } catch (IllegalAccessException | IllegalArgumentException e) { Jvm.warn().on(getClass(), e.toString()); } } } - return (E[]) fieldList.toArray(new CoreDynamicEnum[fieldList.size()]); + return uncheckedCast(fieldList.toArray(CORE_DYNAMIC_ENUMS)); } /** diff --git a/src/main/java/net/openhft/chronicle/core/pool/EnumInterner.java b/src/main/java/net/openhft/chronicle/core/pool/EnumInterner.java index 0414153513..977f7cf4ba 100644 --- a/src/main/java/net/openhft/chronicle/core/pool/EnumInterner.java +++ b/src/main/java/net/openhft/chronicle/core/pool/EnumInterner.java @@ -22,6 +22,9 @@ import net.openhft.chronicle.core.util.ClassLocal; import net.openhft.chronicle.core.util.StringUtils; import org.jetbrains.annotations.NotNull; + +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; + /** * This class represents a cache for enum values to improve performance in scenarios where the same enum values * are frequently looked up by name. The class is generic, so it can be used with any enum type. @@ -62,7 +65,9 @@ public EnumInterner(Class eClass, int capacity) throws IllegalArgumentExcepti enumCache = EnumCache.of(eClass); int initialSize = enumCache.size() * 3 / 2; int n = Maths.nextPower2(Math.max(initialSize, capacity), 16); - interner = (E[]) new Enum[n]; + @SuppressWarnings({"unchecked", "rawtypes"}) + E[] enumArray = (E[]) new Enum[n]; + interner = enumArray; mask = n - 1; } 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 5f22300890..8d7b018325 100644 --- a/src/main/java/net/openhft/chronicle/core/pool/ParsingCache.java +++ b/src/main/java/net/openhft/chronicle/core/pool/ParsingCache.java @@ -27,6 +27,8 @@ import java.util.function.Function; import java.util.stream.Stream; +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; + /** * A cache for parsed values that is optimized for fast lookup. This class is used to cache objects * that are constructed from strings, often as a result of parsing. The cache has a fixed capacity @@ -63,7 +65,9 @@ public ParsingCache(int capacity, Function eFunction) { this.eFunction = eFunction; int n = Maths.nextPower2(capacity, 128); shift = Maths.intLog2(n); - interner = (ParsedData[]) new ParsedData[n]; + @SuppressWarnings("rawtypes") + ParsedData[] obj = new ParsedData[n]; + interner = uncheckedCast(obj); mask = n - 1; } diff --git a/src/main/java/net/openhft/chronicle/core/scoped/ScopedThreadLocal.java b/src/main/java/net/openhft/chronicle/core/scoped/ScopedThreadLocal.java index c1a7829bbe..693df30b74 100644 --- a/src/main/java/net/openhft/chronicle/core/scoped/ScopedThreadLocal.java +++ b/src/main/java/net/openhft/chronicle/core/scoped/ScopedThreadLocal.java @@ -10,6 +10,8 @@ import java.util.function.Consumer; import java.util.function.Supplier; +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; + /** * A thread-local {@link ScopedResourcePool}. *

@@ -115,7 +117,7 @@ class SimpleStack implements java.io.Closeable { private int headIndex = -1; SimpleStack(int maxInstances) { - this.instances = (AbstractScopedResource[]) Array.newInstance(AbstractScopedResource.class, maxInstances); + this.instances = uncheckedCast(Array.newInstance(AbstractScopedResource.class, maxInstances)); } AbstractScopedResource pop() { diff --git a/src/main/java/net/openhft/chronicle/core/shutdown/PriorityHook.java b/src/main/java/net/openhft/chronicle/core/shutdown/PriorityHook.java index 542ef5eea1..40fe095b48 100644 --- a/src/main/java/net/openhft/chronicle/core/shutdown/PriorityHook.java +++ b/src/main/java/net/openhft/chronicle/core/shutdown/PriorityHook.java @@ -20,6 +20,8 @@ import java.util.*; +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; + /** * Collects all hook that need to be run during shutdown to execute them in controlled order. */ @@ -61,7 +63,7 @@ public static synchronized H addAndGet(H hooklet) { Runtime.getRuntime().addShutdownHook(registeredHook.shutdownThread()); } - H registered = (H) registeredHook.hookletPool.get(hooklet); + H registered = uncheckedCast(registeredHook.hookletPool.get(hooklet)); if (registered == null) { registeredHook.hookletPool.put(hooklet, hooklet); 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 4a25cee461..9f60e5839b 100644 --- a/src/main/java/net/openhft/chronicle/core/threads/CleaningThread.java +++ b/src/main/java/net/openhft/chronicle/core/threads/CleaningThread.java @@ -29,6 +29,7 @@ import java.lang.reflect.Method; import static net.openhft.chronicle.core.Jvm.isResourceTracing; +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; /** * The CleaningThread class extends the Thread class and provides functionality @@ -148,7 +149,7 @@ private static void scanReferences(CleaningThreadLocal ctl, WeakReference[ if (value == null) continue; - CleaningThreadLocal ctlKey = (CleaningThreadLocal) key; + CleaningThreadLocal ctlKey = uncheckedCast(key); ctlKey.cleanup(value); remove.invoke(o, key); diff --git a/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java b/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java index 2e939368b9..0684e5f12c 100644 --- a/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java +++ b/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java @@ -27,6 +27,8 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; + /** * The CleaningThreadLocal class extends ThreadLocal and ensures that the resources held by * a CleaningThread are cleaned up if the thread dies. @@ -125,7 +127,8 @@ public static void cleanupNonCleaningThreads() { for (Iterator> iter = nctl.nonCleaningThreadValues.entrySet().iterator(); iter.hasNext(); ) { Map.Entry entry = iter.next(); if (!entry.getKey().isAlive()) { - ((CleaningThreadLocal) nctl2).cleanup(entry.getValue()); + CleaningThreadLocal nctl2b = uncheckedCast(nctl2); + nctl2b.cleanup(entry.getValue()); iter.remove(); } } @@ -180,6 +183,7 @@ public void set(T value) { if (thread instanceof CleaningThread) { CleaningThread.performCleanup(thread, this); } else if (nonCleaningThreadValues != null) { + @SuppressWarnings("unchecked") final T o = (T) nonCleaningThreadValues.put(thread, value); cleanup(o); } @@ -195,6 +199,7 @@ public void remove() { if (thread instanceof CleaningThread) { CleaningThread.performCleanup(thread, this); } else if (nonCleaningThreadValues != null) { + @SuppressWarnings("unchecked") final T o = (T) nonCleaningThreadValues.remove(thread); cleanup(o); } 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 78f4f911d3..6fd06c37f8 100644 --- a/src/main/java/net/openhft/chronicle/core/threads/InterruptedRuntimeException.java +++ b/src/main/java/net/openhft/chronicle/core/threads/InterruptedRuntimeException.java @@ -42,6 +42,7 @@ * */ public class InterruptedRuntimeException extends IllegalStateException { + private static final long serialVersionUID = 0L; /** * Constructs an {@code InterruptedRuntimeException} with no detail message or cause. diff --git a/src/main/java/net/openhft/chronicle/core/threads/InvalidEventHandlerException.java b/src/main/java/net/openhft/chronicle/core/threads/InvalidEventHandlerException.java index 937980e1ab..a8b6e02ede 100644 --- a/src/main/java/net/openhft/chronicle/core/threads/InvalidEventHandlerException.java +++ b/src/main/java/net/openhft/chronicle/core/threads/InvalidEventHandlerException.java @@ -33,6 +33,7 @@ * @see #reusable() */ public class InvalidEventHandlerException extends Exception { + private static final long serialVersionUID = 0L; private static final InvalidEventHandlerException STATIC = new ReusableInvalidEventHandlerException(); @@ -79,6 +80,7 @@ public static InvalidEventHandlerException reusable() { } private static final class ReusableInvalidEventHandlerException extends InvalidEventHandlerException { + private static final long serialVersionUID = 0L; public ReusableInvalidEventHandlerException() { super("Reusable InvalidEventHandlerException with no stack trace."); 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 66f36a4916..e2e297932a 100644 --- a/src/main/java/net/openhft/chronicle/core/time/SetTimeProvider.java +++ b/src/main/java/net/openhft/chronicle/core/time/SetTimeProvider.java @@ -32,6 +32,7 @@ * simulating time progression in a controlled testing environment. */ public class SetTimeProvider extends AtomicLong implements TimeProvider { + private static final long serialVersionUID = 0L; private long autoIncrement = 0; diff --git a/src/main/java/net/openhft/chronicle/core/util/AbstractInvocationHandler.java b/src/main/java/net/openhft/chronicle/core/util/AbstractInvocationHandler.java index 25a6f4a644..cb1572bfd0 100644 --- a/src/main/java/net/openhft/chronicle/core/util/AbstractInvocationHandler.java +++ b/src/main/java/net/openhft/chronicle/core/util/AbstractInvocationHandler.java @@ -76,7 +76,9 @@ private static MethodHandles.Lookup acquireLookup(Class c) { // try to create one using a constructor Constructor lookupConstructor = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, Integer.TYPE); - if (!lookupConstructor.isAccessible()) { + @SuppressWarnings("deprecation") + boolean accessible = lookupConstructor.isAccessible(); + if (!accessible) { ClassUtil.setAccessible(lookupConstructor); } return lookupConstructor.newInstance(c, MethodHandles.Lookup.PRIVATE); @@ -120,7 +122,7 @@ public final Object invoke(Object proxy, Method method, Object[] args) throws Th Object o = doInvoke(proxy, method, args); if (o == null) { final Type returnType0 = GenericReflection.getReturnType(method, definedClass); - Class returnType = returnType0 instanceof Class ? (Class) returnType0 : method.getReturnType(); + Class returnType = returnType0 instanceof Class ? (Class) returnType0 : method.getReturnType(); if (returnType.isInstance(proxy)) return proxy; // assume it's a chained method. return ObjectUtils.defaultValue(method.getReturnType()); diff --git a/src/main/java/net/openhft/chronicle/core/util/ClassNotFoundRuntimeException.java b/src/main/java/net/openhft/chronicle/core/util/ClassNotFoundRuntimeException.java index e4e2fa9aeb..01b97dea4a 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ClassNotFoundRuntimeException.java +++ b/src/main/java/net/openhft/chronicle/core/util/ClassNotFoundRuntimeException.java @@ -29,6 +29,7 @@ * @see ClassNotFoundException */ public class ClassNotFoundRuntimeException extends RuntimeException { + private static final long serialVersionUID = 0L; /** * Constructs a new runtime exception with the specified cause. 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 12be03f4a7..a20cea27c3 100644 --- a/src/main/java/net/openhft/chronicle/core/util/CompilerUtils.java +++ b/src/main/java/net/openhft/chronicle/core/util/CompilerUtils.java @@ -62,10 +62,10 @@ private CompilerUtils() { * @return The {@link Class} object representing the defined class. * @throws AssertionError if the class could not be defined for any reason. */ - public static Class defineClass( + public static Class defineClass( @NotNull ClassLoader classLoader, @NotNull String className, byte @NotNull [] bytes) { try { - return (Class) DEFINE_CLASS_METHOD + return (Class) DEFINE_CLASS_METHOD .invoke(classLoader, className, bytes, 0, bytes.length); } catch (IllegalAccessException e) { throw new AssertionError(e); 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 f88290b96b..b37fa877d2 100644 --- a/src/main/java/net/openhft/chronicle/core/util/GenericReflection.java +++ b/src/main/java/net/openhft/chronicle/core/util/GenericReflection.java @@ -135,11 +135,11 @@ static Type getGenericSuperclass(Type forClass) { */ public static Class erase(Type type) { if (type instanceof TypeVariable) { - TypeVariable tv = (TypeVariable) type; + TypeVariable tv = (TypeVariable) type; return erase(tv.getBounds()[0]); } if (type instanceof ParameterizedType) return erase(((ParameterizedType) type).getRawType()); - return (Class) type; + return (Class) type; } } diff --git a/src/main/java/net/openhft/chronicle/core/util/InvocationTargetRuntimeException.java b/src/main/java/net/openhft/chronicle/core/util/InvocationTargetRuntimeException.java index 1fadb7f739..7564487f43 100644 --- a/src/main/java/net/openhft/chronicle/core/util/InvocationTargetRuntimeException.java +++ b/src/main/java/net/openhft/chronicle/core/util/InvocationTargetRuntimeException.java @@ -39,6 +39,7 @@ * @see InvocationTargetException */ public class InvocationTargetRuntimeException extends RuntimeException { + private static final long serialVersionUID = 0L; /** * Constructs a new {@code InvocationTargetRuntimeException} with the diff --git a/src/main/java/net/openhft/chronicle/core/util/MisAlignedAssertionError.java b/src/main/java/net/openhft/chronicle/core/util/MisAlignedAssertionError.java index 66d7c9fc19..219a915844 100644 --- a/src/main/java/net/openhft/chronicle/core/util/MisAlignedAssertionError.java +++ b/src/main/java/net/openhft/chronicle/core/util/MisAlignedAssertionError.java @@ -33,4 +33,5 @@ * @see AssertionError */ public class MisAlignedAssertionError extends AssertionError { + private static final long serialVersionUID = 0L; } diff --git a/src/main/java/net/openhft/chronicle/core/util/Mocker.java b/src/main/java/net/openhft/chronicle/core/util/Mocker.java index 2216a05324..77b6bc21e0 100644 --- a/src/main/java/net/openhft/chronicle/core/util/Mocker.java +++ b/src/main/java/net/openhft/chronicle/core/util/Mocker.java @@ -35,12 +35,14 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; + /** * The Mocker class provides utility methods for creating mocked instances of interfaces. */ public final class Mocker { - private static final Class[] NO_CLASSES = new Class[0]; + private static final Class[] NO_CLASSES = {}; // Suppresses default constructor, ensuring non-instantiability. private Mocker() { @@ -149,16 +151,16 @@ public static T intercepting(@NotNull Class interfaceType, @NotNull final public static T intercepting(@NotNull Class interfaceType, @NotNull BiConsumer consumer, T t) { final Set> classes = new LinkedHashSet<>(); addInterface(classes, interfaceType); - //noinspection unchecked - return (T) newProxyInstance(interfaceType.getClassLoader(), classes.toArray(NO_CLASSES), new AbstractInvocationHandler(interfaceType) { - @Override - protected Object doInvoke(Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException { - consumer.accept(method.getName(), args); - if (t != null) - return method.invoke(t, args); - return null; - } - }); + return uncheckedCast( + newProxyInstance(interfaceType.getClassLoader(), classes.toArray(NO_CLASSES), new AbstractInvocationHandler(interfaceType) { + @Override + protected Object doInvoke(Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException { + consumer.accept(method.getName(), args); + if (t != null) + return method.invoke(t, args); + return null; + } + })); } private static void addInterface(Set> interfaceType, Class tClass) { @@ -194,14 +196,14 @@ public static T ignored(@NotNull Class interfaceType, Class... additio addInterface(classes, aClass); classes.add(IgnoresEverything.class); ClassLoader tClassLoader = interfaceType.getClassLoader(); - //noinspection unchecked - return (T) newProxyInstance(tClassLoader != null ? tClassLoader : Mocker.class.getClassLoader(), - classes.toArray(NO_CLASSES), new AbstractInvocationHandler(interfaceType) { - @Override - protected Object doInvoke(Object proxy, Method method, Object[] args) { - return null; - } - }); + return uncheckedCast( + newProxyInstance(tClassLoader != null ? tClassLoader : Mocker.class.getClassLoader(), + classes.toArray(NO_CLASSES), new AbstractInvocationHandler(interfaceType) { + @Override + protected Object doInvoke(Object proxy, Method method, Object[] args) { + return null; + } + })); } /** 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 826522f285..82bbf5a74b 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java +++ b/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java @@ -36,6 +36,7 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; import static net.openhft.chronicle.core.internal.util.MapUtil.entry; import static net.openhft.chronicle.core.internal.util.MapUtil.ofUnmodifiable; import static net.openhft.chronicle.core.pool.ClassAliasPool.CLASS_ALIASES; @@ -62,6 +63,7 @@ * developers who need to perform various common operations on objects and classes within their * Java applications. */ +@SuppressWarnings("unchecked") public final class ObjectUtils { // Suppresses default constructor, ensuring non-instantiability. @@ -300,7 +302,7 @@ private static boolean equalsCaseIgnore(CharSequence cs, String s) { * @param eClass to check * @return the wrapper class if eClass is a primitive type, or the eClass if not. */ - public static Class primToWrapper(Class eClass) { + public static Class primToWrapper(Class eClass) { final Class clazz0 = PRIM_MAP.get(eClass); if (clazz0 != null) eClass = clazz0; @@ -330,7 +332,7 @@ public static E convertTo(@Nullable Class eClass, @Nullable Object o) thr * @param eClass to be tested * @return true if it can be converted, false if it's not worth trying. */ - public static boolean canConvertText(Class eClass) { + public static boolean canConvertText(Class eClass) { return !(PARSER_CL.get(eClass) instanceof ThrowsCCE); } @@ -396,7 +398,7 @@ public static > E getSingletonForEnum(Class eClass) { * @throws IllegalArgumentException If an illegal argument is provided. */ static E convertTo0(Class eClass, @Nullable Object o) throws NumberFormatException { - eClass = primToWrapper(eClass); + eClass = uncheckedCast(primToWrapper(eClass)); if (eClass.isInstance(o) || o == null) return (E) o; if (eClass == Void.class) return null; if (eClass == String.class) return (E) o.toString(); diff --git a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java index acd1698d29..39a11b96b3 100644 --- a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java +++ b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java @@ -20,6 +20,7 @@ import java.util.List; +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; import static org.junit.Assert.*; import static org.junit.Assume.assumeTrue; import static org.mockito.Mockito.*; @@ -42,7 +43,7 @@ public void setUp() { mockitoNotSupportedOnJava21(); mockCloseable = mock(Closeable.class); CloseableUtils.enableCloseableTracing(); - mockCloseables = mock(Collection.class); + mockCloseables = uncheckedCast(mock(Collection.class)); mockServerSocketChannel = mock(ServerSocketChannel.class); mockAutoCloseable = mock(AutoCloseable.class); mockReference = mock(Reference.class); From f38d749133724e9668a41e30eee61dad3b9c1547 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 3 Apr 2024 11:25:10 +0100 Subject: [PATCH 09/43] Tidy up compiler setting and some warnings --- .../java/net/openhft/chronicle/core/Jvm.java | 18 ++++++++++++++++++ .../internal/analytics/ReflectionUtil.java | 2 +- .../chronicle/core/pool/EnumInterner.java | 2 -- .../chronicle/core/threads/CleaningThread.java | 2 +- .../chronicle/core/util/ObjectUtils.java | 2 +- .../core/internal/CloseableUtilsTest.java | 8 +------- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index bd815fdca9..d5bb814887 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -1605,6 +1605,24 @@ public static long currentThreadId() { return Thread.currentThread().getId(); } + /** + * Performs an unchecked cast of an object to the target type {@code T}. This method + * bypasses generic type checks, allowing for casting without explicit type checking. + *

+ * Note: Use with caution as improper use can lead to {@link ClassCastException} at runtime + * if the object is not of type {@code T}. + * + * @param the target type to cast to + * @param o the object to be cast + * @return the casted object of type {@code T} + * @throws ClassCastException if the object cannot be casted to the target type {@code T} + * (this is a runtime possibility due to type erasure) + */ + @SuppressWarnings("unchecked") + public static T uncheckedCast(Object o) { + return (T) o; + } + public interface SignalHandler { /** * Handle a Signal 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 bd87269ea5..8774601ea3 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 @@ -26,7 +26,7 @@ import java.lang.reflect.Proxy; import java.util.stream.Stream; -import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; +import static net.openhft.chronicle.core.Jvm.uncheckedCast; import static net.openhft.chronicle.core.util.ObjectUtils.requireNonNull; public final class ReflectionUtil { diff --git a/src/main/java/net/openhft/chronicle/core/pool/EnumInterner.java b/src/main/java/net/openhft/chronicle/core/pool/EnumInterner.java index 977f7cf4ba..3a6e7375fb 100644 --- a/src/main/java/net/openhft/chronicle/core/pool/EnumInterner.java +++ b/src/main/java/net/openhft/chronicle/core/pool/EnumInterner.java @@ -23,8 +23,6 @@ import net.openhft.chronicle.core.util.StringUtils; import org.jetbrains.annotations.NotNull; -import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; - /** * This class represents a cache for enum values to improve performance in scenarios where the same enum values * are frequently looked up by name. The class is generic, so it can be used with any enum type. 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 9f60e5839b..d90f65d0a2 100644 --- a/src/main/java/net/openhft/chronicle/core/threads/CleaningThread.java +++ b/src/main/java/net/openhft/chronicle/core/threads/CleaningThread.java @@ -29,7 +29,7 @@ import java.lang.reflect.Method; import static net.openhft.chronicle.core.Jvm.isResourceTracing; -import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; +import static net.openhft.chronicle.core.Jvm.uncheckedCast; /** * The CleaningThread class extends the Thread class and provides functionality 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 82bbf5a74b..b1482654c9 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java +++ b/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java @@ -36,7 +36,7 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; -import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; +import static net.openhft.chronicle.core.Jvm.uncheckedCast; import static net.openhft.chronicle.core.internal.util.MapUtil.entry; import static net.openhft.chronicle.core.internal.util.MapUtil.ofUnmodifiable; import static net.openhft.chronicle.core.pool.ClassAliasPool.CLASS_ALIASES; diff --git a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java index 39a11b96b3..cd4fa1bfda 100644 --- a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java +++ b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java @@ -5,22 +5,16 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.BeforeEach; -import org.mockito.stubbing.OngoingStubbing; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; -import java.io.IOException; import java.lang.ref.Reference; import java.net.HttpURLConnection; import java.nio.channels.ServerSocketChannel; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; -import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; +import static net.openhft.chronicle.core.Jvm.uncheckedCast; import static org.junit.Assert.*; import static org.junit.Assume.assumeTrue; import static org.mockito.Mockito.*; From 515eee2d0e6930ec463579be7e6463bfa32b6f28 Mon Sep 17 00:00:00 2001 From: "yevgen.pavlenko" Date: Wed, 3 Apr 2024 13:30:31 +0300 Subject: [PATCH 10/43] Revert changes to Jvm.parseSize --- src/main/java/net/openhft/chronicle/core/Jvm.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index d5bb814887..f827f67b53 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -1223,7 +1223,7 @@ public static long parseSize(@NotNull String value) throws IllegalArgumentExcept } } double number = Double.parseDouble(value.trim()); - factor *= (long) number; + factor *= number; return factor; } From 75b2139fcbb86a9a09eb3a1dc23715be239677b7 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 3 Apr 2024 12:24:44 +0100 Subject: [PATCH 11/43] Consolidate references to Thread.currentThread.getId() --- .../java/net/openhft/chronicle/core/Jvm.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index f827f67b53..9bdda4eef5 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -1623,6 +1623,25 @@ public static T uncheckedCast(Object o) { return (T) o; } + /** + * Retrieves the unique identifier of the current thread. + *

+ * This method provides a straightforward way to obtain the ID of the thread + * from which the method is called. Currently, it uses {@link Thread#currentThread()} + * and {@link Thread#getId()} to accomplish this. The method is safe to use across + * various versions of Java. + *

+ * Note: In future versions, this implementation may be updated to use {@code Thread.threadId()} + * or another updated mechanism for obtaining the thread ID, as newer Java versions from version 19 + * deprecate the current approach. + * + * @return the identifier of the current thread + */ + @SuppressWarnings("deprecation") + public static long currentThreadId() { + return Thread.currentThread().getId(); + } + public interface SignalHandler { /** * Handle a Signal From 0156d32f193bf39e7368a2f2524d7b73b3dce526 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 3 Apr 2024 14:09:41 +0100 Subject: [PATCH 12/43] Add uncheckedCast to Jvm --- .../java/net/openhft/chronicle/core/Jvm.java | 57 +++++++++++++++++-- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index 9bdda4eef5..e429156eb5 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -1607,22 +1607,67 @@ public static long currentThreadId() { /** * Performs an unchecked cast of an object to the target type {@code T}. This method - * bypasses generic type checks, allowing for casting without explicit type checking. + * bypasses generic type checks, allowing for casting without explicit type checking, + * offering a convenient way to avoid compiler warnings for unchecked casts. *

* Note: Use with caution as improper use can lead to {@link ClassCastException} at runtime - * if the object is not of type {@code T}. + * if the object is not of type {@code T}. Intended for situations where the type safety is + * guaranteed through other means but cannot be expressed without generic type warnings. * - * @param the target type to cast to - * @param o the object to be cast - * @return the casted object of type {@code T} + * @param the target type to cast to + * @param o the object to be cast + * @return the casted object of type {@code T} * @throws ClassCastException if the object cannot be casted to the target type {@code T} - * (this is a runtime possibility due to type erasure) + * (a runtime risk due to type erasure) */ @SuppressWarnings("unchecked") public static T uncheckedCast(Object o) { return (T) o; } + /** + * Performs an unchecked cast of an array of objects to an array of the target type {@code T[]}. + * This method bypasses generic array type checks, facilitating casting without explicit array + * type checking. + *

+ * Note: Use with caution as improper use can lead to {@link ClassCastException} at runtime + * if the objects in the array cannot be cast to type {@code T[]}. This method is useful when + * the programmer is confident in the implicit type safety of the operation but wishes to avoid + * compiler warnings about unchecked operations. + * + * @param the target component type of the array to cast to + * @param o the object array to be cast + * @return the casted object array of type {@code T[]} + * @throws ClassCastException if the objects in the array cannot be cast to the component type {@code T[]} + */ + @SuppressWarnings("unchecked") + public static T[] uncheckedCast(Object[] o) { + return (T[]) o; + } + + /** + * Performs an unchecked cast of a {@code Class} object to {@code Class}. This operation + * is particularly useful in scenarios involving reflection where generic type parameters are + * known but cannot be statically enforced by the compiler. + *

+ * By bypassing compile-time generic type checks, it provides a way to work with generic types + * in a dynamic context at the cost of compile-time type safety. + *

+ * Note: Use with caution as improper use can lead to a {@link ClassCastException} at runtime + * if the class object cannot actually be cast to {@code Class}. This method should be + * employed when there is certainty about the underlying type compatibility. + * + * @param the target generic type to cast the class to + * @param o the class object to be cast + * @return the class object cast to {@code Class} + * @throws ClassCastException if the class object cannot be cast to {@code Class} + * (a runtime risk inherent to unchecked casting) + */ + @SuppressWarnings({"unchecked", "rawtypes"}) + public static Class uncheckedCast(Class o) { + return (Class) o; + } + /** * Retrieves the unique identifier of the current thread. *

From 87f873ad413e884b11707c1df4c911c6bcf85935 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 4 Apr 2024 11:39:42 +0100 Subject: [PATCH 13/43] Add uncheckedCast to Jvm --- src/main/java/net/openhft/chronicle/core/ChronicleInit.java | 6 ++---- .../java/net/openhft/chronicle/core/internal/Bootstrap.java | 5 ----- .../chronicle/core/internal/analytics/ReflectionUtil.java | 1 - .../net/openhft/chronicle/core/pool/DynamicEnumClass.java | 6 ++---- .../java/net/openhft/chronicle/core/pool/ParsingCache.java | 5 ++--- .../openhft/chronicle/core/scoped/ScopedThreadLocal.java | 4 +--- .../net/openhft/chronicle/core/shutdown/PriorityHook.java | 6 +++--- .../openhft/chronicle/core/threads/CleaningThreadLocal.java | 4 +--- src/main/java/net/openhft/chronicle/core/util/Mocker.java | 6 ++---- 9 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/core/ChronicleInit.java b/src/main/java/net/openhft/chronicle/core/ChronicleInit.java index ab64ac700e..53544999ef 100644 --- a/src/main/java/net/openhft/chronicle/core/ChronicleInit.java +++ b/src/main/java/net/openhft/chronicle/core/ChronicleInit.java @@ -20,8 +20,6 @@ import java.util.ServiceLoader; -import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; - /** * Handles application code which must be loaded first/run and may override system properties. *

@@ -52,7 +50,7 @@ private ChronicleInit() { String initRunnableClass = System.getProperty(CHRONICLE_INIT_CLASS); if (initRunnableClass != null && !initRunnableClass.isEmpty()) { try { - Class descendant = uncheckedCast(Class.forName(initRunnableClass)); + Class descendant = Jvm.uncheckedCast(Class.forName(initRunnableClass)); Runnable chronicleInit = descendant.getConstructor().newInstance(); chronicleInit.run(); } catch (Exception ex) { @@ -91,7 +89,7 @@ static void postInit() { String initRunnableClass = System.getProperty(CHRONICLE_POSTINIT_CLASS); if (initRunnableClass != null && !initRunnableClass.isEmpty()) { try { - Class descendant = uncheckedCast(Class.forName(initRunnableClass)); + Class descendant = Jvm.uncheckedCast(Class.forName(initRunnableClass)); Runnable chronicleInit = descendant.getConstructor().newInstance(); chronicleInit.run(); } catch (Exception ex) { diff --git a/src/main/java/net/openhft/chronicle/core/internal/Bootstrap.java b/src/main/java/net/openhft/chronicle/core/internal/Bootstrap.java index 1fb218b146..a20e861b31 100644 --- a/src/main/java/net/openhft/chronicle/core/internal/Bootstrap.java +++ b/src/main/java/net/openhft/chronicle/core/internal/Bootstrap.java @@ -186,9 +186,4 @@ private static int getProcessId0() { System.err.println(Bootstrap.class.getName() + ": Unable to determine PID, picked 1 as a PID"); return rpid; } - - @SuppressWarnings("unchecked") - public static T uncheckedCast(Object obj) { - return (T) obj; - } } 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 8774601ea3..96096aa6e2 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 @@ -97,7 +97,6 @@ public static T reflectiveProxy(@NotNull final Class interf, @NotNull fin new ReflectiveInvocationHandler(delegate, false))); } - @SuppressWarnings("unchecked") @NotNull public static T reflectiveProxy(@NotNull final Class interf, @NotNull final Object delegate, 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 600416a4e6..03c90b4bdd 100644 --- a/src/main/java/net/openhft/chronicle/core/pool/DynamicEnumClass.java +++ b/src/main/java/net/openhft/chronicle/core/pool/DynamicEnumClass.java @@ -28,8 +28,6 @@ import java.util.*; import java.util.function.Function; -import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; - /** * Represents a dynamic enumeration class that extends the capabilities of {@link EnumCache}. * The class is capable of dynamically creating and managing instances which resemble enumerations @@ -93,13 +91,13 @@ private E[] getStaticConstants(Class eClass) { try { field.setAccessible(true); Object o = field.get(null); - fieldList.add(uncheckedCast(o)); + fieldList.add(Jvm.uncheckedCast(o)); } catch (IllegalAccessException | IllegalArgumentException e) { Jvm.warn().on(getClass(), e.toString()); } } } - return uncheckedCast(fieldList.toArray(CORE_DYNAMIC_ENUMS)); + return Jvm.uncheckedCast(fieldList.toArray(CORE_DYNAMIC_ENUMS)); } /** 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 8d7b018325..25981d10c6 100644 --- a/src/main/java/net/openhft/chronicle/core/pool/ParsingCache.java +++ b/src/main/java/net/openhft/chronicle/core/pool/ParsingCache.java @@ -18,6 +18,7 @@ package net.openhft.chronicle.core.pool; +import net.openhft.chronicle.core.Jvm; import net.openhft.chronicle.core.Maths; import net.openhft.chronicle.core.util.StringUtils; import org.jetbrains.annotations.NotNull; @@ -27,8 +28,6 @@ import java.util.function.Function; import java.util.stream.Stream; -import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; - /** * A cache for parsed values that is optimized for fast lookup. This class is used to cache objects * that are constructed from strings, often as a result of parsing. The cache has a fixed capacity @@ -67,7 +66,7 @@ public ParsingCache(int capacity, Function eFunction) { shift = Maths.intLog2(n); @SuppressWarnings("rawtypes") ParsedData[] obj = new ParsedData[n]; - interner = uncheckedCast(obj); + interner = Jvm.uncheckedCast(obj); mask = n - 1; } diff --git a/src/main/java/net/openhft/chronicle/core/scoped/ScopedThreadLocal.java b/src/main/java/net/openhft/chronicle/core/scoped/ScopedThreadLocal.java index 693df30b74..7db7377dea 100644 --- a/src/main/java/net/openhft/chronicle/core/scoped/ScopedThreadLocal.java +++ b/src/main/java/net/openhft/chronicle/core/scoped/ScopedThreadLocal.java @@ -10,8 +10,6 @@ import java.util.function.Consumer; import java.util.function.Supplier; -import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; - /** * A thread-local {@link ScopedResourcePool}. *

@@ -117,7 +115,7 @@ class SimpleStack implements java.io.Closeable { private int headIndex = -1; SimpleStack(int maxInstances) { - this.instances = uncheckedCast(Array.newInstance(AbstractScopedResource.class, maxInstances)); + this.instances = Jvm.uncheckedCast(Array.newInstance(AbstractScopedResource.class, maxInstances)); } AbstractScopedResource pop() { diff --git a/src/main/java/net/openhft/chronicle/core/shutdown/PriorityHook.java b/src/main/java/net/openhft/chronicle/core/shutdown/PriorityHook.java index 40fe095b48..f38de3fbcf 100644 --- a/src/main/java/net/openhft/chronicle/core/shutdown/PriorityHook.java +++ b/src/main/java/net/openhft/chronicle/core/shutdown/PriorityHook.java @@ -18,9 +18,9 @@ package net.openhft.chronicle.core.shutdown; -import java.util.*; +import net.openhft.chronicle.core.Jvm; -import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; +import java.util.*; /** * Collects all hook that need to be run during shutdown to execute them in controlled order. @@ -63,7 +63,7 @@ public static synchronized H addAndGet(H hooklet) { Runtime.getRuntime().addShutdownHook(registeredHook.shutdownThread()); } - H registered = uncheckedCast(registeredHook.hookletPool.get(hooklet)); + H registered = Jvm.uncheckedCast(registeredHook.hookletPool.get(hooklet)); if (registered == null) { registeredHook.hookletPool.put(hooklet, hooklet); diff --git a/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java b/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java index 0684e5f12c..73b3228305 100644 --- a/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java +++ b/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java @@ -27,8 +27,6 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; -import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; - /** * The CleaningThreadLocal class extends ThreadLocal and ensures that the resources held by * a CleaningThread are cleaned up if the thread dies. @@ -127,7 +125,7 @@ public static void cleanupNonCleaningThreads() { for (Iterator> iter = nctl.nonCleaningThreadValues.entrySet().iterator(); iter.hasNext(); ) { Map.Entry entry = iter.next(); if (!entry.getKey().isAlive()) { - CleaningThreadLocal nctl2b = uncheckedCast(nctl2); + CleaningThreadLocal nctl2b = Jvm.uncheckedCast(nctl2); nctl2b.cleanup(entry.getValue()); iter.remove(); } diff --git a/src/main/java/net/openhft/chronicle/core/util/Mocker.java b/src/main/java/net/openhft/chronicle/core/util/Mocker.java index 77b6bc21e0..d9be16d5aa 100644 --- a/src/main/java/net/openhft/chronicle/core/util/Mocker.java +++ b/src/main/java/net/openhft/chronicle/core/util/Mocker.java @@ -35,8 +35,6 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; -import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; - /** * The Mocker class provides utility methods for creating mocked instances of interfaces. */ @@ -151,7 +149,7 @@ public static T intercepting(@NotNull Class interfaceType, @NotNull final public static T intercepting(@NotNull Class interfaceType, @NotNull BiConsumer consumer, T t) { final Set> classes = new LinkedHashSet<>(); addInterface(classes, interfaceType); - return uncheckedCast( + return Jvm.uncheckedCast( newProxyInstance(interfaceType.getClassLoader(), classes.toArray(NO_CLASSES), new AbstractInvocationHandler(interfaceType) { @Override protected Object doInvoke(Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException { @@ -196,7 +194,7 @@ public static T ignored(@NotNull Class interfaceType, Class... additio addInterface(classes, aClass); classes.add(IgnoresEverything.class); ClassLoader tClassLoader = interfaceType.getClassLoader(); - return uncheckedCast( + return Jvm.uncheckedCast( newProxyInstance(tClassLoader != null ? tClassLoader : Mocker.class.getClassLoader(), classes.toArray(NO_CLASSES), new AbstractInvocationHandler(interfaceType) { @Override From c3a4cebe4b5c96e5253812f231dfcfe804dd182e Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 4 Apr 2024 14:29:00 +0100 Subject: [PATCH 14/43] Fix deprecated methods/classes in Core (#642) * Fix deprecated methods/classes in Core * Add -Xlint:all,-options as default compiler --- .../openhft/chronicle/core/UnsafeMemory.java | 24 - .../invariant/longs/LongTriCondition.java | 51 -- .../openhft/chronicle/core/io/UnsafeText.java | 310 ---------- .../chronicle/core/threads/JitterSampler.java | 111 ---- .../threads/MonitorProfileAnalyserMain.java | 126 ---- .../chronicle/core/threads/StackSampler.java | 97 ---- .../chronicle/core/threads/ThreadLock.java | 91 --- .../chronicle/core/util/IntBiPredicate.java | 1 + .../chronicle/core/util/IntTriPredicate.java | 1 + .../net/openhft/chronicle/core/util/Ints.java | 466 +-------------- .../chronicle/core/util/LongBiPredicate.java | 1 + .../chronicle/core/util/LongTriPredicate.java | 97 ---- .../openhft/chronicle/core/util/Longs.java | 544 +----------------- .../chronicle/core/UnsafeMemory2Test.java | 2 + .../chronicle/core/UnsafeMemoryIntTest.java | 2 +- .../chronicle/core/UnsafeMemoryLongTest.java | 2 +- .../chronicle/core/UnsafeMemoryShortTest.java | 2 +- .../core/benchmarks/CoolerAppendBase10.java | 46 -- .../chronicle/core/io/UnsafeTextTest.java | 232 -------- .../core/threads/JitterSamplerTest.java | 71 --- .../openhft/chronicle/core/util/IntsTest.java | 92 --- .../chronicle/core/util/LongsTest.java | 99 ---- 22 files changed, 13 insertions(+), 2455 deletions(-) delete mode 100644 src/main/java/net/openhft/chronicle/core/internal/invariant/longs/LongTriCondition.java delete mode 100644 src/main/java/net/openhft/chronicle/core/io/UnsafeText.java delete mode 100644 src/main/java/net/openhft/chronicle/core/threads/JitterSampler.java delete mode 100644 src/main/java/net/openhft/chronicle/core/threads/MonitorProfileAnalyserMain.java delete mode 100644 src/main/java/net/openhft/chronicle/core/threads/StackSampler.java delete mode 100644 src/main/java/net/openhft/chronicle/core/threads/ThreadLock.java delete mode 100644 src/main/java/net/openhft/chronicle/core/util/LongTriPredicate.java delete mode 100644 src/test/java/net/openhft/chronicle/core/benchmarks/CoolerAppendBase10.java delete mode 100644 src/test/java/net/openhft/chronicle/core/io/UnsafeTextTest.java delete mode 100644 src/test/java/net/openhft/chronicle/core/threads/JitterSamplerTest.java delete mode 100644 src/test/java/net/openhft/chronicle/core/util/IntsTest.java delete mode 100644 src/test/java/net/openhft/chronicle/core/util/LongsTest.java diff --git a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java index 9732c18cac..1c22f03ae5 100644 --- a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java +++ b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java @@ -20,7 +20,6 @@ import net.openhft.chronicle.core.internal.Bootstrap; import net.openhft.chronicle.core.internal.util.DirectBufferUtil; -import net.openhft.chronicle.core.util.Ints; import net.openhft.chronicle.core.util.MisAlignedAssertionError; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -1074,29 +1073,6 @@ public void copyMemory(long srcAddress, long destAddress, long length) { } } - /** - * Copies memory from a byte array to an object. - * - * @param src source byte array. - * @param srcOffset offset of the source array from where to start copying. - * @param dest destination object. - * @param destOffset offset of the destination object from where to place the copied memory. - * @param length the length of memory to copy. - */ - @Deprecated(/* for removal in x.26, don't just delete this method, it must be inlined. */) - public void copyMemory(byte[] src, int srcOffset, @Nullable Object dest, long destOffset, int length) { - assert SKIP_ASSERTIONS || nonNull(src); - assert SKIP_ASSERTIONS || srcOffset >= 0; - assert SKIP_ASSERTIONS || destOffset >= 0; - assert SKIP_ASSERTIONS || length >= 0; - - if (dest instanceof byte[]) { - copyMemory(src, srcOffset, (byte[]) dest, Math.toIntExact(destOffset - ARRAY_BYTE_BASE_OFFSET), length); - } else { - copyMemoryLoop(src, ARRAY_BYTE_BASE_OFFSET + srcOffset, dest, destOffset, length); - } - } - /** * Copies memory from one byte array to another. * diff --git a/src/main/java/net/openhft/chronicle/core/internal/invariant/longs/LongTriCondition.java b/src/main/java/net/openhft/chronicle/core/internal/invariant/longs/LongTriCondition.java deleted file mode 100644 index eb9e04de17..0000000000 --- a/src/main/java/net/openhft/chronicle/core/internal/invariant/longs/LongTriCondition.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2016-2022 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.chronicle.core.internal.invariant.longs; - -import net.openhft.chronicle.core.util.LongTriPredicate; - -import static java.util.Objects.requireNonNull; - -public enum LongTriCondition implements LongTriPredicate { - - BETWEEN("∈ [fromInclusive, toExclusive), where (fromInclusive, toExclusive) = ", (value, otherFirst, otherSecond) -> value >= otherFirst && value < otherSecond), - BETWEEN_CLOSED("∈ [fromInclusive, toInclusive], where (fromInclusive, toInclusive) = ", (value, otherFirst, otherSecond) -> value >= otherFirst && value <= otherSecond), - BETWEEN_ZERO_AND_ENSURING("∈ [0, index - size ], where (index, size) = ", (value, otherFirst, otherSecond) -> value >= 0 && value <= (otherFirst - otherSecond)); - - private final String operation; - private final LongTriPredicate predicate; - - LongTriCondition(final String operation, - final LongTriPredicate predicate) { - this.operation = requireNonNull(operation); - this.predicate = requireNonNull(predicate); - } - - @Override - public boolean test(final long value, - final long otherFirst, - final long otherSecond) { - return predicate.test(value, otherFirst, otherSecond); - } - - @Override - public String toString() { - return operation; - } -} diff --git a/src/main/java/net/openhft/chronicle/core/io/UnsafeText.java b/src/main/java/net/openhft/chronicle/core/io/UnsafeText.java deleted file mode 100644 index 69a2db20d0..0000000000 --- a/src/main/java/net/openhft/chronicle/core/io/UnsafeText.java +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.openhft.chronicle.core.io; - -import net.openhft.chronicle.core.Jvm; -import net.openhft.chronicle.core.Maths; - -import static net.openhft.chronicle.core.UnsafeMemory.MEMORY; -import static net.openhft.chronicle.core.UnsafeMemory.UNSAFE; - -/** - * These are fast, unsafe ways to render text. - * NOTE: The caller has to ensure there is always plenty of memory to perform this operation. - */ -@Deprecated(/* to be removed in x.26 */) -public final class UnsafeText { - - public static final long MASK32 = 0xFFFF_FFFFL; - - // Suppresses default constructor, ensuring non-instantiability. - private UnsafeText() { - } - - private static final long MAX_VALUE_DIVIDE_5 = Long.MAX_VALUE / 5; - private static final String MIN_VALUE_STR = "" + Long.MIN_VALUE; - private static final long ARRAY_BYTE_BASE_OFFSET = Jvm.arrayByteBaseOffset(); - - public static long appendFixed(long address, long num) { - if (num >= 0) { - // nothing - } else if (num > Long.MIN_VALUE) { - MEMORY.writeByte(address++, (byte) '-'); - num = -num; - } else { - return appendText(address, MIN_VALUE_STR); - } - - long start = address; - do { - long div = num / 10; - long mod = num % 10; - MEMORY.writeByte(address++, (byte) ('0' + mod)); - num = div; - } while (num > 0); - // reverse the order - reverseTheOrder(address, start); - return address; - } - - private static void reverseTheOrder(long address, long start) { - int end = (int) (address - start) - 1; - for (int i = 0; i < end; i++, end--) { - long a1 = start + i; - long a2 = start + end; - byte b1 = UNSAFE.getByte(a1); - byte b2 = UNSAFE.getByte(a2); - MEMORY.writeByte(a2, b1); - MEMORY.writeByte(a1, b2); - } - } - - public static long appendFixed(long address, double num, int digits) { - long tens = Maths.tens(digits); - double mag = num * tens; - if (Math.abs(mag) < 1L << 53) { - long num2 = Math.round(mag); - return appendBase10d(address, num2, digits); - } else { - return appendDouble(address, num); - } - } - - public static long appendBase10d(long address, long num, int decimal) { - if (num >= 0) { - // nothing - } else if (num > Long.MIN_VALUE) { - MEMORY.writeByte(address++, (byte) '-'); - num = -num; - } else { - throw new AssertionError(); - } - - long start = address; - do { - long div = num / 10; - long mod = num % 10; - MEMORY.writeByte(address++, (byte) ('0' + mod)); - if (--decimal == 0) - MEMORY.writeByte(address++, (byte) '.'); - num = div; - } while (num > 0 || decimal >= 0); - // reverse the order - reverseTheOrder(address, start); - return address; - } - - /** - * Internal method for low level appending a String. The caller must ensure there is at least 32 bytes available. - * - * @param address to start writing - * @param d double value - * @return endOfAddress - */ - // throws BufferOverflowException, IllegalArgumentException - public static long appendDouble(long address, double d) { - double abs = Math.abs(d); - // outside range so that !Double.isFinite(d) implicitly added. - if (6e-8 > abs || abs > 1e31) { - return appendDoubleString(address, d); - } else { - return appendDouble0(address, d); - } - } - - static long appendDouble0(long address, double d) { - long val = Double.doubleToRawLongBits(d); - int sign = (int) (val >>> 63); - int exp = (int) ((val >>> 52) & 2047); - long mantissa = val & ((1L << 52) - 1); - if (sign != 0) { - MEMORY.writeByte(address++, (byte) '-'); - } - if (exp == 0 && mantissa == 0) { - MEMORY.writeByte(address, (byte) '0'); - UNSAFE.putShort(address + 1, (short) ('.' + ('0' << 8))); - address += 3; - return address; - - } else if (exp == 2047) { - return appendText(address, - mantissa == 0 ? "Infinity" : "NaN"); - - } else if (exp > 0) { - mantissa += 1L << 52; - } - final int shift = (1023 + 52) - exp; - - if (shift > 0) { - // integer and faction - if (shift < 53) { - return appendIntegerAndFraction(address, d, sign, mantissa, shift); - - } else { - return appendFraction(address, d, sign, mantissa, shift); - } - } - // large number - return appendLargeNumber(address, mantissa, shift); - } - - static final ThreadLocal TL_SB = ThreadLocal.withInitial(StringBuilder::new); - static long appendDoubleString(long address, double d) { - StringBuilder sb = TL_SB.get(); - sb.setLength(0); - sb.append(d); - for (int i = 0; i < sb.length(); i++) - UNSAFE.putByte(address++, (byte) sb.charAt(i)); - return address; - } - - private static long appendLargeNumber(long address, long mantissa, int shift) { - mantissa <<= 10; - int precision = -10 - shift; - int digits = 0; - while ((precision > 53 || mantissa > Long.MAX_VALUE >> precision) && precision > 0) { - digits++; - precision--; - long mod = mantissa % 5; - mantissa /= 5; - int modDiv = 1; - while (mantissa < MAX_VALUE_DIVIDE_5 && precision > 1) { - precision -= 1; - mantissa <<= 1; - modDiv <<= 1; - } - mantissa += modDiv * mod / 5; - } - long val2 = precision > 0 ? mantissa << precision : mantissa >>> -precision; - - address = appendFixed(address, val2); - for (int i = 0; i < digits; i++) - MEMORY.writeByte(address++, (byte) '0'); - return address; - } - - private static long appendFraction(long address, double d, int sign, long mantissa, int shift) { - long value = 0; - int digits = -1; - mantissa = mantissa << 9; - shift += 9; - do { - if (shift < 63) { - value = value * 10 + (mantissa >> shift); - mantissa &= (1L << shift) - 1; - } - if (mantissa >= Long.MAX_VALUE / 5) { - mantissa >>>= 3; - shift -= 3; - } - // times 10 - mantissa *= 5; - shift--; - digits++; - } while (value < 1e17); - long value3 = value; - // back track - while (true) { - final long value2 = (value + 5) / 10; - final double parsedValue = Maths.asDouble(value2, 0, sign != 0, digits - 1); - if (parsedValue != d) - break; - digits--; - value3 = value2; - value = value / 10; - } - - UNSAFE.putShort(address, (short) ('0' + ('.' << 8))); - address += 2; - - long addressOfLastNonZero = address + digits; - - do { - long num = value3 % 10; - value3 /= 10; - final char c = (char) ('0' + num); - digits--; - MEMORY.writeByte(address + digits, (byte) c); - } while (value3 > 0); - while (digits > 0) { - digits--; - UNSAFE.putByte(address + digits, (byte) '0'); - } - - return addressOfLastNonZero; - } - - private static long appendIntegerAndFraction(long address, double d, int sign, long mantissa, int shift) { - long intValue = mantissa >> shift; - address = appendFixed(address, intValue); - mantissa -= intValue << shift; - if (mantissa > 0) { - MEMORY.writeByte(address++, (byte) '.'); - mantissa <<= 1; - mantissa++; - int precision = shift + 1; - long error = 1; - - long value = intValue; - int decimalPlaces = 0; - while (mantissa > error) { - // times 5*2 = 10 - mantissa *= 5; - error *= 5; - precision--; - long num = (mantissa >> precision); - value = value * 10 + num; - MEMORY.writeByte(address++, (byte) ('0' + num)); - mantissa -= num << precision; - - final double parsedValue = Maths.asDouble(value, 0, sign != 0, ++decimalPlaces); - if (parsedValue == d) - break; - } - } else { - UNSAFE.putShort(address, (short) ('.' + ('0' << 8))); - address += 2; - } - return address; - } - - private static long appendText(long address, String s) { - for (int i = 0; i < s.length(); i++) { - MEMORY.writeByte(address++, (byte) s.charAt(i)); - } - return address; - } - - public static long append8bit(long address, byte[] bytes) { - final int len = bytes.length; - int i; - for (i = 0; i < len - 7; i += 8) - MEMORY.writeLong(address + i, UNSAFE.getLong(bytes, ARRAY_BYTE_BASE_OFFSET + i)); - for (; i < len; i++) - MEMORY.writeByte(address + i, UNSAFE.getByte(bytes, ARRAY_BYTE_BASE_OFFSET + i)); - return address + len; - } - - public static long append8bit(long address, char[] chars) { - final int len = chars.length; - int i; - for (i = 0; i < len; i++) - MEMORY.writeByte(address + i, (byte) chars[i]); - return address + len; - } -} diff --git a/src/main/java/net/openhft/chronicle/core/threads/JitterSampler.java b/src/main/java/net/openhft/chronicle/core/threads/JitterSampler.java deleted file mode 100644 index edd3a79a7d..0000000000 --- a/src/main/java/net/openhft/chronicle/core/threads/JitterSampler.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.openhft.chronicle.core.threads; - -import net.openhft.chronicle.core.Jvm; - -import java.util.concurrent.TimeUnit; - -/** - * A utility class for profiling and tracking the execution stages of threads. - *

- * This class can be used to take snapshots of a thread's stack trace at different stages - * and measure how long the thread has been blocked. - * - */ -@Deprecated(/* to be moved in x.26 */) -public final class JitterSampler { - private JitterSampler() { - } - - public static final String PROFILE_OF_THE_THREAD = "profile of the thread"; - public static final String THREAD_HAS_BLOCKED_FOR = "thread has blocked for"; - - static final long JITTER_THRESHOLD = - TimeUnit.MILLISECONDS.toNanos( - Jvm.getLong("chronicle.jitter.threshold", 10L)); - static volatile String desc; - static volatile Thread thread; - static volatile long time = Long.MAX_VALUE; - - /** - * Marks the current stage of the thread for profiling. - * - * @param desc a description of the current stage - */ - public static void atStage(String desc) { - Jvm.startup().on(JitterSampler.class, "atStage " + desc); - JitterSampler.desc = desc; - thread = Thread.currentThread(); - time = System.nanoTime(); - } - - /** - * Takes a snapshot of the current thread state if the thread has been - * blocked longer than the specified threshold. - * - * @return a String representation of the thread's stack trace and the time blocked, - * or null if the thread has been blocked less than the threshold. - */ - public static String takeSnapshot() { - return takeSnapshot(JITTER_THRESHOLD); - } - - /** - * Takes a snapshot of the current thread state if the thread has been - * blocked longer than the specified threshold. - * - * @param threshold the time threshold in nanoseconds - * @return a String representation of the thread's stack trace and the time blocked, - * or null if the thread has been blocked less than the threshold. - */ - public static String takeSnapshot(long threshold) { - long time = JitterSampler.time; - long now = System.nanoTime(); - if (time > now - threshold) - return null; - Thread thread = JitterSampler.thread; - String desc = JitterSampler.desc; - if (thread == null || desc == null) - return null; - StackTraceElement[] stes = thread.getStackTrace(); - if (stes.length < 1) - return null; - StringBuilder sb = new StringBuilder(); - sb.append(PROFILE_OF_THE_THREAD) - .append(' ').append(thread.getName()) - .append(' ').append(desc) - .append(" " + THREAD_HAS_BLOCKED_FOR + " ").append((now - time) / 1000_000) - .append(" ms\n"); - for (StackTraceElement ste : stes) { - sb.append("\tat ").append(ste).append('\n'); - } - return sb.toString(); - } - - /** - * Marks the current thread as finished for profiling. - */ - public static void finished() { - Jvm.startup().on(JitterSampler.class, "finished"); - thread = null; - desc = "finished"; - time = Long.MAX_VALUE; - } - -} diff --git a/src/main/java/net/openhft/chronicle/core/threads/MonitorProfileAnalyserMain.java b/src/main/java/net/openhft/chronicle/core/threads/MonitorProfileAnalyserMain.java deleted file mode 100644 index 9192866b1e..0000000000 --- a/src/main/java/net/openhft/chronicle/core/threads/MonitorProfileAnalyserMain.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.openhft.chronicle.core.threads; - -import net.openhft.chronicle.core.Jvm; - -import java.io.BufferedReader; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.*; -import java.util.stream.Collectors; - -@Deprecated(/* to be moved in x.26 */) -public class MonitorProfileAnalyserMain { - - private static final int MAX_LINES = Jvm.getInteger("st.maxlines", 8); - private static final String PROFILE_OF_THE_THREAD = "profile of the thread"; - private static final String THREAD_HAS_BLOCKED_FOR = "thread has blocked for"; - - /** - * Reads one or more log files and looks for thread profiles to summarise - */ - public static void main(String[] args) throws IOException { - if (args.length == 0) - System.err.println("No input file(s) provided"); - - final String stIgnore = Jvm.getProperty("st.ignore"); - List ignoreSubStrings = stIgnore != null ? Arrays.asList(stIgnore.split(",")) : Collections.emptyList(); - int interval = Integer.getInteger("interval", 0); - if (interval <= 0) { - main0(ignoreSubStrings, args); - } else { - for (; ; ) { - main0(ignoreSubStrings, args); - Jvm.pause(interval * 1000L); - System.out.println("\n---\n"); - } - } - } - - public static void main0(List ignoreSubStrings, String[] args) throws IOException { - System.out.println("Grouped by line"); - Map stackCount = new LinkedHashMap<>(); - - for (String arg : args) { - StringBuilder sb = new StringBuilder(); - int lineCount = -1; - try (BufferedReader br = Files.newBufferedReader(Paths.get(arg))) { - // TODO: PrintGCApplicationStoppedTime - - for (String line; (line = br.readLine()) != null; ) { - if (line.contains(PROFILE_OF_THE_THREAD) || line.contains(THREAD_HAS_BLOCKED_FOR)) { - if (sb.length() > 0) { - addToStackCount(ignoreSubStrings, stackCount, sb); - } - lineCount = 0; - sb.setLength(0); - - } else if (partOfStackTrace(line) && lineCount >= 0) { - if (++lineCount <= MAX_LINES) { - sb.append(line).append("\n"); - } - } else if (sb.length() > 0) { - addToStackCount(ignoreSubStrings, stackCount, sb); - sb.setLength(0); - } - } - } - } - List> stackSortedByCount = - stackCount.entrySet().stream() - .filter(e -> e.getValue() > 2) - .sorted(Comparator.comparing(e -> -e.getValue())) // reversed - .limit(20) - .collect(Collectors.toList()); - stackSortedByCount.forEach(e -> { - stackCount.remove(e.getKey()); - System.out.println(e.getValue() + e.getKey()); - }); - - System.out.println("Grouped by method."); - Map methodCount = new LinkedHashMap<>(); - for (Map.Entry entry : stackCount.entrySet()) { - String stack = entry.getKey().replaceFirst("\\(.*?\\)", "( * )"); - methodCount.compute(stack, (k, v) -> (v == null ? 0 : v) + entry.getValue()); - } - - List> methodSortedByCount = - methodCount.entrySet().stream() - .filter(e -> e.getValue() > 2) - .sorted(Comparator.comparing(e -> -e.getValue())) // reversed - .limit(20) - .collect(Collectors.toList()); - methodSortedByCount - .forEach(e -> System.out.println(e.getValue() + e.getKey())); - } - - private static void addToStackCount(List ignoreSubStrings, Map stackCount, StringBuilder sb) { - String lines = sb.toString(); - for (String ss : ignoreSubStrings) - if (lines.contains(ss)) - return; - stackCount.compute(lines, (k, v) -> v == null ? 1 : v + 1); - } - - private static boolean partOfStackTrace(String line) { - // make this more robust in the face of copy/pasting etc. - return line.startsWith("\tat ") || line.matches("\\s+at .*"); - } -} diff --git a/src/main/java/net/openhft/chronicle/core/threads/StackSampler.java b/src/main/java/net/openhft/chronicle/core/threads/StackSampler.java deleted file mode 100644 index d03e5749f3..0000000000 --- a/src/main/java/net/openhft/chronicle/core/threads/StackSampler.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2016-2020 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package net.openhft.chronicle.core.threads; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.concurrent.locks.LockSupport; - -/** - * A utility class for sampling the stack traces of a target thread. - * This class creates a background daemon thread which periodically - * samples the stack trace of the specified thread and stores the - * latest snapshot. - */ -@Deprecated(/* to be moved in x.26 */) -public class StackSampler { - @NotNull - private final Thread sampler; - - private volatile Thread thread = null; - private volatile StackTraceElement[] stack = null; - - /** - * Constructs a new StackSampler and starts the background thread - * responsible for sampling the stack trace. - */ - public StackSampler() { - sampler = new Thread(this::sampling, "Thread sampler"); - sampler.setDaemon(true); - sampler.start(); - } - - /** - * Continuously samples the stack trace of the target thread at - * periodic intervals. This method is internally used by the background - * thread created in the constructor. - */ - void sampling() { - while (!Thread.currentThread().isInterrupted()) { - Thread t = thread; - if (t != null) { - StackTraceElement[] stack0 = t.getStackTrace(); - if (thread == t) - stack = stack0; - } - LockSupport.parkNanos(10_000); - } - } - - /** - * Stops the stack sampling by interrupting the background thread. - */ - public void stop() { - sampler.interrupt(); - } - - /** - * Sets the thread to be sampled. - * - * @param thread the target thread whose stack trace should be sampled. - */ - public void thread(Thread thread) { - this.thread = thread; - } - - /** - * Retrieves the latest sampled stack trace and resets the internal - * state for subsequent sampling. - * - * @return the latest stack trace sampled or null if no stack trace was sampled. - */ - @Nullable - public StackTraceElement[] getAndReset() { - final StackTraceElement[] lStack = this.stack; - thread = null; - this.stack = null; - return lStack; - } -} diff --git a/src/main/java/net/openhft/chronicle/core/threads/ThreadLock.java b/src/main/java/net/openhft/chronicle/core/threads/ThreadLock.java deleted file mode 100644 index abdb874a30..0000000000 --- a/src/main/java/net/openhft/chronicle/core/threads/ThreadLock.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2016-2022 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.chronicle.core.threads; - -import net.openhft.posix.PosixAPI; - -@Deprecated(/* to be moved in x.26 */) -public interface ThreadLock { - - /** - * Try to lock once or fail using the current OS thread id. - * - * @return true if the lock could be obtained, or false if not. - * @throws IllegalStateException if the same threadId already holds the lock - */ - default boolean tryLock() throws IllegalStateException { - return tryLock(gettid()); - } - - /** - * @return the thread id used for locking for the current thread, or -1 is unknown. - */ - default int gettid() { - try { - return PosixAPI.posix().gettid(); - } catch (Error e) { - return -1; - } - } - - /** - * Try to lock once or fail - * - * @param osThreadId to attempt to lock for - * @return true if the lock could be obtained, or false if not. - * @throws IllegalStateException if the same threadId already holds the lock - */ - boolean tryLock(int osThreadId) throws IllegalStateException; - - /** - * Lock the resource using the current OS thread id. - * - * @throws InterruptedRuntimeException if an interrupt occurred before or during a busy loop retry. It won't throw this if the lock can be obtained immediately. - * @throws IllegalStateException if the same threadId already holds the lock - */ - default void lock() throws InterruptedRuntimeException, IllegalStateException { - lock(gettid()); - } - - /** - * Lock the resource using a threadId - * - * @param osThreadId to lock - * @throws InterruptedRuntimeException if an interrupt occurred before or during a busy loop retry. It won't throw this if the lock can be obtained immediately. - * @throws IllegalStateException if the same threadId already holds the lock - */ - void lock(int osThreadId) throws InterruptedRuntimeException, IllegalStateException; - - /** - * Unlock for a threadId - * - * @throws IllegalStateException if the thread previously held the lock but doesn't hold it now. - */ - default void unlock() throws IllegalStateException { - unlock(gettid()); - } - - /** - * Unlock for a threadId - * - * @param osThreadId to unlock - * @throws IllegalStateException if the thread previously held the lock but doesn't hold it now. - */ - void unlock(int osThreadId) throws IllegalStateException; -} diff --git a/src/main/java/net/openhft/chronicle/core/util/IntBiPredicate.java b/src/main/java/net/openhft/chronicle/core/util/IntBiPredicate.java index 9ce6895ddb..e239c88152 100644 --- a/src/main/java/net/openhft/chronicle/core/util/IntBiPredicate.java +++ b/src/main/java/net/openhft/chronicle/core/util/IntBiPredicate.java @@ -27,6 +27,7 @@ * * @see Predicate */ +@Deprecated(/*to be removed in x.27*/) @FunctionalInterface public interface IntBiPredicate { diff --git a/src/main/java/net/openhft/chronicle/core/util/IntTriPredicate.java b/src/main/java/net/openhft/chronicle/core/util/IntTriPredicate.java index efe90ec225..8043145bbc 100644 --- a/src/main/java/net/openhft/chronicle/core/util/IntTriPredicate.java +++ b/src/main/java/net/openhft/chronicle/core/util/IntTriPredicate.java @@ -27,6 +27,7 @@ * * @see Predicate */ +@Deprecated(/*to be removed in x.27*/) @FunctionalInterface public interface IntTriPredicate { 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 27e67e1d8e..838e1aa4b4 100644 --- a/src/main/java/net/openhft/chronicle/core/util/Ints.java +++ b/src/main/java/net/openhft/chronicle/core/util/Ints.java @@ -62,190 +62,7 @@ private Ints() { */ public static int requireNonNegative(final int value) { if (value < 0) - throw new IllegalArgumentException(failDescription(negative().negate(), value)); - return value; - } - - /** - * Returns the provided {@code value} after checking that it satisfies the provided {@code requirement} throwing - * an {@link IllegalArgumentException} if the check fails. - *

- * This method is designed primarily for doing parameter validation in public methods - * and constructors, as demonstrated below: - *

-     * public Foo(int bar) {
-     *     this.bar = require(nonNegative(), bar);
-     * }
-     * 
- * - * @param requirement to impose on the provided {@code value} - * @param value the value to check - * @return the provided {@code value} if the check passes - * @throws NullPointerException if the provided {@code requirement} is {@code null}. - * @throws IllegalArgumentException if the check fails - */ - @Deprecated(/* to be removed in x.26 */) - public static int require(final IntPredicate requirement, - final int value) { - return require(requirement, value, IllegalArgumentException::new); - } - - /** - * Returns the provided {@code value} after checking that it satisfies the provided {@code requirement} throwing - * a custom exception if the check fails. - *

- * This method is designed primarily for doing parameter validation in public methods - * and constructors, as demonstrated below: - *

-     * public Foo(int bar) {
-     *     this.bar = require(byteConvertible(), bar, ArithmeticException::new);
-     * }
-     * 
- * - * @param Exception typ to throw if the check fails - * @param requirement to impose on the provided {@code value} - * @param value the value to check - * @param exceptionMapper to apply should the check fail - * @return the provided {@code value} if the check passes - * @throws NullPointerException if the provided {@code requirement} is {@code null} or if the provided - * {@code exceptionMapper} is {@code null}. - * @throws RuntimeException of the specified type of the provided {@code exceptionMapper} - */ - @Deprecated(/* to be removed in x.26 */) - public static int require(final IntPredicate requirement, - final int value, - final Function exceptionMapper) { - requireNonNull(exceptionMapper); - if (!requirement.test(value)) - throw exceptionMapper.apply(failDescription(requirement, value)); - return value; - } - - /** - * Returns the provided {@code value} after checking that it and the provided {@code otherValue} satisfies the - * provided {@code requirement} throwing an {@link IllegalArgumentException} if the check fails. - *

- * Checks that the provided {@code value} and provided {@code otherValue} satisfies the provided {@code requirement}. - *

- * This method is designed primarily for doing parameter validation in public methods - * and constructors, as demonstrated below: - *

-     * public Foo(int bar) {
-     *     this.bar = require(betweenZeroAnd(), bar, 32);
-     * }
-     * 
- * - * @param requirement to impose on the provided {@code value} and {@code otherValue} - * @param value the value to check - * @param otherValue the other value to compare against the provided {@code value} - * @return the provided {@code value} if the check passes - * @throws NullPointerException if the provided {@code requirement} is {@code null}. - * @throws IllegalArgumentException if the check fails - */ - @Deprecated(/* to be removed in x.26 */) - public static int require(final IntBiPredicate requirement, - final int value, - final int otherValue) { - if (!requirement.test(value, otherValue)) - throw new IllegalArgumentException(failDescription(requirement, value, otherValue)); - return value; - } - - /** - * Returns the provided {@code value} after checking that it and the provided {@code otherValue} satisfies the - * provided {@code requirement} throwing an {@link IllegalArgumentException} if the check fails. - *

- * Checks that the provided {@code value} and provided {@code otherValue} satisfies the provided {@code requirement}. - *

- * This method is designed primarily for doing parameter validation in public methods - * and constructors, as demonstrated below: - *

-     * public Foo(int bar) {
-     *     this.bar = require(betweenZeroAnd(), bar, 16, 32, ArithmeticException::new);
-     * }
-     * 
- * - * @param Exception typ to throw if the check fails - * @param requirement to impose on the provided {@code value} and {@code otherValue} - * @param value the value to check - * @param otherValue the other value to compare against the provided {@code value} - * @param exceptionMapper to apply should the check fail - * @return the provided {@code value} if the check passes - * @throws NullPointerException if the provided {@code requirement} is {@code null}. - * @throws IllegalArgumentException if the check fails - */ - @Deprecated(/* to be removed in x.26 */) - public static int require(final IntBiPredicate requirement, - final int value, - final int otherValue, - final Function exceptionMapper) { - requireNonNull(exceptionMapper); - if (!requirement.test(value, otherValue)) - throw exceptionMapper.apply(failDescription(requirement, value, otherValue)); - return value; - } - - /** - * Returns the provided {@code value} after checking that it and the provided {@code otherValue} - * and the provided {@code otherSecondValue} satisfies the provided {@code requirement} - * throwing an {@link IllegalArgumentException} if the check fails. - *

- * This method is designed primarily for doing parameter validation in public methods - * and constructors, as demonstrated below: - *

-     * public Foo(int bar) {
-     *     this.bar = require(between(), bar, 16, 32);
-     * }
-     * 
- * - * @param requirement to impose on the provided values - * @param value the value to check - * @param otherFirstValue the other first value to compare against the provided {@code value} - * @param otherSecondValue the other first value to compare against the provided {@code value} - * @return the provided {@code value} if the check passes - * @throws NullPointerException if the provided {@code requirement} is {@code null}. - * @throws IllegalArgumentException if the check fails - */ - @Deprecated(/* to be removed in x.26 */) - public static int require(final IntTriPredicate requirement, - final int value, - final int otherFirstValue, - final int otherSecondValue) { - return require(requirement, value, otherFirstValue, otherSecondValue, IllegalArgumentException::new); - } - - /** - * Returns the provided {@code value} after checking that it and the provided {@code otherValue} - * and the provided {@code otherSecondValue} satisfies the provided {@code requirement} - * throwing an {@link IllegalArgumentException} if the check fails. - *

- * This method is designed primarily for doing parameter validation in public methods - * and constructors, as demonstrated below: - *

-     * public Foo(int bar) {
-     *     this.bar = require(between(), bar, 16, 32, ArithmeticException::new);
-     * }
-     * 
- * - * @param Exception typ to throw if the check fails - * @param requirement to impose on the provided values - * @param value the value to check - * @param otherFirstValue the other first value to compare against the provided {@code value} - * @param otherSecondValue the other first value to compare against the provided {@code value} - * @param exceptionMapper to apply should the check fail - * @return the provided {@code value} if the check passes - * @throws NullPointerException if the provided {@code requirement} is {@code null}. - * @throws IllegalArgumentException if the check fails - */ - @Deprecated(/* to be removed in x.26 */) - public static int require(final IntTriPredicate requirement, - final int value, - final int otherFirstValue, - final int otherSecondValue, - final Function exceptionMapper) { - requireNonNull(exceptionMapper); - if (!requirement.test(value, otherFirstValue, otherSecondValue)) - throw exceptionMapper.apply(failDescription(requirement, value, otherFirstValue, otherSecondValue)); + throw new IllegalArgumentException("The provided value (" + value + ") is negative"); return value; } @@ -278,38 +95,6 @@ public static boolean assertIfEnabled(final IntPredicate requirement, return true; } - /** - * Asserts that the provided {@code value} and provided {@code otherValue} satisfies the provided {@code requirement} - * if assertions is enabled (i.e. {@code -ea}) and {@link AssertUtil#SKIP_ASSERTIONS} is {@code false}. - *

- * This method is designed primarily for doing parameter validation in private methods - * and constructors, as demonstrated below: - *

-     * private Foo(int bar) {
-     *     assertIfEnabled(betweenZeroAnd(), bar, 32);
-     *     this.bar = bar;
-     * }
-     * 
- * - * @param requirement to impose on the provided {@code value} and {@code otherValue} - * @param value the value to check - * @param otherValue the other value to compare against the provided {@code value} - * @return {@code true} - * @throws NullPointerException if the provided {@code requirement} is {@code null}. There is no guarantee that this - * exception is thrown. For example, if assertions are not enabled, then the exception - * might not be thrown. - * @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 x.26 */) - public static boolean assertIfEnabled(final IntBiPredicate requirement, - final int value, - final int otherValue) { - assert AssertUtil.SKIP_ASSERTIONS || requirement.test(value, otherValue) - : failDescription(requirement, value, otherValue); - return true; - } - /** * Asserts that the provided {@code value}, provided {@code otherFirstValue} and provided {@code otherSecondValue} * satisfies the provided {@code requirement} if assertions is enabled (i.e. {@code -ea}) and @@ -394,26 +179,6 @@ public static String failDescription(final IntTriPredicate requirement, return String.format("The provided value (%d) is illegal because it does not satisfy the provided requirement: %d %s (%d, %d)", value, value, requirement, otherFirstValue, otherSecondValue); } - /** - * Returns a predicate that can test if a value is positive (i.e. value > 0). - * - * @return a predicate that can test if a value is positive (i.e. value > 0) - */ - @Deprecated(/* to be removed in x.26 */) - public static IntPredicate positive() { - return IntCondition.POSITIVE; - } - - /** - * Returns a predicate that can test if a value is negative (i.e. value < 0). - * - * @return a predicate that can test if a value is negative (i.e. value < 0) - */ - @Deprecated(/* to be removed in x.26 */) - public static IntPredicate negative() { - return IntCondition.NEGATIVE; - } - /** * Returns a predicate that can test if a value is non-negative (i.e. value >= 0). *

@@ -424,233 +189,4 @@ public static IntPredicate negative() { public static IntPredicate nonNegative() { return IntCondition.NON_NEGATIVE; } - - /** - * Returns a predicate that can test if a value is zero (i.e. value == 0). - * - * @return a predicate that can test if a value is zero (i.e. value == 0) - */ - @Deprecated(/* to be removed in x.26 */) - public static IntPredicate zero() { - return IntCondition.ZERO; - } - - /** - * Returns a predicate that can test if a value can fit in a {@code byte} (i.e. value ∈ [-128, 127]"). - * - * @return a predicate that can test if a value can fit in a {@code byte} (i.e. value ∈ [-128, 127]") - */ - @Deprecated(/* to be removed in x.26 */) - public static IntPredicate byteConvertible() { - return IntCondition.BYTE_CONVERTIBLE; - } - - /** - * Returns a predicate that can test if a value can fit in a {@code short} (i.e. value ∈ [-32768, 32767]"). - * - * @return a predicate that can test if a value can fit in a {@code short} (i.e. value ∈ [-32768, 32767]") - */ - @Deprecated(/* to be removed in x.26 */) - public static IntPredicate shortConvertible() { - return IntCondition.SHORT_CONVERTIBLE; - } - - /** - * Returns a predicate that can test if a value is an even power of two - * (i.e. log2(value) is an integer). - * - * @return a predicate that can test if a value is an even power of two - * (i.e. log2(value) is an integer) - */ - @Deprecated(/* to be removed in x.26 */) - public static IntPredicate evenPowerOfTwo() { - return IntCondition.EVEN_POWER_OF_TWO; - } - - /** - * Returns a predicate that can test if a value is short aligned - * (i.e. value & (Short.BYTES - 1) == 0). - * - * @return a predicate that can test if a value is short aligned - * (i.e. value & (Short.BYTES - 1) == 0) - */ - @Deprecated(/* to be removed in x.26 */) - public static IntPredicate shortAligned() { - return IntCondition.SHORT_ALIGNED; - } - - /** - * Returns a predicate that can test if a value is int aligned - * (i.e. value & (Integer.BYTES - 1) == 0). - * - * @return a predicate that can test if a value is a int aligned - * (i.e. value & (Integer.BYTES - 1) == 0) - */ - @Deprecated(/* to be removed in x.26 */) - public static IntPredicate intAligned() { - return IntCondition.INT_ALIGNED; - } - - /** - * Returns a predicate that can test if a value is long aligned - * (i.e. value & (Long.BYTES - 1) == 0). - * - * @return a predicate that can test if a value is a long aligned - * (i.e. value & (Long.BYTES - 1) == 0) - */ - @Deprecated(/* to be removed in x.26 */) - public static IntPredicate longAligned() { - return IntCondition.LONG_ALIGNED; - } - - /** - * Returns a predicate that can test if a value is equal to another value. - * - * @return a predicate that can test if a value is equal to another value - */ - @Deprecated(/* to be removed in x.26 */) - public static IntBiPredicate equalTo() { - return IntBiCondition.EQUAL_TO; - } - - /** - * Returns a predicate that can test if a value is greater than to another value. - * - * @return a predicate that can test if a value is greater than to another value - */ - @Deprecated(/* to be removed in x.26 */) - public static IntBiPredicate greaterThan() { - return IntBiCondition.GREATER_THAN; - } - - /** - * Returns a predicate that can test if a value is greater or equal to another value. - * - * @return a predicate that can test if a value is greater or equal to another value - */ - @Deprecated(/* to be removed in x.26 */) - public static IntBiPredicate greaterOrEqual() { - return IntBiCondition.GREATER_OR_EQUAL; - } - - /** - * Returns a predicate that can test if a value is less than to another value. - * - * @return a predicate that can test if a value is less than to another value - */ - @Deprecated(/* to be removed in x.26 */) - public static IntBiPredicate lessThan() { - return IntBiCondition.LESS_THAN; - } - - /** - * Returns a predicate that can test if a value is less or equal to another value. - * - * @return a predicate that can test if a value is less or equal to another value - */ - @Deprecated(/* to be removed in x.26 */) - public static IntBiPredicate lessOrEqual() { - return IntBiCondition.LESS_OR_EQUAL; - } - - /** - * Returns a predicate that can test if a value is between zero and another value (exclusive) - * (i.e value ∈ [0, other value) ). - * - * @return a predicate that can test if a value is between zero and another value (exclusive) - * (i.e value ∈ [0, other value) ) - */ - @Deprecated(/* to be removed in x.26 */) - public static IntBiPredicate betweenZeroAnd() { - return IntBiCondition.BETWEEN_ZERO_AND; - } - - /** - * Returns a predicate that can test if a value is between zero and another value (inclusive) - * (i.e value ∈ [0, other value] ). - * - * @return a predicate that can test if a value is between zero and another value (inclusive) - * (i.e value ∈ [0, other value] ) - */ - @Deprecated(/* to be removed in x.26 */) - public static IntBiPredicate betweenZeroAndClosed() { - return IntBiCondition.BETWEEN_ZERO_AND_CLOSED; - } - - /** - * Returns a predicate that can test if a value is a power of two of another value - * (i.e. value = 2 ^ other value). - * For example, - * {@code powerOfTwo().test(16, 4)} is {@code true} because 2^4 is 16 - * - * @return a predicate that can test if a value is an even power of two - * (i.e. an N exists such that value ^ N is an integer) - */ - @Deprecated(/* to be removed in x.26 */) - public static IntBiPredicate powerOfTwo() { - return IntBiCondition.POWER_OF_TWO; - } - - /** - * Returns a predicate that can test if a value is log2 of another value - * (i.e. value = log2(other value) ). - *

- * For example, - * {@code log2().test(4, 16)} is {@code true} because log2(16) is 4 - * - * @return a predicate that can test if a value is log2 of another value - * (i.e. value = log2(other value) ). - */ - @Deprecated(/* to be removed in x.26 */) - public static IntBiPredicate log2() { - return IntBiCondition.LOG2; - } - - /** - * Returns a predicate that can test if a value is between another first value (inclusive) - * and another second value (exclusive) (i.e value ∈ [other first value , other second value) ). - * - * @return a predicate that can test if a value is between another first value (inclusive) - * and another second value (exclusive) (i.e value ∈ [other first value , other second value) ) - */ - @Deprecated(/* to be removed in x.26 */) - public static IntTriPredicate between() { - return IntTriCondition.BETWEEN; - } - - /** - * Returns a predicate that can test if a value is between (closed) another first value (inclusive) - * and another second value (inclusive) (i.e value ∈ [other first value , other second value] ). - * - * @return a predicate that can test if a value is between (closed) another first value (inclusive) - * and another second value (inclusive) (i.e value ∈ [other first value , other second value] ). - */ - @Deprecated(/* to be removed in x.26 */) - public static IntTriPredicate betweenClosed() { - return IntTriCondition.BETWEEN_CLOSED; - } - - /** - * Returns a predicate that can test if a value is between zero and another first value (inclusive) - * whilst ensuring a value of size defined by another second value can fit. - * (i.e value ∈ [0, other first value - other second value] ). - *

- * This predicate is useful when ensuring that a memory structure can be updated without exceeding its upper - * bounds. For example: - *

-     * public static void putInt(byte[] bytes, int offset, int value) {
-     *         assert nonNull(bytes);
-     *         assert betweenZeroAndReserving.test(offset, bytes.length, Integer.BYTES);
-     *         ...
-     * 
- * - * @return Returns a predicate that can test if a value is between zero and another first value (inclusive) - * whilst ensuring a value of size defined by another second value can fit. - * (i.e value ∈ [0, other first value - other second value] ). - */ - @Deprecated(/* to be removed in x.26 */) - public static IntTriPredicate betweenZeroAndReserving() { - return IntTriCondition.BETWEEN_ZERO_AND_ENSURING; - } - } diff --git a/src/main/java/net/openhft/chronicle/core/util/LongBiPredicate.java b/src/main/java/net/openhft/chronicle/core/util/LongBiPredicate.java index cd4ecc45a2..c5ea0c65b4 100644 --- a/src/main/java/net/openhft/chronicle/core/util/LongBiPredicate.java +++ b/src/main/java/net/openhft/chronicle/core/util/LongBiPredicate.java @@ -27,6 +27,7 @@ * * @see Predicate */ +@Deprecated(/*to be removed in x.27*/) @FunctionalInterface public interface LongBiPredicate { diff --git a/src/main/java/net/openhft/chronicle/core/util/LongTriPredicate.java b/src/main/java/net/openhft/chronicle/core/util/LongTriPredicate.java deleted file mode 100644 index f2c16bbf89..0000000000 --- a/src/main/java/net/openhft/chronicle/core/util/LongTriPredicate.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2016-2022 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.chronicle.core.util; - -import java.util.Objects; -import java.util.function.Predicate; - -/** - * Represents a predicate (boolean-valued function) of three long arguments. This is - * the three-arity specialization of {@link Predicate}. - * - * @see Predicate - */ -@Deprecated(/* to be removed in x.26 */) -@FunctionalInterface -public interface LongTriPredicate { - - /** - * Evaluates this predicate on the given arguments. - * - * @param t the first input argument - * @param u the second input argument - * @param v the third input argument - * @return {@code true} if the input arguments match the predicate, - * otherwise {@code false} - */ - boolean test(long t, long u, long v); - - /** - * Returns a composed predicate that represents a short-circuiting logical - * AND of this predicate and another. When evaluating the composed - * predicate, if this predicate is {@code false}, then the {@code other} - * predicate is not evaluated. - * - *

Any exceptions thrown during evaluation of either predicate are relayed - * to the caller; if evaluation of this predicate throws an exception, the - * {@code other} predicate will not be evaluated. - * - * @param other a predicate that will be logically-ANDed with this - * predicate - * @return a composed predicate that represents the short-circuiting logical - * AND of this predicate and the {@code other} predicate - * @throws NullPointerException If other is null - */ - default LongTriPredicate and(LongTriPredicate other) { - Objects.requireNonNull(other); - return (long t, long u, long v) -> test(t, u, v) && other.test(t, u, v); - } - - /** - * Returns a predicate that represents the logical negation of this - * predicate. - * - * @return a predicate that represents the logical negation of this - * predicate - */ - default LongTriPredicate negate() { - return (long t, long u, long v) -> !test(t, u, v); - } - - /** - * Returns a composed predicate that represents a short-circuiting logical - * OR of this predicate and another. When evaluating the composed - * predicate, if this predicate is {@code true}, then the {@code other} - * predicate is not evaluated. - * - *

Any exceptions thrown during evaluation of either predicate are relayed - * to the caller; if evaluation of this predicate throws an exception, the - * {@code other} predicate will not be evaluated. - * - * @param other a predicate that will be logically-ORed with this - * predicate - * @return a composed predicate that represents the short-circuiting logical - * OR of this predicate and the {@code other} predicate - * @throws NullPointerException If other is null - */ - default LongTriPredicate or(LongTriPredicate other) { - Objects.requireNonNull(other); - return (long t, long u, long v) -> test(t, u, v) || other.test(t, u, v); - } -} diff --git a/src/main/java/net/openhft/chronicle/core/util/Longs.java b/src/main/java/net/openhft/chronicle/core/util/Longs.java index b9f6c76ba5..5e85547a46 100644 --- a/src/main/java/net/openhft/chronicle/core/util/Longs.java +++ b/src/main/java/net/openhft/chronicle/core/util/Longs.java @@ -19,11 +19,8 @@ package net.openhft.chronicle.core.util; import net.openhft.chronicle.assertions.AssertUtil; -import net.openhft.chronicle.core.internal.invariant.longs.LongBiCondition; import net.openhft.chronicle.core.internal.invariant.longs.LongCondition; -import net.openhft.chronicle.core.internal.invariant.longs.LongTriCondition; -import java.util.function.BooleanSupplier; import java.util.function.Function; import java.util.function.LongPredicate; @@ -57,7 +54,7 @@ private Longs() { */ public static long requireNonNegative(final long value) { if (value < 0) - throw new IllegalArgumentException(failDescription(negative().negate(), value)); + throw new IllegalArgumentException("The provided value (" + value + ") is negative"); return value; } @@ -79,55 +76,10 @@ public static long requireNonNegative(final long value) { */ public static long requirePositive(final long value) { if (value <= 0) - throw new IllegalArgumentException(failDescription(positive(), value)); + throw new IllegalArgumentException("The provided value (" + value + ") is not positive"); return value; } - /** - * Returns the provided {@code value} after checking that it satisfies the provided {@code requirement} throwing - * an {@link IllegalArgumentException} if the check fails. - *

- * This method is designed primarily for doing parameter validation in public methods - * and constructors, as demonstrated below: - *

-     * public Foo(long bar) {
-     *     this.bar = require(nonNegative(), bar);
-     * }
-     * 
- * - * @param requirement to impose on the provided {@code value} - * @param value the value to check - * @return the provided {@code value} if the check passes - * @throws NullPointerException If the provided {@code requirement} is {@code null}. - * @throws IllegalArgumentException If the check fails - */ - @Deprecated(/* to be removed in x.26 */) - public static long require(final LongPredicate requirement, - final long value) { - return require(requirement, value, IllegalArgumentException::new); - } - - /** - * Returns the provided {@code value} after checking that it satisfies the provided {@code requirement} throwing - * an {@link IllegalArgumentException} if the check fails. - *

- * This method is designed primarily for doing parameter validation in public methods - * and constructors, as demonstrated below: - *

-     * public Foo(long bar) {
-     *     this.bar = require(() -> bar > 0, "bar should be positive");
-     * }
-     * 
- * - * @param requirement to impose on the provided {@code value} - * @throws NullPointerException If the provided {@code requirement} is {@code null}. - * @throws IllegalArgumentException If the check fails - */ - @Deprecated(/* to be removed in x.26 */) - public static void require(final BooleanSupplier requirement, final String msg) { - require(requirement, msg, IllegalArgumentException::new); - } - /** * Returns the provided {@code value} after checking that it satisfies the provided {@code requirement} throwing * a custom exception if the check fails. @@ -158,190 +110,6 @@ public static long require(final LongPredicate requ return value; } - /** - * Returns the provided {@code value} after checking that it satisfies the provided {@code requirement} throwing - * a custom exception if the check fails. - *

- * This method is designed primarily for doing parameter validation in public methods - * and constructors, as demonstrated below: - *

-     * public Foo(long bar) {
-     *     this.bar = require(byteConvertible(), bar, ArithmeticException::new);
-     * }
-     * 
- * - * @param Exception typ to throw if the check fails - * @param requirement to impose on the provided {@code value} - * @param exceptionMapper to apply should the check fail - * @throws NullPointerException If the provided {@code requirement} is {@code null} or if the provided - * {@code exceptionMapper} is {@code null}. - * @throws RuntimeException of the specified type of the provided {@code exceptionMapper} - */ - @Deprecated(/* to be removed in x.26 */) - public static void require(final BooleanSupplier requirement, - final String msg, - final Function exceptionMapper) { - requireNonNull(exceptionMapper); - if (!requirement.getAsBoolean()) - throw exceptionMapper.apply(msg); - } - - /** - * Returns the provided {@code value} after checking that it and the provided {@code otherValue} satisfies the - * provided {@code requirement} throwing an {@link IllegalArgumentException} if the check fails. - *

- * Checks that the provided {@code value} and provided {@code otherValue} satisfies the provided {@code requirement}. - *

- * This method is designed primarily for doing parameter validation in public methods - * and constructors, as demonstrated below: - *

-     * public Foo(long bar) {
-     *     this.bar = require(betweenZeroAnd(), bar, 32);
-     * }
-     * 
- * - * @param requirement to impose on the provided {@code value} and {@code otherValue} - * @param value the value to check - * @param otherValue the other value to compare against the provided {@code value} - * @return the provided {@code value} if the check passes - * @throws NullPointerException If the provided {@code requirement} is {@code null}. - * @throws IllegalArgumentException If the check fails - */ - public static long require(final LongBiPredicate requirement, - final long value, - final long otherValue) { - if (!requirement.test(value, otherValue)) - throw new IllegalArgumentException(failDescription(requirement, value, otherValue)); - return value; - } - - /** - * Returns the provided {@code value} after checking that it and the provided {@code otherValue} satisfies the - * provided {@code requirement} throwing an {@link IllegalArgumentException} if the check fails. - *

- * Checks that the provided {@code value} and provided {@code otherValue} satisfies the provided {@code requirement}. - *

- * This method is designed primarily for doing parameter validation in public methods - * and constructors, as demonstrated below: - *

-     * public Foo(long bar) {
-     *     this.bar = require(betweenZeroAnd(), bar, 16, 32, ArithmeticException::new);
-     * }
-     * 
- * - * @param Exception typ to throw if the check fails - * @param requirement to impose on the provided {@code value} and {@code otherValue} - * @param value the value to check - * @param otherValue the other value to compare against the provided {@code value} - * @param exceptionMapper to apply should the check fail - * @return the provided {@code value} if the check passes - * @throws NullPointerException If the provided {@code requirement} is {@code null}. - * @throws IllegalArgumentException If the check fails - */ - @Deprecated(/* to be removed in x.26 */) - public static long require(final LongBiPredicate requirement, - final long value, - final long otherValue, - final Function exceptionMapper) { - requireNonNull(exceptionMapper); - if (!requirement.test(value, otherValue)) - throw exceptionMapper.apply(failDescription(requirement, value, otherValue)); - return value; - } - - /** - * Returns the provided {@code value} after checking that it and the provided {@code otherValue} - * and the provided {@code otherSecondValue} satisfies the provided {@code requirement} - * throwing an {@link IllegalArgumentException} if the check fails. - *

- * This method is designed primarily for doing parameter validation in public methods - * and constructors, as demonstrated below: - *

-     * public Foo(long bar) {
-     *     this.bar = require(between(), bar, 16, 32);
-     * }
-     * 
- * - * @param requirement to impose on the provided values - * @param value the value to check - * @param otherFirstValue the other first value to compare against the provided {@code value} - * @param otherSecondValue the other first value to compare against the provided {@code value} - * @return the provided {@code value} if the check passes - * @throws NullPointerException If the provided {@code requirement} is {@code null}. - * @throws IllegalArgumentException If the check fails - */ - public static long require(final LongTriPredicate requirement, - final long value, - final long otherFirstValue, - final long otherSecondValue) { - return require(requirement, value, otherFirstValue, otherSecondValue, IllegalArgumentException::new); - } - - /** - * Returns the provided {@code value} after checking that it and the provided {@code otherValue} - * and the provided {@code otherSecondValue} satisfies the provided {@code requirement} - * throwing an {@link IllegalArgumentException} if the check fails. - *

- * This method is designed primarily for doing parameter validation in public methods - * and constructors, as demonstrated below: - *

-     * public Foo(long bar) {
-     *     this.bar = require(between(), bar, 16, 32, ArithmeticException::new);
-     * }
-     * 
- * - * @param Exception typ to throw if the check fails - * @param requirement to impose on the provided values - * @param value the value to check - * @param otherFirstValue the other first value to compare against the provided {@code value} - * @param otherSecondValue the other first value to compare against the provided {@code value} - * @param exceptionMapper to apply should the check fail - * @return the provided {@code value} if the check passes - * @throws NullPointerException If the provided {@code requirement} is {@code null}. - * @throws IllegalArgumentException If the check fails - */ - @Deprecated(/* to be removed in x.26 */) - public static long require(final LongTriPredicate requirement, - final long value, - final long otherFirstValue, - final long otherSecondValue, - final Function exceptionMapper) { - requireNonNull(exceptionMapper); - if (!requirement.test(value, otherFirstValue, otherSecondValue)) - throw exceptionMapper.apply(failDescription(requirement, value, otherFirstValue, otherSecondValue)); - return value; - } - - /** - * Asserts that the provided {@code value} satisfies the provided {@code requirement} if - * assertions is enabled (i.e. {@code -ea}) and {@link AssertUtil#SKIP_ASSERTIONS} is {@code false}. - *

- * This method is designed primarily for doing parameter validation in private methods - * and constructors, as demonstrated below: - *

-     * private Foo(long bar) {
-     *     assertIfEnabled(nonNegative, bar);
-     *     this.bar = bar;
-     * }
-     * 
- * - * @param requirement to impose on the provided {@code value} - * @param value the value to check - * @return {@code true} - * @throws NullPointerException If the provided {@code requirement} is {@code null}. There is no guarantee that this - * exception is thrown. For example, if assertions are not enabled, then the exception - * might not be thrown. - * @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 x.26 */) - public static boolean assertIfEnabled(final LongPredicate requirement, - final long value) { - assert AssertUtil.SKIP_ASSERTIONS || requirement.test(value) - : failDescription(requirement, value); - return true; - } - /** * Asserts that the provided {@code value} and provided {@code otherValue} satisfies the provided {@code requirement} * if assertions is enabled (i.e. {@code -ea}) and {@link AssertUtil#SKIP_ASSERTIONS} is {@code false}. @@ -373,40 +141,6 @@ public static boolean assertIfEnabled(final LongBiPredicate requirement, return true; } - /** - * Asserts that the provided {@code value}, provided {@code otherFirstValue} and provided {@code otherSecondValue} - * satisfies the provided {@code requirement} if assertions is enabled (i.e. {@code -ea}) and - * {@link AssertUtil#SKIP_ASSERTIONS} is {@code false}. - *

- * This method is designed primarily for doing parameter validation in private methods - * and constructors, as demonstrated below: - *

-     * public private(long bar) {
-     *     assertIfEnabled(between(), bar, 13, 42);
-     *     this.bar = bar;
-     * }
-     * 
- * - * @param requirement to impose on the provided values - * @param value the value to check - * @param otherFirstValue the other first value to compare against the provided {@code value} - * @param otherSecondValue the other first value to compare against the provided {@code value} - * @return {@code true} - * @throws NullPointerException If the provided {@code requirement} is {@code null}. There is no guarantee that this - * exception is thrown. For example, if assertions are not enabled, then the exception - * might not be thrown. - * @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 x.26 */) - public static boolean assertIfEnabled(final LongTriPredicate requirement, - final long value, - final long otherFirstValue, - final long otherSecondValue) { - assert AssertUtil.SKIP_ASSERTIONS || requirement.test(value, otherFirstValue, otherSecondValue) - : failDescription(requirement, value, otherFirstValue, otherSecondValue); - return true; - } /** * Returns a human-readable form of a failure message provided that the provided {@code value} did not @@ -418,8 +152,7 @@ public static boolean assertIfEnabled(final LongTriPredicate requirement, * satisfy the provided {@code requirement} * @throws NullPointerException If the provided {@code requirement} is {@code null}. */ - @Deprecated(/* to be removed in x.26 */) - public static String failDescription(final LongPredicate requirement, + private static String failDescription(final LongPredicate requirement, final long value) { return String.format("The provided value (%d) is illegal because it does not satisfy the provided requirement: %d %s", value, value, requirement); } @@ -435,52 +168,12 @@ public static String failDescription(final LongPredicate requirement, * provided {@code otherValue} did not satisfy the provided {@code requirement} * @throws NullPointerException If the provided {@code requirement} is {@code null}. */ - @Deprecated(/* to be removed in x.26 */) - public static String failDescription(final LongBiPredicate requirement, + private static String failDescription(final LongBiPredicate requirement, final long value, final long otherValue) { return String.format("The provided value (%d) is illegal because it does not satisfy the provided requirement: %d %s %d", value, value, requirement, otherValue); } - /** - * Returns a human-readable form of a failure message provided that the provided {@code value}, - * provided {@code otherFirstValue} and provided {@code otherFirstValue} did not satisfy the - * provided {@code requirement}. - * - * @param requirement to imposed on the provided values - * @param value the value to check - * @return a human-readable form of a failure message provided that the provided {@code value} and - * provided {@code otherValue} did not satisfy the provided {@code requirement} - * @throws NullPointerException If the provided {@code requirement} is {@code null}. - */ - @Deprecated(/* to be removed in x.26 */) - public static String failDescription(final LongTriPredicate requirement, - final long value, - final long otherFirstValue, - final long otherSecondValue) { - return String.format("The provided value (%d) is illegal because it does not satisfy the provided requirement: %d %s (%d, %d)", value, value, requirement, otherFirstValue, otherSecondValue); - } - - /** - * Returns a predicate that can test if a value is positive (i.e. value > 0). - * - * @return a predicate that can test if a value is positive (i.e. value > 0) - */ - @Deprecated(/* to be removed in x.26 */) - public static LongPredicate positive() { - return LongCondition.POSITIVE; - } - - /** - * Returns a predicate that can test if a value is negative (i.e. value < 0). - * - * @return a predicate that can test if a value is negative (i.e. value < 0) - */ - @Deprecated(/* to be removed in x.26 */) - public static LongPredicate negative() { - return LongCondition.NEGATIVE; - } - /** * Returns a predicate that can test if a value is non-negative (i.e. value >= 0). *

@@ -491,233 +184,4 @@ public static LongPredicate negative() { public static LongPredicate nonNegative() { return LongCondition.NON_NEGATIVE; } - - /** - * Returns a predicate that can test if a value is zero (i.e. value == 0). - * - * @return a predicate that can test if a value is zero (i.e. value == 0) - */ - @Deprecated(/* to be removed in x.26 */) - public static LongPredicate zero() { - return LongCondition.ZERO; - } - - /** - * Returns a predicate that can test if a value can fit in a {@code byte} (i.e. value ∈ [-128, 127]"). - * - * @return a predicate that can test if a value can fit in a {@code byte} (i.e. value ∈ [-128, 127]") - */ - @Deprecated(/* to be removed in x.26 */) - public static LongPredicate byteConvertible() { - return LongCondition.BYTE_CONVERTIBLE; - } - - /** - * Returns a predicate that can test if a value can fit in a {@code short} (i.e. value ∈ [-32768, 32767]"). - * - * @return a predicate that can test if a value can fit in a {@code short} (i.e. value ∈ [-32768, 32767]") - */ - @Deprecated(/* to be removed in x.26 */) - public static LongPredicate shortConvertible() { - return LongCondition.SHORT_CONVERTIBLE; - } - - /** - * Returns a predicate that can test if a value is an even power of two - * (i.e. log2(value) is an integer). - * - * @return a predicate that can test if a value is an even power of two - * (i.e. log2(value) is an integer) - */ - @Deprecated(/* to be removed in x.26 */) - public static LongPredicate evenPowerOfTwo() { - return LongCondition.EVEN_POWER_OF_TWO; - } - - /** - * Returns a predicate that can test if a value is short aligned - * (i.e. value & (Short.BYTES - 1) == 0). - * - * @return a predicate that can test if a value is short aligned - * (i.e. value & (Short.BYTES - 1) == 0) - */ - @Deprecated(/* to be removed in x.26 */) - public static LongPredicate shortAligned() { - return LongCondition.SHORT_ALIGNED; - } - - /** - * Returns a predicate that can test if a value is int aligned - * (i.e. value & (Integer.BYTES - 1) == 0). - * - * @return a predicate that can test if a value is a int aligned - * (i.e. value & (Integer.BYTES - 1) == 0) - */ - @Deprecated(/* to be removed in x.26 */) - public static LongPredicate intAligned() { - return LongCondition.INT_ALIGNED; - } - - /** - * Returns a predicate that can test if a value is long aligned - * (i.e. value & (Long.BYTES - 1) == 0). - * - * @return a predicate that can test if a value is a long aligned - * (i.e. value & (Long.BYTES - 1) == 0) - */ - @Deprecated(/* to be removed in x.26 */) - public static LongPredicate longAligned() { - return LongCondition.LONG_ALIGNED; - } - - /** - * Returns a predicate that can test if a value is equal to another value. - * - * @return a predicate that can test if a value is equal to another value - */ - @Deprecated(/* to be removed in x.26 */) - public static LongBiPredicate equalTo() { - return LongBiCondition.EQUAL_TO; - } - - /** - * Returns a predicate that can test if a value is greater than to another value. - * - * @return a predicate that can test if a value is greater than to another value - */ - @Deprecated(/* to be removed in x.26 */) - public static LongBiPredicate greaterThan() { - return LongBiCondition.GREATER_THAN; - } - - /** - * Returns a predicate that can test if a value is greater or equal to another value. - * - * @return a predicate that can test if a value is greater or equal to another value - */ - @Deprecated(/* to be removed in x.26 */) - public static LongBiPredicate greaterOrEqual() { - return LongBiCondition.GREATER_OR_EQUAL; - } - - /** - * Returns a predicate that can test if a value is less than to another value. - * - * @return a predicate that can test if a value is less than to another value - */ - @Deprecated(/* to be removed in x.26 */) - public static LongBiPredicate lessThan() { - return LongBiCondition.LESS_THAN; - } - - /** - * Returns a predicate that can test if a value is less or equal to another value. - * - * @return a predicate that can test if a value is less or equal to another value - */ - @Deprecated(/* to be removed in x.26 */) - public static LongBiPredicate lessOrEqual() { - return LongBiCondition.LESS_OR_EQUAL; - } - - /** - * Returns a predicate that can test if a value is between zero and another value (exclusive) - * (i.e value ∈ [0, other value) ). - * - * @return a predicate that can test if a value is between zero and another value (exclusive) - * (i.e value ∈ [0, other value) ) - */ - @Deprecated(/* to be removed in x.26 */) - public static LongBiPredicate betweenZeroAnd() { - return LongBiCondition.BETWEEN_ZERO_AND; - } - - /** - * Returns a predicate that can test if a value is between zero and another value (inclusive) - * (i.e value ∈ [0, other value] ). - * - * @return a predicate that can test if a value is between zero and another value (inclusive) - * (i.e value ∈ [0, other value] ) - */ - @Deprecated(/* to be removed in x.26 */) - public static LongBiPredicate betweenZeroAndClosed() { - return LongBiCondition.BETWEEN_ZERO_AND_CLOSED; - } - - /** - * Returns a predicate that can test if a value is a power of two of another value - * (i.e. value = 2 ^ other value). - * For example, - * {@code powerOfTwo().test(16, 4)} is {@code true} because 2^4 is 16 - * - * @return a predicate that can test if a value is an even power of two - * (i.e. an N exists such that value ^ N is an integer) - */ - @Deprecated(/* to be removed in x.26 */) - public static LongBiPredicate powerOfTwo() { - return LongBiCondition.POWER_OF_TWO; - } - - /** - * Returns a predicate that can test if a value is log2 of another value - * (i.e. value = log2(other value) ). - *

- * For example, - * {@code log2().test(4, 16)} is {@code true} because log2(16) is 4 - * - * @return a predicate that can test if a value is log2 of another value - * (i.e. value = log2(other value) ). - */ - @Deprecated(/* to be removed in x.26 */) - public static LongBiPredicate log2() { - return LongBiCondition.LOG2; - } - - /** - * Returns a predicate that can test if a value is between another first value (inclusive) - * and another second value (exclusive) (i.e value ∈ [other first value , other second value) ). - * - * @return a predicate that can test if a value is between another first value (inclusive) - * and another second value (exclusive) (i.e value ∈ [other first value , other second value) ) - */ - @Deprecated(/* to be removed in x.26 */) - public static LongTriPredicate between() { - return LongTriCondition.BETWEEN; - } - - /** - * Returns a predicate that can test if a value is between (closed) another first value (inclusive) - * and another second value (inclusive) (i.e value ∈ [other first value , other second value] ). - * - * @return a predicate that can test if a value is between (closed) another first value (inclusive) - * and another second value (inclusive) (i.e value ∈ [other first value , other second value] ). - */ - @Deprecated(/* to be removed in x.26 */) - public static LongTriPredicate betweenClosed() { - return LongTriCondition.BETWEEN_CLOSED; - } - - /** - * Returns a predicate that can test if a value is between zero and another first value (inclusive) - * whilst ensuring a value of size defined by another second value can fit. - * (i.e value ∈ [0, other first value - other second value] ). - *

- * This predicate is useful when ensuring that a memory structure can be updated without exceeding its upper - * bounds. For example: - *

-     * public static void putLong(byte[] bytes, long offset, long value) {
-     *         assert nonNull(bytes);
-     *         assert betweenZeroAndReserving.test(offset, bytes.length, Integer.BYTES);
-     *         ...
-     * 
- * - * @return Returns a predicate that can test if a value is between zero and another first value (inclusive) - * whilst ensuring a value of size defined by another second value can fit. - * (i.e value ∈ [0, other first value - other second value] ). - */ - @Deprecated(/* to be removed in x.26 */) - public static LongTriPredicate betweenZeroAndReserving() { - return LongTriCondition.BETWEEN_ZERO_AND_ENSURING; - } - } diff --git a/src/test/java/net/openhft/chronicle/core/UnsafeMemory2Test.java b/src/test/java/net/openhft/chronicle/core/UnsafeMemory2Test.java index bdca4fbaf6..e476f94daa 100644 --- a/src/test/java/net/openhft/chronicle/core/UnsafeMemory2Test.java +++ b/src/test/java/net/openhft/chronicle/core/UnsafeMemory2Test.java @@ -392,7 +392,9 @@ public void copyMemoryEachWayByteArrayHeapObject() throws NoSuchFieldException { final byte[] data = new byte[Integer.BYTES]; data[0] = 98; MyDTO to = new MyDTO(); + memory.copyMemory(data, 0, to, offset, Integer.BYTES); + assertEquals(data[0], to.num); to.num = 77; memory.copyMemory(to, offset, data, memory.arrayBaseOffset(data.getClass()), Integer.BYTES); diff --git a/src/test/java/net/openhft/chronicle/core/UnsafeMemoryIntTest.java b/src/test/java/net/openhft/chronicle/core/UnsafeMemoryIntTest.java index 9945efe29e..850788c7a8 100644 --- a/src/test/java/net/openhft/chronicle/core/UnsafeMemoryIntTest.java +++ b/src/test/java/net/openhft/chronicle/core/UnsafeMemoryIntTest.java @@ -36,7 +36,7 @@ public Class type() { @Override public IntPredicate alignedToType() { - return Ints.intAligned(); + return x -> x % 4 == 0; } @Override diff --git a/src/test/java/net/openhft/chronicle/core/UnsafeMemoryLongTest.java b/src/test/java/net/openhft/chronicle/core/UnsafeMemoryLongTest.java index c78cba1230..fd628da705 100644 --- a/src/test/java/net/openhft/chronicle/core/UnsafeMemoryLongTest.java +++ b/src/test/java/net/openhft/chronicle/core/UnsafeMemoryLongTest.java @@ -36,7 +36,7 @@ public Class type() { @Override public IntPredicate alignedToType() { - return Ints.longAligned(); + return x -> x % 8 == 0; } @Override diff --git a/src/test/java/net/openhft/chronicle/core/UnsafeMemoryShortTest.java b/src/test/java/net/openhft/chronicle/core/UnsafeMemoryShortTest.java index 9e11bc36f3..c1d4c205e6 100644 --- a/src/test/java/net/openhft/chronicle/core/UnsafeMemoryShortTest.java +++ b/src/test/java/net/openhft/chronicle/core/UnsafeMemoryShortTest.java @@ -36,7 +36,7 @@ public Class type() { @Override public IntPredicate alignedToType() { - return Ints.shortAligned(); + return x -> x % 2 == 0; } @Override diff --git a/src/test/java/net/openhft/chronicle/core/benchmarks/CoolerAppendBase10.java b/src/test/java/net/openhft/chronicle/core/benchmarks/CoolerAppendBase10.java deleted file mode 100644 index 25f8d7740a..0000000000 --- a/src/test/java/net/openhft/chronicle/core/benchmarks/CoolerAppendBase10.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2016-2022 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.chronicle.core.benchmarks; - -import net.openhft.chronicle.core.cooler.CoolerTester; -import net.openhft.chronicle.core.cooler.CpuCoolers; -import net.openhft.chronicle.core.io.UnsafeText; - -import static net.openhft.chronicle.core.UnsafeMemory.UNSAFE; - -public class CoolerAppendBase10 { - - static long blackhole; - - public static void main(String[] args) { - long address = UNSAFE.allocateMemory(32); - new CoolerTester(CpuCoolers.PAUSE1, CpuCoolers.BUSY100) -// .add("noop", () -> null) - .add("20d", () -> { - blackhole = UnsafeText.appendFixed(address, -Integer.MAX_VALUE); - return null; - }) - .runTimeMS(10000) - .repeat(6) - .run(); - - UNSAFE.freeMemory(address); - } - -} diff --git a/src/test/java/net/openhft/chronicle/core/io/UnsafeTextTest.java b/src/test/java/net/openhft/chronicle/core/io/UnsafeTextTest.java deleted file mode 100644 index 10bd242520..0000000000 --- a/src/test/java/net/openhft/chronicle/core/io/UnsafeTextTest.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright 2016-2022 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.chronicle.core.io; - -import net.openhft.chronicle.core.CoreTestCommon; -import net.openhft.chronicle.core.cooler.CoolerTester; -import net.openhft.chronicle.core.cooler.CpuCoolers; -import org.junit.Before; -import org.junit.Test; - -import java.util.Random; -import java.util.stream.IntStream; -import java.util.stream.LongStream; - -import static net.openhft.chronicle.core.UnsafeMemory.UNSAFE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -public class UnsafeTextTest extends CoreTestCommon { - - static long blackhole; - - @Override - @Before - public void threadDump() { - super.threadDump(); - } - - @Test - public void coolerAppendBase10quick() { - long address = UNSAFE.allocateMemory(32); - - try { - - new CoolerTester(CpuCoolers.PAUSE1, CpuCoolers.BUSY1) -// .add("noop", () -> null) - .add("20d", () -> { - blackhole = UnsafeText.appendFixed(address, -Integer.MAX_VALUE); - return null; - }) - .runTimeMS(100) - .repeat(3) - .run(); - - final String memVal = LongStream.range(address, blackhole) - .mapToInt(addr -> UNSAFE.getByte(null, addr)) - .mapToObj(c -> (char) c) - .reduce(new StringBuilder(), StringBuilder::append, StringBuilder::append) - .toString(); - - assertEquals(Long.toString(-Integer.MAX_VALUE), memVal); - } finally { - UNSAFE.freeMemory(address); - } - - } - - @Test - public void testAppendDouble() { - // TODO FIX - // Examples for https://github.com/OpenHFT/Chronicle-Core/issues/493 - testAppendDoubleOnce(5.959231521092378E-8, "5.959231521092378E-8"); - testAppendDoubleOnce(5.954710747053357E-8, "5.954710747053357E-8"); - testAppendDoubleOnce(-4.3723721608241563E-8, "-4.3723721608241563E-8"); - testAppendDoubleOnce(3.5645738448792343E-8, "3.5645738448792343E-8"); - testAppendDoubleOnce(1.1914579369762811E-8, "1.1914579369762811E-8"); - - // FIXED - testAppendDoubleOnce(-1.4778838950354771E-9, "-1.4778838950354771E-9"); - testAppendDoubleOnce(-145344868913.80003, "-145344868913.80003"); - - testAppendDoubleOnce(1.4753448053710411E-8, "1.4753448053710411E-8"); - testAppendDoubleOnce(4.731428525883379E-10, "4.731428525883379E-10"); - testAppendDoubleOnce(1e-5, "0.00001"); - - testAppendDoubleOnce(5.7270847085938394E-9, "5.7270847085938394E-9"); - testAppendDoubleOnce(-3.5627763205104632E-9, "-3.5627763205104632E-9"); - testAppendDoubleOnce(3.4363211797092447E-10, "3.4363211797092447E-10"); - - testAppendDoubleOnce(0.91234567890123456789, "0.9123456789012345"); - testAppendDoubleOnce(0.7205789375929972, "0.7205789375929972"); - testAppendDoubleOnce(1.7205789375929972E-8, "1.7205789375929972E-8"); - testAppendDoubleOnce(1.000000459754255, "1.000000459754255"); -// testAppendDoubleOnce(1.0000004597542552, "1.0000004597542552"); - testAppendDoubleOnce(-0.0042633243189823394, "-0.0042633243189823394"); - // too high - testAppendDoubleOnce(4.3634067645459027E-4, "0.00043634067645459027"); - testAppendDoubleOnce(-4.8378951079402273E-4, "-0.00048378951079402273"); - testAppendDoubleOnce(3.8098893793449994E-4, "0.00038098893793449994"); - testAppendDoubleOnce(-0.0036980489197619678, "-0.0036980489197619678"); - - // FIXED - testAppendDoubleOnce(1.1777536373898703E-7, "0.00000011777536373898703"); - testAppendDoubleOnce(8.577881719106565E-8, "0.00000008577881719106565"); - testAppendDoubleOnce(1.1709707236415293E-7, "0.00000011709707236415293"); - testAppendDoubleOnce(1.0272238286878982E-7, "0.00000010272238286878982"); - testAppendDoubleOnce(9.077547054210796E-8, "0.00000009077547054210796"); - testAppendDoubleOnce(-1.1914407211387385E-7, "-0.00000011914407211387385"); -// testAppendDoubleOnce(1.0626477603237785E-10, "0.00000000010626477603237785"); - testAppendDoubleOnce(8.871684275243539E-4, "0.0008871684275243539"); - testAppendDoubleOnce(8.807878708605213E-4, "0.0008807878708605213"); - testAppendDoubleOnce(8.417670165790972E-4, "0.0008417670165790972"); - testAppendDoubleOnce(0.0013292726996348332, "0.0013292726996348332"); - testAppendDoubleOnce(2.4192540417349368E-4, "0.00024192540417349368"); - testAppendDoubleOnce(1.9283711356548258E-4, "0.00019283711356548258"); - testAppendDoubleOnce(-8.299137873077923E-5, "-0.00008299137873077923"); - - // OK - testAppendDoubleOnce(0, "0.0"); - testAppendDoubleOnce(0.001, "0.001"); - testAppendDoubleOnce(0.0001, "0.0001"); - testAppendDoubleOnce(0.000001, "0.000001"); - testAppendDoubleOnce(0.0000001, "0.0000001"); - testAppendDoubleOnce(1.0E-8, "1.0E-8"); - testAppendDoubleOnce(1.0E-9, "1.0E-9"); - testAppendDoubleOnce(0.009, "0.009"); - testAppendDoubleOnce(0.0009, "0.0009"); - testAppendDoubleOnce(0.00009, "0.00009"); - testAppendDoubleOnce(0.000009, "0.000009"); - testAppendDoubleOnce(0.0000009, "0.0000009"); - testAppendDoubleOnce(0.00000009, "0.00000009"); - testAppendDoubleOnce(9.0E-9, "9.0E-9"); - testAppendDoubleOnce(Double.NaN, "NaN"); - testAppendDoubleOnce(Double.POSITIVE_INFINITY, "Infinity"); - testAppendDoubleOnce(Double.NEGATIVE_INFINITY, "-Infinity"); - testAppendDoubleOnce(0.1, "0.1"); - testAppendDoubleOnce(12.0, "12.0"); - testAppendDoubleOnce(12.1, "12.1"); - testAppendDoubleOnce(12.00000001, "12.00000001"); - testAppendDoubleOnce(1e-9 + Math.ulp(1e-9), "1.0000000000000003E-9"); - testAppendDoubleOnce(1e-10 + Math.ulp(1e-10), "1.0000000000000002E-10"); - testAppendDoubleOnce(1e-11 + Math.ulp(1e-11), "1.0000000000000001E-11"); - double d = -1e30; - testAppendDoubleOnce(d - Math.ulp(d), "-1000000000000000158000000000000"); - d = -1e31; - testAppendDoubleOnce(d - Math.ulp(d), "-1.0000000000000001E31"); - d = -1e32; - testAppendDoubleOnce(d - Math.ulp(d), "-1.0000000000000002E32"); - - } - - public void testAppendDoubleOnce(double value, String expectedValue) { - long address = UNSAFE.allocateMemory(max + 8); - try { - final String memVal = appendDoubleToString(value, address); - assertEquals("value; " + value, expectedValue, memVal); - } finally { - UNSAFE.freeMemory(address); - } - } - - static final int max = 32; - - @Test - public void testRandom() { - int runLength = 10_000; - IntStream.range(0, runLength).parallel().forEach(t -> { - Random r = new Random(); - long address = UNSAFE.allocateMemory(max + 8); - long l = r.nextLong() | 1L; - for (int i = 0; i < 1_000; i++) { - // agitate - l += 2; - double d = Double.longBitsToDouble(l); - if (!Double.isFinite(d) || Math.abs(d) < 1e-20 || Math.abs(d) > 5e11) { - break; - } - String s = appendDoubleToString(d, address); - double d2 = Double.parseDouble(s); - if (d != d2) { - String message = "" + (d - d2); - assertEquals(message, d, d2, 0); - } - } - // this is called unless the test is about to die - UNSAFE.freeMemory(address); - }); - } - - @Test - public void testSequential() { - IntStream.range(0, 300).parallel().forEach(t -> { - // odd numbers have the most precision error - long address = UNSAFE.allocateMemory(max + 8); - // double only has 16-17 digits of accuracy so 1 + x/1e15 has 16 digits. - double n = 1e15; - for (int i = 1; i < 10_000; i += 2) { - // multiply by 10191 to traverse the space. - long l = (t * 10_000L + i) * 10191L + (long) n; - double d = l / n; - String s = appendDoubleToString(d, address); - double d2 = Double.parseDouble(s); - if (d != d2) - assertEquals("" + (d - d2), d, d2, 0); - } - // this is called unless the test is about to die - UNSAFE.freeMemory(address); - }); - } - - public String appendDoubleToString(double value, long address) { - UNSAFE.putLong(address + max, 0L); - final long endAddress = UnsafeText.appendDouble(address, value); - if (endAddress > address + max) - fail("value: " + value + " length: " + (endAddress - address)); - long end = UNSAFE.getLong(address + max); - if (end != 0L) - fail("Overwrite: " + Long.toHexString(end)); - return LongStream.range(address, endAddress) - .mapToInt(addr -> UNSAFE.getByte(null, addr)) - .mapToObj(c -> (char) c) - .reduce(new StringBuilder(), StringBuilder::append, StringBuilder::append) - .toString(); - } - -} diff --git a/src/test/java/net/openhft/chronicle/core/threads/JitterSamplerTest.java b/src/test/java/net/openhft/chronicle/core/threads/JitterSamplerTest.java deleted file mode 100644 index 914ce8b3ce..0000000000 --- a/src/test/java/net/openhft/chronicle/core/threads/JitterSamplerTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2016-2022 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.chronicle.core.threads; - -import net.openhft.chronicle.core.CoreTestCommon; -import net.openhft.chronicle.core.Jvm; -import org.junit.Test; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.*; - -public class JitterSamplerTest extends CoreTestCommon { - - @Test - public void takeSnapshot() throws InterruptedException { - CountDownLatch latch = new CountDownLatch(2); - Thread t = new Thread(() -> { - JitterSampler.atStage("started"); - waitForLatch(latch); - int millis = Jvm.isArm() ? 120 : 60; - Jvm.pause(millis); - JitterSampler.atStage("finishing"); - Jvm.pause(millis); - JitterSampler.finished(); - }); - t.start(); - waitForLatch(latch); - for (int i = 0; i < 10; i++) { - Jvm.busyWaitMicros(1000); - String s = JitterSampler.takeSnapshot(10_000_000); - final String desc = JitterSampler.desc; - if ("finishing".equals(desc)) { - if (s != null && s.contains("finish")) - break; - } else { - assertEquals("started", desc); - } - } - t.join(); - String s = JitterSampler.takeSnapshot(); - assertNull(s); - } - - private void waitForLatch(CountDownLatch latch) { - latch.countDown(); - try { - assertTrue(latch.await(3, TimeUnit.SECONDS)); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new RuntimeException("Interrupted waiting for latch", e); - } - } -} diff --git a/src/test/java/net/openhft/chronicle/core/util/IntsTest.java b/src/test/java/net/openhft/chronicle/core/util/IntsTest.java deleted file mode 100644 index 4a7f25de54..0000000000 --- a/src/test/java/net/openhft/chronicle/core/util/IntsTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2016-2022 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.chronicle.core.util; - -import net.openhft.chronicle.core.CoreTestCommon; -import org.jetbrains.annotations.NotNull; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -public class IntsTest extends CoreTestCommon { - - @Test - public void require1Arg() { - test(1, 0, v -> Ints.require(Ints.positive(), v)); - test(1, -1, v -> Ints.require(Ints.positive(), v)); - } - - @Test - public void require2Arg() { - test(1, 0, v -> Ints.require(Ints.equalTo(), v, 1)); - } - - @Test - public void require3Ard() { - test(0, 16, v -> Ints.require(Ints.between(), v, 0, 16)); - test(15, -1, v -> Ints.require(Ints.between(), v, 0, 16)); - } - - @Test - public void shortAligned() { - test(0, 1, v -> Ints.require(Ints.shortAligned(), v)); - test(2, 3, v -> Ints.require(Ints.shortAligned(), v)); - test(4, 5, v -> Ints.require(Ints.shortAligned(), v)); - test(6, 7, v -> Ints.require(Ints.shortAligned(), v)); - test(8, 9, v -> Ints.require(Ints.shortAligned(), v)); - } - @Test - public void intAligned() { - test(0, 1, v -> Ints.require(Ints.intAligned(), v)); - test(0, 2, v -> Ints.require(Ints.intAligned(), v)); - test(0, 3, v -> Ints.require(Ints.intAligned(), v)); - test(4, 5, v -> Ints.require(Ints.intAligned(), v)); - test(4, 6, v -> Ints.require(Ints.intAligned(), v)); - } - @Test - public void longAligned() { - test(0, 1, v -> Ints.require(Ints.longAligned(), v)); - test(0, 2, v -> Ints.require(Ints.longAligned(), v)); - test(0, 3, v -> Ints.require(Ints.longAligned(), v)); - test(0, 4, v -> Ints.require(Ints.longAligned(), v)); - test(0, 5, v -> Ints.require(Ints.longAligned(), v)); - test(0, 6, v -> Ints.require(Ints.longAligned(), v)); - test(0, 7, v -> Ints.require(Ints.longAligned(), v)); - test(8, 9, v -> Ints.require(Ints.longAligned(), v)); - } - - private void test(final int happy, - final int sad, - @NotNull final IntUnaryOperator mapper) { - final long result = mapper.applyAsInt(happy); - assertEquals(happy, result); - try { - final long result2 = mapper.applyAsInt(sad); - fail(result2 + " is not valid!"); - } catch (IllegalArgumentException ignored) { - // Happy path - } - } - - interface IntUnaryOperator { - long applyAsInt(int happy) throws IllegalArgumentException; - } - -} diff --git a/src/test/java/net/openhft/chronicle/core/util/LongsTest.java b/src/test/java/net/openhft/chronicle/core/util/LongsTest.java deleted file mode 100644 index 1e42ba9bdf..0000000000 --- a/src/test/java/net/openhft/chronicle/core/util/LongsTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2016-2022 chronicle.software - * - * https://chronicle.software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.chronicle.core.util; - -import net.openhft.chronicle.core.CoreTestCommon; -import org.jetbrains.annotations.NotNull; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class LongsTest extends CoreTestCommon { - - @Test - public void requireBoolean() { - assertThrows(IllegalArgumentException.class, () -> Longs.require(() -> false, "Error")); - Longs.require(() -> true, "OK"); - } - - @Test - public void require1Arg() { - test(1, 0, v -> Longs.require(Longs.positive(), v)); - test(1, -1, v -> Longs.require(Longs.positive(), v)); - } - - @Test - public void require2Arg() { - test(1, 0, v -> Longs.require(Longs.equalTo(), v, 1)); - } - - @Test - public void require3Ard() { - test(0, 16, v -> Longs.require(Longs.between(), v, 0, 16)); - test(15, -1, v -> Longs.require(Longs.between(), v, 0, 16)); - } - - @Test - public void shortAligned() { - test(0, 1, v -> Longs.require(Longs.shortAligned(), v)); - test(2, 3, v -> Longs.require(Longs.shortAligned(), v)); - test(4, 5, v -> Longs.require(Longs.shortAligned(), v)); - test(6, 7, v -> Longs.require(Longs.shortAligned(), v)); - test(8, 9, v -> Longs.require(Longs.shortAligned(), v)); - } - - @Test - public void intAligned() { - test(0, 1, v -> Longs.require(Longs.intAligned(), v)); - test(0, 2, v -> Longs.require(Longs.intAligned(), v)); - test(0, 3, v -> Longs.require(Longs.intAligned(), v)); - test(4, 5, v -> Longs.require(Longs.intAligned(), v)); - test(4, 6, v -> Longs.require(Longs.intAligned(), v)); - } - - @Test - public void longAligned() { - test(0, 1, v -> Longs.require(Longs.longAligned(), v)); - test(0, 2, v -> Longs.require(Longs.longAligned(), v)); - test(0, 3, v -> Longs.require(Longs.longAligned(), v)); - test(0, 4, v -> Longs.require(Longs.longAligned(), v)); - test(0, 5, v -> Longs.require(Longs.longAligned(), v)); - test(0, 6, v -> Longs.require(Longs.longAligned(), v)); - test(0, 7, v -> Longs.require(Longs.longAligned(), v)); - test(8, 9, v -> Longs.require(Longs.longAligned(), v)); - } - - private void test(final int happy, - final int sad, - @NotNull final LongUnaryOperator mapper) { - final long result = mapper.applyAsLong(happy); - assertEquals(happy, result); - try { - final long result2 = mapper.applyAsLong(sad); - fail(result2 + " is not valid!"); - } catch (IllegalArgumentException ignored) { - // Happy path - } - } - - interface LongUnaryOperator { - long applyAsLong(int happy) throws IllegalArgumentException; - } - -} From 6fc1484eca6ff0ec2cdefbeb1e6ac69b49960ce2 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 8 Apr 2024 17:59:55 +0100 Subject: [PATCH 15/43] Tidy up code base --- .../openhft/chronicle/core/UnsafeMemory.java | 37 +++++++++---------- .../chronicle/core/util/ObjectUtils.java | 5 ++- .../net/openhft/chronicle/core/OSTest.java | 9 ++--- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java index 1c22f03ae5..abe97dbcb0 100644 --- a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java +++ b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java @@ -30,7 +30,6 @@ import java.nio.ByteOrder; import java.util.concurrent.atomic.AtomicLong; -import static java.util.Objects.nonNull; import static net.openhft.chronicle.assertions.AssertUtil.SKIP_ASSERTIONS; import static net.openhft.chronicle.core.util.ObjectUtils.requireNonNull; @@ -162,9 +161,9 @@ private static long retryReadVolatileLong(long address, long value) { * @param value the integer value to insert. */ public static void putInt(byte[] bytes, int offset, int value) { - assert SKIP_ASSERTIONS || nonNull(bytes); + assert SKIP_ASSERTIONS || bytes != null; assert SKIP_ASSERTIONS || offset + Integer.BYTES <= bytes.length; - UnsafeMemory.UNSAFE.putInt(bytes, ARRAY_BYTE_BASE_OFFSET + offset, value); + UNSAFE.putInt(bytes, ARRAY_BYTE_BASE_OFFSET + offset, value); } /** @@ -259,7 +258,7 @@ public static void unsafePutByte(long address, byte value) { * @param value to put */ public static void unsafePutLong(byte[] bytes, int offset, long value) { - assert SKIP_ASSERTIONS || nonNull(bytes); + assert SKIP_ASSERTIONS || bytes != null; assert SKIP_ASSERTIONS || offset + Long.BYTES <= bytes.length; UNSAFE.putLong(bytes, ARRAY_BYTE_BASE_OFFSET + offset, value); } @@ -272,7 +271,7 @@ public static void unsafePutLong(byte[] bytes, int offset, long value) { * @param value to put */ public static void unsafePutInt(byte[] bytes, int offset, int value) { - assert SKIP_ASSERTIONS || nonNull(bytes); + assert SKIP_ASSERTIONS || bytes != null; assert SKIP_ASSERTIONS || offset + Integer.BYTES <= bytes.length; UNSAFE.putInt(bytes, ARRAY_BYTE_BASE_OFFSET + offset, value); } @@ -285,7 +284,7 @@ public static void unsafePutInt(byte[] bytes, int offset, int value) { * @param value to put */ public static void unsafePutByte(byte[] bytes, int offset, byte value) { - assert SKIP_ASSERTIONS || nonNull(bytes); + assert SKIP_ASSERTIONS || bytes != null; assert SKIP_ASSERTIONS || offset + Byte.BYTES <= bytes.length; UNSAFE.putByte(bytes, ARRAY_BYTE_BASE_OFFSET + offset, value); } @@ -526,7 +525,7 @@ public static T unsafeGetObject(Object obj, long offset) { * @return the offset of the field. */ public static long unsafeObjectFieldOffset(Field field) { - assert SKIP_ASSERTIONS || nonNull(field); + assert SKIP_ASSERTIONS || field != null; return UNSAFE.objectFieldOffset(field); } @@ -541,7 +540,7 @@ public static long unsafeObjectFieldOffset(Field field) { @NotNull @Override public E allocateInstance(Class clazz) throws InstantiationException { - assert SKIP_ASSERTIONS || nonNull(clazz); + assert SKIP_ASSERTIONS || clazz != null; @NotNull E e = (E) UNSAFE.allocateInstance(clazz); return e; @@ -555,7 +554,7 @@ public E allocateInstance(Class clazz) throws InstantiationExce */ @Override public long getFieldOffset(Field field) { - assert SKIP_ASSERTIONS || nonNull(field); + assert SKIP_ASSERTIONS || field != null; return UNSAFE.objectFieldOffset(field); } @@ -1083,9 +1082,9 @@ public void copyMemory(long srcAddress, long destAddress, long length) { * @param length the length of memory to copy. */ public void copyMemory(byte[] src, int srcOffset, byte[] dest, int destOffset, int length) { - assert SKIP_ASSERTIONS || nonNull(src); + assert SKIP_ASSERTIONS || src != null; assert SKIP_ASSERTIONS || srcOffset >= 0; - assert SKIP_ASSERTIONS || nonNull(dest); + assert SKIP_ASSERTIONS || dest != null; assert SKIP_ASSERTIONS || destOffset >= 0; assert SKIP_ASSERTIONS || length >= 0; final long offsetB = ARRAY_BYTE_BASE_OFFSET + srcOffset; @@ -1176,9 +1175,9 @@ private void copyMemoryLoop(Object src, long srcOffset, Object dest, long destOf } private void backwardCopyMemoryLoop(Object src, long srcOffset, Object dest, long destOffset, int length) { - assert SKIP_ASSERTIONS || nonNull(src); + assert SKIP_ASSERTIONS || src != null; assert SKIP_ASSERTIONS || srcOffset > 0; - assert SKIP_ASSERTIONS || nonNull(dest); + assert SKIP_ASSERTIONS || dest != null; assert SKIP_ASSERTIONS || destOffset > 0; assert SKIP_ASSERTIONS || length >= 0; srcOffset += length; @@ -1307,7 +1306,7 @@ private int stopBitLength0(long l) { */ @Override public long partialRead(byte[] bytes, int offset, int length) { - assert SKIP_ASSERTIONS || nonNull(bytes); + assert SKIP_ASSERTIONS || bytes != null; assert SKIP_ASSERTIONS || offset + length <= bytes.length; switch (length) { case 8: @@ -1404,7 +1403,7 @@ public long partialRead(long addr, int length) { */ @Override public void partialWrite(byte[] bytes, int offset, long value, int length) { - assert SKIP_ASSERTIONS || nonNull(bytes); + assert SKIP_ASSERTIONS || bytes != null; assert SKIP_ASSERTIONS || offset >= 0; assert SKIP_ASSERTIONS || length >= 0; switch (length) { @@ -1496,7 +1495,7 @@ public void partialWrite(long addr, long value, int length) { */ @Override public boolean is7Bit(byte[] bytes, int offset, int length) { - assert SKIP_ASSERTIONS || nonNull(bytes); + assert SKIP_ASSERTIONS || bytes != null; assert SKIP_ASSERTIONS || offset >= 0; assert SKIP_ASSERTIONS || length >= 0; final long offset2 = offset + ARRAY_BYTE_BASE_OFFSET; @@ -1531,7 +1530,7 @@ public boolean is7Bit(byte[] bytes, int offset, int length) { */ @Override public boolean is7Bit(char[] chars, int offset, int length) { - assert SKIP_ASSERTIONS || nonNull(chars); + assert SKIP_ASSERTIONS || chars != null; assert SKIP_ASSERTIONS || offset >= 0; assert SKIP_ASSERTIONS || length >= 0; final long offset2 = offset * 2L + ARRAY_CHAR_BASE_OFFSET; @@ -1639,7 +1638,7 @@ public void testAndSetInt(long address, long offset, int expected, int value) th */ @Override public void testAndSetInt(Object object, long offset, int expected, int value) throws IllegalStateException { - assert SKIP_ASSERTIONS || nonNull(object); + assert SKIP_ASSERTIONS || object != null; assert SKIP_ASSERTIONS || offset > 0; if (UNSAFE.compareAndSwapInt(object, offset, expected, value)) return; @@ -2766,7 +2765,7 @@ public void testAndSetInt(long address, long offset, int expected, int value) th */ @Override public void testAndSetInt(Object object, long offset, int expected, int value) throws IllegalStateException { - assert SKIP_ASSERTIONS || nonNull(object); + assert SKIP_ASSERTIONS || object != null; assert SKIP_ASSERTIONS || offset > 0; if (safeAlignedInt(offset)) { if (UNSAFE.compareAndSwapInt(object, offset, expected, value)) { 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 b1482654c9..6c974a7c5c 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java +++ b/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java @@ -36,7 +36,6 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; -import static net.openhft.chronicle.core.Jvm.uncheckedCast; import static net.openhft.chronicle.core.internal.util.MapUtil.entry; import static net.openhft.chronicle.core.internal.util.MapUtil.ofUnmodifiable; import static net.openhft.chronicle.core.pool.ClassAliasPool.CLASS_ALIASES; @@ -398,7 +397,9 @@ public static > E getSingletonForEnum(Class eClass) { * @throws IllegalArgumentException If an illegal argument is provided. */ static E convertTo0(Class eClass, @Nullable Object o) throws NumberFormatException { - eClass = uncheckedCast(primToWrapper(eClass)); + @SuppressWarnings("unchecked") + Class eClass0 = (Class) primToWrapper(eClass); + eClass = eClass0; if (eClass.isInstance(o) || o == null) return (E) o; if (eClass == Void.class) return null; if (eClass == String.class) return (E) o.toString(); diff --git a/src/test/java/net/openhft/chronicle/core/OSTest.java b/src/test/java/net/openhft/chronicle/core/OSTest.java index 3366e98bb9..53e5c738c9 100644 --- a/src/test/java/net/openhft/chronicle/core/OSTest.java +++ b/src/test/java/net/openhft/chronicle/core/OSTest.java @@ -25,23 +25,22 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; -import org.mockito.*; +import org.mockito.MockitoAnnotations; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; import java.lang.reflect.InvocationTargetException; import java.net.InetAddress; import java.nio.ByteOrder; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileChannel.MapMode; -import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.mockito.Mockito.*; import static org.junit.Assert.*; import static org.junit.Assume.assumeTrue; import static org.junit.jupiter.api.Assertions.assertTrue; From b877bd682e5245927c352c0219b8e45b16107299 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 10 Apr 2024 16:18:08 +0100 Subject: [PATCH 16/43] resolve Javadoc issues --- checked-exceptions/src/main/java/java/lang/Appendable.java | 4 ++-- .../src/main/java/java/lang/CharSequence.java | 2 +- src/main/java/net/openhft/chronicle/core/Jvm.java | 3 +-- src/main/java/net/openhft/chronicle/core/OS.java | 2 +- .../java/net/openhft/chronicle/core/onoes/package-info.java | 1 - .../net/openhft/chronicle/core/threads/package-info.java | 6 ------ .../net/openhft/chronicle/core/values/BooleanValue.java | 1 - .../java/net/openhft/chronicle/core/values/ByteValue.java | 1 - .../java/net/openhft/chronicle/core/values/CharValue.java | 1 - .../java/net/openhft/chronicle/core/values/DoubleValue.java | 1 - .../java/net/openhft/chronicle/core/values/FloatValue.java | 1 - .../net/openhft/chronicle/core/values/IntArrayValues.java | 1 - .../java/net/openhft/chronicle/core/values/IntValue.java | 1 - .../net/openhft/chronicle/core/values/LongArrayValues.java | 1 - .../java/net/openhft/chronicle/core/values/LongValue.java | 1 - .../java/net/openhft/chronicle/core/values/ShortValue.java | 1 - .../java/net/openhft/chronicle/core/values/StringValue.java | 1 - .../net/openhft/chronicle/core/values/TwoLongValue.java | 1 - .../net/openhft/chronicle/core/values/package-info.java | 1 - 19 files changed, 5 insertions(+), 26 deletions(-) diff --git a/checked-exceptions/src/main/java/java/lang/Appendable.java b/checked-exceptions/src/main/java/java/lang/Appendable.java index 5777959763..cf85f9cdf3 100644 --- a/checked-exceptions/src/main/java/java/lang/Appendable.java +++ b/checked-exceptions/src/main/java/java/lang/Appendable.java @@ -23,7 +23,7 @@ public interface Appendable { /** * Appends the specified character sequence to this Appendable. *

- *

Depending on which class implements the character sequence + * Depending on which class implements the character sequence * csq, the entire sequence may not be appended. For * instance, if csq is a {@link java.nio.CharBuffer} then * the subsequence to append is defined by the buffer's position and limit. @@ -40,7 +40,7 @@ public interface Appendable { * Appends a subsequence of the specified character sequence to this * Appendable. *

- *

An invocation of this method of the form out.append(csq, start, + * An invocation of this method of the form out.append(csq, start, * end) when csq is not null, behaves in * exactly the same way as the invocation *

diff --git a/checked-exceptions/src/main/java/java/lang/CharSequence.java b/checked-exceptions/src/main/java/java/lang/CharSequence.java index 7d13d2eb12..ed48ec4824 100644 --- a/checked-exceptions/src/main/java/java/lang/CharSequence.java +++ b/checked-exceptions/src/main/java/java/lang/CharSequence.java @@ -32,7 +32,7 @@ public interface CharSequence { * index zero, the next at index one, and so on, as for array * indexing. *

- *

If the char value specified by the index is a + * If the char value specified by the index is a * surrogate, the surrogate * value is returned. * diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index e429156eb5..287d93257b 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -1506,8 +1506,7 @@ public static A findAnnotation(AnnotatedElement annotated * Typically, the name of these classes contains the "$$Lambda" substring. * Note that this naming convention is JVM-specific and can change * in future versions. The approach is known to work up to Java 21. - *

- * + * * @param clazz the class to be checked. * @return {@code true} if the class is a lambda, {@code false} otherwise. */ diff --git a/src/main/java/net/openhft/chronicle/core/OS.java b/src/main/java/net/openhft/chronicle/core/OS.java index 6085fc67fc..1e1e7d2c9a 100644 --- a/src/main/java/net/openhft/chronicle/core/OS.java +++ b/src/main/java/net/openhft/chronicle/core/OS.java @@ -298,7 +298,7 @@ public static Memory memory() { * Align the size to page boundary * * @param size the size to align - * @param pageSize + * @param pageSize the size of pages * @return aligned size * @see #pageSize() */ diff --git a/src/main/java/net/openhft/chronicle/core/onoes/package-info.java b/src/main/java/net/openhft/chronicle/core/onoes/package-info.java index b92b657e3b..043ebe22c1 100644 --- a/src/main/java/net/openhft/chronicle/core/onoes/package-info.java +++ b/src/main/java/net/openhft/chronicle/core/onoes/package-info.java @@ -19,7 +19,6 @@ *
  • {@link net.openhft.chronicle.core.onoes.ExceptionKey} - Represents a unique key for an exception event.
  • *
  • {@link net.openhft.chronicle.core.onoes.LogLevel} - Defines various levels of logging severity.
  • *
  • {@link net.openhft.chronicle.core.onoes.NullExceptionHandler} - Implements ExceptionHandler as a null object.
  • - *
  • {@link net.openhft.chronicle.core.onoes.PrintExceptionHandler} - Logs exceptions to standard output or error streams.
  • *
  • {@link net.openhft.chronicle.core.onoes.RecordingExceptionHandler} - Records exceptions by incrementing counts in a map.
  • *
  • {@link net.openhft.chronicle.core.onoes.Slf4jExceptionHandler} - Uses SLF4J for logging exceptions based on severity levels.
  • *
  • {@link net.openhft.chronicle.core.onoes.ThreadLocalisedExceptionHandler} - Provides thread-localized exception handling.
  • diff --git a/src/main/java/net/openhft/chronicle/core/threads/package-info.java b/src/main/java/net/openhft/chronicle/core/threads/package-info.java index ccfbd22cd6..95d3907460 100644 --- a/src/main/java/net/openhft/chronicle/core/threads/package-info.java +++ b/src/main/java/net/openhft/chronicle/core/threads/package-info.java @@ -35,15 +35,9 @@ *
  • {@link net.openhft.chronicle.core.threads.InvalidEventHandlerException}: Represents * an exception thrown when an event handler is invalid or needs to be removed.
  • * - *
  • {@link net.openhft.chronicle.core.threads.JitterSampler}: Utility class for - * profiling and tracking the execution stages of threads.
  • - * *
  • {@link net.openhft.chronicle.core.threads.OnDemandEventLoop}: A wrapper for an * EventLoop, which is created on-demand when any of its methods are called.
  • * - *
  • {@link net.openhft.chronicle.core.threads.StackSampler}: Utility class for sampling - * the stack traces of a target thread.
  • - * *
  • {@link net.openhft.chronicle.core.threads.ThreadDump}: Utility class for monitoring * and managing threads.
  • * diff --git a/src/main/java/net/openhft/chronicle/core/values/BooleanValue.java b/src/main/java/net/openhft/chronicle/core/values/BooleanValue.java index c499f40182..7bc49de278 100644 --- a/src/main/java/net/openhft/chronicle/core/values/BooleanValue.java +++ b/src/main/java/net/openhft/chronicle/core/values/BooleanValue.java @@ -48,7 +48,6 @@ * @see net.openhft.chronicle.core.values.StringValue * @see net.openhft.chronicle.core.values.LongArrayValues * @see net.openhft.chronicle.core.values.IntArrayValues - * @see net.openhft.chronicle.core.values.UnsetLongValue * @since 10/10/13 */ public interface BooleanValue { diff --git a/src/main/java/net/openhft/chronicle/core/values/ByteValue.java b/src/main/java/net/openhft/chronicle/core/values/ByteValue.java index 944e6c6a9b..2760ed68b0 100644 --- a/src/main/java/net/openhft/chronicle/core/values/ByteValue.java +++ b/src/main/java/net/openhft/chronicle/core/values/ByteValue.java @@ -39,7 +39,6 @@ * @see net.openhft.chronicle.core.values.StringValue * @see net.openhft.chronicle.core.values.LongArrayValues * @see net.openhft.chronicle.core.values.IntArrayValues - * @see net.openhft.chronicle.core.values.UnsetLongValue * @since 10/10/13 */ public interface ByteValue { diff --git a/src/main/java/net/openhft/chronicle/core/values/CharValue.java b/src/main/java/net/openhft/chronicle/core/values/CharValue.java index e652fd720f..3b89c10acd 100644 --- a/src/main/java/net/openhft/chronicle/core/values/CharValue.java +++ b/src/main/java/net/openhft/chronicle/core/values/CharValue.java @@ -39,7 +39,6 @@ * @see net.openhft.chronicle.core.values.StringValue * @see net.openhft.chronicle.core.values.LongArrayValues * @see net.openhft.chronicle.core.values.IntArrayValues - * @see net.openhft.chronicle.core.values.UnsetLongValue * @since 10/10/13 */ public interface CharValue { diff --git a/src/main/java/net/openhft/chronicle/core/values/DoubleValue.java b/src/main/java/net/openhft/chronicle/core/values/DoubleValue.java index 67e37b9418..6307d38d7a 100644 --- a/src/main/java/net/openhft/chronicle/core/values/DoubleValue.java +++ b/src/main/java/net/openhft/chronicle/core/values/DoubleValue.java @@ -48,7 +48,6 @@ * @see net.openhft.chronicle.core.values.StringValue * @see net.openhft.chronicle.core.values.LongArrayValues * @see net.openhft.chronicle.core.values.IntArrayValues - * @see net.openhft.chronicle.core.values.UnsetLongValue * @since 10/10/13 */ public interface DoubleValue { diff --git a/src/main/java/net/openhft/chronicle/core/values/FloatValue.java b/src/main/java/net/openhft/chronicle/core/values/FloatValue.java index e289548be0..7e48f19d5e 100644 --- a/src/main/java/net/openhft/chronicle/core/values/FloatValue.java +++ b/src/main/java/net/openhft/chronicle/core/values/FloatValue.java @@ -48,7 +48,6 @@ * @see net.openhft.chronicle.core.values.StringValue * @see net.openhft.chronicle.core.values.LongArrayValues * @see net.openhft.chronicle.core.values.IntArrayValues - * @see net.openhft.chronicle.core.values.UnsetLongValue * @since 10/10/13 */ public interface FloatValue { diff --git a/src/main/java/net/openhft/chronicle/core/values/IntArrayValues.java b/src/main/java/net/openhft/chronicle/core/values/IntArrayValues.java index 0dc31425e5..f16827ea55 100644 --- a/src/main/java/net/openhft/chronicle/core/values/IntArrayValues.java +++ b/src/main/java/net/openhft/chronicle/core/values/IntArrayValues.java @@ -56,7 +56,6 @@ * @see net.openhft.chronicle.core.values.StringValue * @see net.openhft.chronicle.core.values.LongArrayValues * @see net.openhft.chronicle.core.values.IntArrayValues - * @see net.openhft.chronicle.core.values.UnsetLongValue * @since 10/10/13 */ public interface IntArrayValues extends Closeable { diff --git a/src/main/java/net/openhft/chronicle/core/values/IntValue.java b/src/main/java/net/openhft/chronicle/core/values/IntValue.java index 8eb9e96cb2..dca6ca0415 100644 --- a/src/main/java/net/openhft/chronicle/core/values/IntValue.java +++ b/src/main/java/net/openhft/chronicle/core/values/IntValue.java @@ -46,7 +46,6 @@ * @see net.openhft.chronicle.core.values.StringValue * @see net.openhft.chronicle.core.values.LongArrayValues * @see net.openhft.chronicle.core.values.IntArrayValues - * @see net.openhft.chronicle.core.values.UnsetLongValue * @since 10/10/13 */ public interface IntValue extends Closeable { diff --git a/src/main/java/net/openhft/chronicle/core/values/LongArrayValues.java b/src/main/java/net/openhft/chronicle/core/values/LongArrayValues.java index bf448b44af..9d1a4de13a 100644 --- a/src/main/java/net/openhft/chronicle/core/values/LongArrayValues.java +++ b/src/main/java/net/openhft/chronicle/core/values/LongArrayValues.java @@ -55,7 +55,6 @@ * @see net.openhft.chronicle.core.values.StringValue * @see net.openhft.chronicle.core.values.LongArrayValues * @see net.openhft.chronicle.core.values.IntArrayValues - * @see net.openhft.chronicle.core.values.UnsetLongValue * @since 10/10/13 */ public interface LongArrayValues extends Closeable { diff --git a/src/main/java/net/openhft/chronicle/core/values/LongValue.java b/src/main/java/net/openhft/chronicle/core/values/LongValue.java index 448a8fbe40..54197b2c86 100644 --- a/src/main/java/net/openhft/chronicle/core/values/LongValue.java +++ b/src/main/java/net/openhft/chronicle/core/values/LongValue.java @@ -44,7 +44,6 @@ * @see net.openhft.chronicle.core.values.StringValue * @see net.openhft.chronicle.core.values.LongArrayValues * @see net.openhft.chronicle.core.values.IntArrayValues - * @see net.openhft.chronicle.core.values.UnsetLongValue * @since 10/10/13 */ public interface LongValue extends Closeable { diff --git a/src/main/java/net/openhft/chronicle/core/values/ShortValue.java b/src/main/java/net/openhft/chronicle/core/values/ShortValue.java index c51b9a0cd4..9828192cd7 100644 --- a/src/main/java/net/openhft/chronicle/core/values/ShortValue.java +++ b/src/main/java/net/openhft/chronicle/core/values/ShortValue.java @@ -45,7 +45,6 @@ * @see net.openhft.chronicle.core.values.StringValue * @see net.openhft.chronicle.core.values.LongArrayValues * @see net.openhft.chronicle.core.values.IntArrayValues - * @see net.openhft.chronicle.core.values.UnsetLongValue * @since 10/10/13 */ public interface ShortValue { diff --git a/src/main/java/net/openhft/chronicle/core/values/StringValue.java b/src/main/java/net/openhft/chronicle/core/values/StringValue.java index a661ad6f81..7e30b3e5fd 100644 --- a/src/main/java/net/openhft/chronicle/core/values/StringValue.java +++ b/src/main/java/net/openhft/chronicle/core/values/StringValue.java @@ -44,7 +44,6 @@ * @see net.openhft.chronicle.core.values.StringValue * @see net.openhft.chronicle.core.values.LongArrayValues * @see net.openhft.chronicle.core.values.IntArrayValues - * @see net.openhft.chronicle.core.values.UnsetLongValue */ public interface StringValue { diff --git a/src/main/java/net/openhft/chronicle/core/values/TwoLongValue.java b/src/main/java/net/openhft/chronicle/core/values/TwoLongValue.java index 96d74dcc94..9504cc2d1b 100644 --- a/src/main/java/net/openhft/chronicle/core/values/TwoLongValue.java +++ b/src/main/java/net/openhft/chronicle/core/values/TwoLongValue.java @@ -61,7 +61,6 @@ * @see net.openhft.chronicle.core.values.StringValue * @see net.openhft.chronicle.core.values.LongArrayValues * @see net.openhft.chronicle.core.values.IntArrayValues - * @see net.openhft.chronicle.core.values.UnsetLongValue * @since 10/10/13 */ public interface TwoLongValue extends LongValue { diff --git a/src/main/java/net/openhft/chronicle/core/values/package-info.java b/src/main/java/net/openhft/chronicle/core/values/package-info.java index 36d6800d12..36f4a0b38f 100644 --- a/src/main/java/net/openhft/chronicle/core/values/package-info.java +++ b/src/main/java/net/openhft/chronicle/core/values/package-info.java @@ -29,7 +29,6 @@ *
  • {@link net.openhft.chronicle.core.values.ShortValue} - Represents a reference to a 16-bit short value. *
  • {@link net.openhft.chronicle.core.values.StringValue} - Represents a reference to a String value. *
  • {@link net.openhft.chronicle.core.values.TwoLongValue} - Represents a reference to two long values. - *
  • {@link net.openhft.chronicle.core.values.UnsetLongValue} - Represents a long value that ignores attempts to modify it. * * * @since 10/10/13 From 233f7fb2d9bdf2f963c28c4123ebce046c64ddcb Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 12 Apr 2024 09:32:15 +0100 Subject: [PATCH 17/43] Added fail on warning lint for Javadoc, and rawtypes fixes for Bytes (#648) --- pom.xml | 7 ------- src/main/java/net/openhft/chronicle/core/Jvm.java | 2 +- .../net/openhft/chronicle/core/util/GenericReflection.java | 2 +- .../net/openhft/chronicle/core/util/ReadResolvable.java | 2 +- .../net/openhft/chronicle/core/util/ObjectUtilsTest.java | 4 ++-- 5 files changed, 5 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index ff6f0d6a21..682d65f0af 100644 --- a/pom.xml +++ b/pom.xml @@ -324,13 +324,6 @@ org.apache.maven.plugins maven-install-plugin - - org.apache.maven.plugins - maven-javadoc-plugin - - 8 - - diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index 287d93257b..06d7fff16f 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -1663,7 +1663,7 @@ public static T[] uncheckedCast(Object[] o) { * (a runtime risk inherent to unchecked casting) */ @SuppressWarnings({"unchecked", "rawtypes"}) - public static Class uncheckedCast(Class o) { + public static Class uncheckedCast(Class o) { return (Class) o; } 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 b37fa877d2..d32ec45390 100644 --- a/src/main/java/net/openhft/chronicle/core/util/GenericReflection.java +++ b/src/main/java/net/openhft/chronicle/core/util/GenericReflection.java @@ -119,7 +119,7 @@ static Type[] getGenericInterfaces(Type forClass) { static Type getGenericSuperclass(Type forClass) { if (forClass instanceof Class) - return ((Class) forClass).getGenericSuperclass(); + return ((Class) forClass).getGenericSuperclass(); if (forClass instanceof ParameterizedType) { return null; } diff --git a/src/main/java/net/openhft/chronicle/core/util/ReadResolvable.java b/src/main/java/net/openhft/chronicle/core/util/ReadResolvable.java index 2172a07bb1..2807779088 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ReadResolvable.java +++ b/src/main/java/net/openhft/chronicle/core/util/ReadResolvable.java @@ -45,7 +45,7 @@ public interface ReadResolvable { static T readResolve(Object o) { // Pattern matching if (o instanceof ReadResolvable) { - return (T) ((ReadResolvable) o).readResolve(); + return (T) ((ReadResolvable) o).readResolve(); } else if (o instanceof Serializable) { return (T) ObjectUtils.readResolve(o); } else { diff --git a/src/test/java/net/openhft/chronicle/core/util/ObjectUtilsTest.java b/src/test/java/net/openhft/chronicle/core/util/ObjectUtilsTest.java index 98f0a1e6ee..c0ffcd7221 100644 --- a/src/test/java/net/openhft/chronicle/core/util/ObjectUtilsTest.java +++ b/src/test/java/net/openhft/chronicle/core/util/ObjectUtilsTest.java @@ -34,7 +34,7 @@ public class ObjectUtilsTest extends CoreTestCommon { @Test public void testImmutable() { - for (@NotNull Class c : new Class[]{ + for (@NotNull Class c: new Class[]{ String.class, Integer.class, Date.class, @@ -43,7 +43,7 @@ public void testImmutable() { }) { assertEquals(c.getName(), ObjectUtils.Immutability.MAYBE, ObjectUtils.isImmutable(c)); } - for (@NotNull Class c : new Class[]{ + for (@NotNull Class c: new Class[]{ // StringBuilder.class, // StringBuilder implements Comparable in Java 11 ArrayList.class, HashMap.class, From 4d94a4a7117f16ebc797c2334bcaabb0b2d4e7d7 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 3 Apr 2024 09:49:32 +0100 Subject: [PATCH 18/43] review with lint:all (#641) --- src/main/java/net/openhft/chronicle/core/ChronicleInit.java | 6 ++++-- src/main/java/net/openhft/chronicle/core/Jvm.java | 2 +- .../java/net/openhft/chronicle/core/internal/Bootstrap.java | 5 +++++ .../net/openhft/chronicle/core/pool/DynamicEnumClass.java | 6 ++++-- .../java/net/openhft/chronicle/core/pool/ParsingCache.java | 4 +++- .../openhft/chronicle/core/scoped/ScopedThreadLocal.java | 4 +++- .../net/openhft/chronicle/core/shutdown/PriorityHook.java | 6 +++--- .../openhft/chronicle/core/threads/CleaningThreadLocal.java | 4 +++- src/main/java/net/openhft/chronicle/core/util/Mocker.java | 6 ++++-- 9 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/core/ChronicleInit.java b/src/main/java/net/openhft/chronicle/core/ChronicleInit.java index 53544999ef..ab64ac700e 100644 --- a/src/main/java/net/openhft/chronicle/core/ChronicleInit.java +++ b/src/main/java/net/openhft/chronicle/core/ChronicleInit.java @@ -20,6 +20,8 @@ import java.util.ServiceLoader; +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; + /** * Handles application code which must be loaded first/run and may override system properties. *

    @@ -50,7 +52,7 @@ private ChronicleInit() { String initRunnableClass = System.getProperty(CHRONICLE_INIT_CLASS); if (initRunnableClass != null && !initRunnableClass.isEmpty()) { try { - Class descendant = Jvm.uncheckedCast(Class.forName(initRunnableClass)); + Class descendant = uncheckedCast(Class.forName(initRunnableClass)); Runnable chronicleInit = descendant.getConstructor().newInstance(); chronicleInit.run(); } catch (Exception ex) { @@ -89,7 +91,7 @@ static void postInit() { String initRunnableClass = System.getProperty(CHRONICLE_POSTINIT_CLASS); if (initRunnableClass != null && !initRunnableClass.isEmpty()) { try { - Class descendant = Jvm.uncheckedCast(Class.forName(initRunnableClass)); + Class descendant = uncheckedCast(Class.forName(initRunnableClass)); Runnable chronicleInit = descendant.getConstructor().newInstance(); chronicleInit.run(); } catch (Exception ex) { diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index 06d7fff16f..19444b5cfd 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -1223,7 +1223,7 @@ public static long parseSize(@NotNull String value) throws IllegalArgumentExcept } } double number = Double.parseDouble(value.trim()); - factor *= number; + factor *= (long) number; return factor; } diff --git a/src/main/java/net/openhft/chronicle/core/internal/Bootstrap.java b/src/main/java/net/openhft/chronicle/core/internal/Bootstrap.java index a20e861b31..1fb218b146 100644 --- a/src/main/java/net/openhft/chronicle/core/internal/Bootstrap.java +++ b/src/main/java/net/openhft/chronicle/core/internal/Bootstrap.java @@ -186,4 +186,9 @@ private static int getProcessId0() { System.err.println(Bootstrap.class.getName() + ": Unable to determine PID, picked 1 as a PID"); return rpid; } + + @SuppressWarnings("unchecked") + public static T uncheckedCast(Object obj) { + return (T) obj; + } } 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 03c90b4bdd..5f54addb21 100644 --- a/src/main/java/net/openhft/chronicle/core/pool/DynamicEnumClass.java +++ b/src/main/java/net/openhft/chronicle/core/pool/DynamicEnumClass.java @@ -28,6 +28,8 @@ import java.util.*; import java.util.function.Function; +import static net.openhft.chronicle.core.Jvm.uncheckedCast; + /** * Represents a dynamic enumeration class that extends the capabilities of {@link EnumCache}. * The class is capable of dynamically creating and managing instances which resemble enumerations @@ -91,13 +93,13 @@ private E[] getStaticConstants(Class eClass) { try { field.setAccessible(true); Object o = field.get(null); - fieldList.add(Jvm.uncheckedCast(o)); + fieldList.add(uncheckedCast(o)); } catch (IllegalAccessException | IllegalArgumentException e) { Jvm.warn().on(getClass(), e.toString()); } } } - return Jvm.uncheckedCast(fieldList.toArray(CORE_DYNAMIC_ENUMS)); + return uncheckedCast(fieldList.toArray(CORE_DYNAMIC_ENUMS)); } /** 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 25981d10c6..c42c9a205e 100644 --- a/src/main/java/net/openhft/chronicle/core/pool/ParsingCache.java +++ b/src/main/java/net/openhft/chronicle/core/pool/ParsingCache.java @@ -28,6 +28,8 @@ import java.util.function.Function; import java.util.stream.Stream; +import static net.openhft.chronicle.core.Jvm.uncheckedCast; + /** * A cache for parsed values that is optimized for fast lookup. This class is used to cache objects * that are constructed from strings, often as a result of parsing. The cache has a fixed capacity @@ -66,7 +68,7 @@ public ParsingCache(int capacity, Function eFunction) { shift = Maths.intLog2(n); @SuppressWarnings("rawtypes") ParsedData[] obj = new ParsedData[n]; - interner = Jvm.uncheckedCast(obj); + interner = uncheckedCast(obj); mask = n - 1; } diff --git a/src/main/java/net/openhft/chronicle/core/scoped/ScopedThreadLocal.java b/src/main/java/net/openhft/chronicle/core/scoped/ScopedThreadLocal.java index 7db7377dea..680a96894f 100644 --- a/src/main/java/net/openhft/chronicle/core/scoped/ScopedThreadLocal.java +++ b/src/main/java/net/openhft/chronicle/core/scoped/ScopedThreadLocal.java @@ -10,6 +10,8 @@ import java.util.function.Consumer; import java.util.function.Supplier; +import static net.openhft.chronicle.core.Jvm.uncheckedCast; + /** * A thread-local {@link ScopedResourcePool}. *

    @@ -115,7 +117,7 @@ class SimpleStack implements java.io.Closeable { private int headIndex = -1; SimpleStack(int maxInstances) { - this.instances = Jvm.uncheckedCast(Array.newInstance(AbstractScopedResource.class, maxInstances)); + this.instances = uncheckedCast(Array.newInstance(AbstractScopedResource.class, maxInstances)); } AbstractScopedResource pop() { diff --git a/src/main/java/net/openhft/chronicle/core/shutdown/PriorityHook.java b/src/main/java/net/openhft/chronicle/core/shutdown/PriorityHook.java index f38de3fbcf..5396826db4 100644 --- a/src/main/java/net/openhft/chronicle/core/shutdown/PriorityHook.java +++ b/src/main/java/net/openhft/chronicle/core/shutdown/PriorityHook.java @@ -18,10 +18,10 @@ package net.openhft.chronicle.core.shutdown; -import net.openhft.chronicle.core.Jvm; - import java.util.*; +import static net.openhft.chronicle.core.Jvm.uncheckedCast; + /** * Collects all hook that need to be run during shutdown to execute them in controlled order. */ @@ -63,7 +63,7 @@ public static synchronized H addAndGet(H hooklet) { Runtime.getRuntime().addShutdownHook(registeredHook.shutdownThread()); } - H registered = Jvm.uncheckedCast(registeredHook.hookletPool.get(hooklet)); + H registered = uncheckedCast(registeredHook.hookletPool.get(hooklet)); if (registered == null) { registeredHook.hookletPool.put(hooklet, hooklet); diff --git a/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java b/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java index 73b3228305..58026d5048 100644 --- a/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java +++ b/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java @@ -27,6 +27,8 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; +import static net.openhft.chronicle.core.Jvm.uncheckedCast; + /** * The CleaningThreadLocal class extends ThreadLocal and ensures that the resources held by * a CleaningThread are cleaned up if the thread dies. @@ -125,7 +127,7 @@ public static void cleanupNonCleaningThreads() { for (Iterator> iter = nctl.nonCleaningThreadValues.entrySet().iterator(); iter.hasNext(); ) { Map.Entry entry = iter.next(); if (!entry.getKey().isAlive()) { - CleaningThreadLocal nctl2b = Jvm.uncheckedCast(nctl2); + CleaningThreadLocal nctl2b = uncheckedCast(nctl2); nctl2b.cleanup(entry.getValue()); iter.remove(); } diff --git a/src/main/java/net/openhft/chronicle/core/util/Mocker.java b/src/main/java/net/openhft/chronicle/core/util/Mocker.java index d9be16d5aa..e196edc7f1 100644 --- a/src/main/java/net/openhft/chronicle/core/util/Mocker.java +++ b/src/main/java/net/openhft/chronicle/core/util/Mocker.java @@ -35,6 +35,8 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; +import static net.openhft.chronicle.core.Jvm.uncheckedCast; + /** * The Mocker class provides utility methods for creating mocked instances of interfaces. */ @@ -149,7 +151,7 @@ public static T intercepting(@NotNull Class interfaceType, @NotNull final public static T intercepting(@NotNull Class interfaceType, @NotNull BiConsumer consumer, T t) { final Set> classes = new LinkedHashSet<>(); addInterface(classes, interfaceType); - return Jvm.uncheckedCast( + return uncheckedCast( newProxyInstance(interfaceType.getClassLoader(), classes.toArray(NO_CLASSES), new AbstractInvocationHandler(interfaceType) { @Override protected Object doInvoke(Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException { @@ -194,7 +196,7 @@ public static T ignored(@NotNull Class interfaceType, Class... additio addInterface(classes, aClass); classes.add(IgnoresEverything.class); ClassLoader tClassLoader = interfaceType.getClassLoader(); - return Jvm.uncheckedCast( + return uncheckedCast( newProxyInstance(tClassLoader != null ? tClassLoader : Mocker.class.getClassLoader(), classes.toArray(NO_CLASSES), new AbstractInvocationHandler(interfaceType) { @Override From d0241a7f0fef483ec45c1b429cf174f0365c5ca1 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 12 Apr 2024 13:45:29 +0100 Subject: [PATCH 19/43] Fix javadoc issues --- src/main/java/net/openhft/chronicle/core/UnsafeMemory.java | 7 ++++--- src/main/java/net/openhft/chronicle/core/util/Ints.java | 4 ++-- src/main/java/net/openhft/chronicle/core/util/Longs.java | 4 ++-- .../java/net/openhft/chronicle/core/util/ObjectUtils.java | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java index abe97dbcb0..e1b317acbf 100644 --- a/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java +++ b/src/main/java/net/openhft/chronicle/core/UnsafeMemory.java @@ -1786,10 +1786,10 @@ public byte readVolatileByte(Object object, long offset) { /** * Reads a short value in a volatile manner from the specified memory address. + * This method currently does not support a short split across cache lines. * * @param address the memory address. * @return the short value read from the address. - * @implNote This method currently does not support a short split across cache lines. */ @Override public short readVolatileShort(long address) { @@ -1845,10 +1845,11 @@ public int readVolatileInt(Object object, long offset) { /** * Reads a float value in a volatile manner from the specified memory address. + * This method currently does not support a float split across cache lines. * * @param address the memory address. * @return the float value read from the address. - * @implNote This method currently does not support a float split across cache lines. + * */ @Override public float readVolatileFloat(long address) { @@ -1902,10 +1903,10 @@ public long readVolatileLong(Object object, long offset) { /** * Reads a double value in a volatile manner from the specified memory address. + * This method currently does not support a double split across cache lines. * * @param address the memory address. * @return the double value read from the address. - * @implNote This method currently does not support a double split across cache lines. */ @Override public double readVolatileDouble(long address) { 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 838e1aa4b4..83c04a7a4d 100644 --- a/src/main/java/net/openhft/chronicle/core/util/Ints.java +++ b/src/main/java/net/openhft/chronicle/core/util/Ints.java @@ -180,11 +180,11 @@ public static String failDescription(final IntTriPredicate requirement, } /** - * Returns a predicate that can test if a value is non-negative (i.e. value >= 0). + * Returns a predicate that can test if a value is non-negative (i.e. value >= 0). *

    * This is equivalent to: {@code negative().negate()} * - * @return a predicate that can test if a value is non-negative (i.e. value >= 0) + * @return a predicate that can test if a value is non-negative (i.e. value >= 0) */ public static IntPredicate nonNegative() { return IntCondition.NON_NEGATIVE; diff --git a/src/main/java/net/openhft/chronicle/core/util/Longs.java b/src/main/java/net/openhft/chronicle/core/util/Longs.java index 5e85547a46..15473e0096 100644 --- a/src/main/java/net/openhft/chronicle/core/util/Longs.java +++ b/src/main/java/net/openhft/chronicle/core/util/Longs.java @@ -175,11 +175,11 @@ private static String failDescription(final LongBiPredicate requirement, } /** - * Returns a predicate that can test if a value is non-negative (i.e. value >= 0). + * Returns a predicate that can test if a value is non-negative (i.e. value >= 0). *

    * This is equivalent to: {@code negative().negate()} * - * @return a predicate that can test if a value is non-negative (i.e. value >= 0) + * @return a predicate that can test if a value is non-negative (i.e. value >= 0) */ public static LongPredicate nonNegative() { return LongCondition.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 6c974a7c5c..6a0df4a98a 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java +++ b/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java @@ -590,7 +590,7 @@ static Number convertToNumber(Class eClass, Object o) throws NumberFormatExce * @throws ClassCastException if the class cannot be cast to the type T. */ @NotNull - public static T newInstance(@NotNull String className) { + public static T newInstance(@NotNull String className) throws ClassCastException { return newInstance((Class) CLASS_ALIASES.forName(className)); } @@ -603,7 +603,7 @@ public static T newInstance(@NotNull String className) { * @throws ClassCastException if the class cannot be cast to the type T. */ @NotNull - public static T newInstance(@NotNull Class clazz) { + public static T newInstance(@NotNull Class clazz) throws ClassCastException { final Supplier cons = supplierClassLocal.get(clazz); return (T) cons.get(); } From d3cc44d212e6969bf735fb7bc8bbf15fa2108295 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 15 Apr 2024 12:55:28 +0100 Subject: [PATCH 20/43] Fix a rounding error --- src/main/java/net/openhft/chronicle/core/Jvm.java | 3 +-- src/test/java/net/openhft/chronicle/core/JvmParseSizeTest.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index 19444b5cfd..0e8d73f9d6 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -1223,8 +1223,7 @@ public static long parseSize(@NotNull String value) throws IllegalArgumentExcept } } double number = Double.parseDouble(value.trim()); - factor *= (long) number; - return factor; + return Math.round(factor * number); } /** diff --git a/src/test/java/net/openhft/chronicle/core/JvmParseSizeTest.java b/src/test/java/net/openhft/chronicle/core/JvmParseSizeTest.java index cf27d47527..bf206d67d4 100644 --- a/src/test/java/net/openhft/chronicle/core/JvmParseSizeTest.java +++ b/src/test/java/net/openhft/chronicle/core/JvmParseSizeTest.java @@ -53,7 +53,7 @@ public static Collection data() { {" 2 M", 2L << 20}, {"0.75GiB", 768L << 20}, {"1.5 GiB", 1536L << 20}, - {"0.001TiB", (1L << 40) / 1000} + {"0.001TiB", Math.round((1L << 40) / 1000.0)} }); } From 5d8661702b2c136c4e30825ec79f18fa78634a11 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 15 Apr 2024 15:56:35 +0100 Subject: [PATCH 21/43] Javadoc fixes from x.26 (#650) --- .../java/net/openhft/chronicle/core/pom/PomPropertiesTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/net/openhft/chronicle/core/pom/PomPropertiesTest.java b/src/test/java/net/openhft/chronicle/core/pom/PomPropertiesTest.java index 4520fc124b..d5fb58a5cf 100644 --- a/src/test/java/net/openhft/chronicle/core/pom/PomPropertiesTest.java +++ b/src/test/java/net/openhft/chronicle/core/pom/PomPropertiesTest.java @@ -1,6 +1,7 @@ package net.openhft.chronicle.core.pom; import org.junit.jupiter.api.Test; + import java.util.Properties; import static org.junit.jupiter.api.Assertions.*; From edd73857c23c2c11601ffcd0e3982c27f8d308b9 Mon Sep 17 00:00:00 2001 From: "yevgen.pavlenko" Date: Wed, 27 Mar 2024 10:06:36 +0200 Subject: [PATCH 22/43] Deprecate due x.26 --- .../net/openhft/chronicle/core/threads/JitterSampler.java | 0 .../net/openhft/chronicle/core/announcer/AnnouncerTest.java | 4 ++-- .../net/openhft/chronicle/core/pom/PomPropertiesTest.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/openhft/chronicle/core/threads/JitterSampler.java diff --git a/src/main/java/net/openhft/chronicle/core/threads/JitterSampler.java b/src/main/java/net/openhft/chronicle/core/threads/JitterSampler.java new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java b/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java index cb8be18660..61c77b1023 100644 --- a/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java +++ b/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java @@ -15,11 +15,11 @@ void testAnnounceWithValidArguments() { @Test void testAnnounceWithNullGroupId() { - assertThrows(NullPointerException.class, () -> Announcer.announce(null, "chronicle-queue")); + assertThrows(IllegalArgumentException.class, () -> Announcer.announce(null, "chronicle-queue")); } @Test void testAnnounceWithNullArtifactId() { - assertThrows(NullPointerException.class, () -> Announcer.announce("net.openhft", null)); + assertThrows(IllegalArgumentException.class, () -> Announcer.announce("net.openhft", null)); } } diff --git a/src/test/java/net/openhft/chronicle/core/pom/PomPropertiesTest.java b/src/test/java/net/openhft/chronicle/core/pom/PomPropertiesTest.java index d5fb58a5cf..eaaf97d0ee 100644 --- a/src/test/java/net/openhft/chronicle/core/pom/PomPropertiesTest.java +++ b/src/test/java/net/openhft/chronicle/core/pom/PomPropertiesTest.java @@ -1,9 +1,9 @@ package net.openhft.chronicle.core.pom; import org.junit.jupiter.api.Test; - import java.util.Properties; -import static org.junit.jupiter.api.Assertions.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; class PomPropertiesTest { From de7bb6e8cda381cc5fb0d5b5879c06b25c190f59 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 28 Mar 2024 13:42:12 +0000 Subject: [PATCH 23/43] Remove se.eris.notnull.instrument --- .../net/openhft/chronicle/core/announcer/AnnouncerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java b/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java index 61c77b1023..cb8be18660 100644 --- a/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java +++ b/src/test/java/net/openhft/chronicle/core/announcer/AnnouncerTest.java @@ -15,11 +15,11 @@ void testAnnounceWithValidArguments() { @Test void testAnnounceWithNullGroupId() { - assertThrows(IllegalArgumentException.class, () -> Announcer.announce(null, "chronicle-queue")); + assertThrows(NullPointerException.class, () -> Announcer.announce(null, "chronicle-queue")); } @Test void testAnnounceWithNullArtifactId() { - assertThrows(IllegalArgumentException.class, () -> Announcer.announce("net.openhft", null)); + assertThrows(NullPointerException.class, () -> Announcer.announce("net.openhft", null)); } } From 0bc7839f946fdc874d544bffba1af2bf4ee77e45 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 10 Apr 2024 16:18:08 +0100 Subject: [PATCH 24/43] resolve Javadoc issues --- .../openhft/chronicle/core/time/UniqueMicroTimeProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/openhft/chronicle/core/time/UniqueMicroTimeProvider.java b/src/main/java/net/openhft/chronicle/core/time/UniqueMicroTimeProvider.java index 55e504e484..d7e609e946 100644 --- a/src/main/java/net/openhft/chronicle/core/time/UniqueMicroTimeProvider.java +++ b/src/main/java/net/openhft/chronicle/core/time/UniqueMicroTimeProvider.java @@ -40,7 +40,7 @@ public class UniqueMicroTimeProvider implements TimeProvider { *

    * This constructor initializes the time provider with zero. New instances are typically created for * testing purposes, as this class is stateful and maintains the last time value issued. - */ + */ public UniqueMicroTimeProvider() { // Do nothing } From 61ee9202228c4a268d73b6219f84d11f3d43ae67 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 15 Apr 2024 18:20:33 +0100 Subject: [PATCH 25/43] Fix Javadoc formatting --- src/main/java/net/openhft/chronicle/core/Jvm.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index 0e8d73f9d6..d007b53f80 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -1505,7 +1505,7 @@ public static A findAnnotation(AnnotatedElement annotated * Typically, the name of these classes contains the "$$Lambda" substring. * Note that this naming convention is JVM-specific and can change * in future versions. The approach is known to work up to Java 21. - * + * * @param clazz the class to be checked. * @return {@code true} if the class is a lambda, {@code false} otherwise. */ From 3464ec53bb2ac1ca7363747fdb84771c86ecd97f Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 16 Apr 2024 08:48:49 +0100 Subject: [PATCH 26/43] Fix test after merge --- .../chronicle/core/internal/pom/InternalPomProperties.java | 2 +- .../java/net/openhft/chronicle/core/pom/PomProperties.java | 4 ++-- .../java/net/openhft/chronicle/core/util/ObjectUtils.java | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/core/internal/pom/InternalPomProperties.java b/src/main/java/net/openhft/chronicle/core/internal/pom/InternalPomProperties.java index 4352aa122b..12260498d1 100644 --- a/src/main/java/net/openhft/chronicle/core/internal/pom/InternalPomProperties.java +++ b/src/main/java/net/openhft/chronicle/core/internal/pom/InternalPomProperties.java @@ -35,7 +35,7 @@ private InternalPomProperties() { private static final Map VERSION_CACHE = new ConcurrentHashMap<>(); @NotNull - public static Properties create(@NotNull final String groupId, @NotNull final String artifactId) { + public static Properties create(final String groupId, final String artifactId) { ObjectUtils.requireNonNull(groupId); ObjectUtils.requireNonNull(artifactId); final Properties properties = new Properties(); 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 2c8aa110af..a1d0da8531 100644 --- a/src/main/java/net/openhft/chronicle/core/pom/PomProperties.java +++ b/src/main/java/net/openhft/chronicle/core/pom/PomProperties.java @@ -41,7 +41,7 @@ private PomProperties() { * @return a new instance of Properties for the provided parameters. */ @NotNull - public static Properties create(@NotNull final String groupId, @NotNull final String artifactId) { + public static Properties create(final String groupId, final String artifactId) { return InternalPomProperties.create(groupId, artifactId); } @@ -58,7 +58,7 @@ public static Properties create(@NotNull final String groupId, @NotNull final St * the version cannot be determined * @see #create(String, String) */ - public static String version(@NotNull final String groupId, @NotNull final String artifactId) { + public static String version(final String groupId, final String artifactId) { return InternalPomProperties.version(groupId, artifactId); } } 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 6a0df4a98a..71074f8c66 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java +++ b/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java @@ -928,13 +928,12 @@ static class ThrowsCCE implements ThrowingFunction { /** * Standard mechanism to determine objects as not null. Same method contract as {@link Objects#requireNonNull(Object)} - * and also decorated with {@link NotNull} so that IntelliJ and other static analysis tools can work their magic. * * @param o reference to check for nullity * @throws NullPointerException If o is {@code null } */ @SuppressWarnings("UnusedReturnValue") - public static T requireNonNull(@NotNull T o) { + public static T requireNonNull(T o) { // see https://stackoverflow.com/questions/43115645/in-java-lambdas-why-is-getclass-called-on-a-captured-variable // Maybe calling Objects.requireNonNull is just as optimisable/intrinisfiable but I didn't do the research o.getClass(); From d50490a97bfc88a3aa4f621e88bd92157e1c3037 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 29 Apr 2024 16:19:49 +0100 Subject: [PATCH 27/43] Fix warnings following rebase with develop --- .../java/net/openhft/chronicle/core/Jvm.java | 82 ------------------- 1 file changed, 82 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index d007b53f80..cdad510f84 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -1603,88 +1603,6 @@ public static long currentThreadId() { return Thread.currentThread().getId(); } - /** - * Performs an unchecked cast of an object to the target type {@code T}. This method - * bypasses generic type checks, allowing for casting without explicit type checking, - * offering a convenient way to avoid compiler warnings for unchecked casts. - *

    - * Note: Use with caution as improper use can lead to {@link ClassCastException} at runtime - * if the object is not of type {@code T}. Intended for situations where the type safety is - * guaranteed through other means but cannot be expressed without generic type warnings. - * - * @param the target type to cast to - * @param o the object to be cast - * @return the casted object of type {@code T} - * @throws ClassCastException if the object cannot be casted to the target type {@code T} - * (a runtime risk due to type erasure) - */ - @SuppressWarnings("unchecked") - public static T uncheckedCast(Object o) { - return (T) o; - } - - /** - * Performs an unchecked cast of an array of objects to an array of the target type {@code T[]}. - * This method bypasses generic array type checks, facilitating casting without explicit array - * type checking. - *

    - * Note: Use with caution as improper use can lead to {@link ClassCastException} at runtime - * if the objects in the array cannot be cast to type {@code T[]}. This method is useful when - * the programmer is confident in the implicit type safety of the operation but wishes to avoid - * compiler warnings about unchecked operations. - * - * @param the target component type of the array to cast to - * @param o the object array to be cast - * @return the casted object array of type {@code T[]} - * @throws ClassCastException if the objects in the array cannot be cast to the component type {@code T[]} - */ - @SuppressWarnings("unchecked") - public static T[] uncheckedCast(Object[] o) { - return (T[]) o; - } - - /** - * Performs an unchecked cast of a {@code Class} object to {@code Class}. This operation - * is particularly useful in scenarios involving reflection where generic type parameters are - * known but cannot be statically enforced by the compiler. - *

    - * By bypassing compile-time generic type checks, it provides a way to work with generic types - * in a dynamic context at the cost of compile-time type safety. - *

    - * Note: Use with caution as improper use can lead to a {@link ClassCastException} at runtime - * if the class object cannot actually be cast to {@code Class}. This method should be - * employed when there is certainty about the underlying type compatibility. - * - * @param the target generic type to cast the class to - * @param o the class object to be cast - * @return the class object cast to {@code Class} - * @throws ClassCastException if the class object cannot be cast to {@code Class} - * (a runtime risk inherent to unchecked casting) - */ - @SuppressWarnings({"unchecked", "rawtypes"}) - public static Class uncheckedCast(Class o) { - return (Class) o; - } - - /** - * Retrieves the unique identifier of the current thread. - *

    - * This method provides a straightforward way to obtain the ID of the thread - * from which the method is called. Currently, it uses {@link Thread#currentThread()} - * and {@link Thread#getId()} to accomplish this. The method is safe to use across - * various versions of Java. - *

    - * Note: In future versions, this implementation may be updated to use {@code Thread.threadId()} - * or another updated mechanism for obtaining the thread ID, as newer Java versions from version 19 - * deprecate the current approach. - * - * @return the identifier of the current thread - */ - @SuppressWarnings("deprecation") - public static long currentThreadId() { - return Thread.currentThread().getId(); - } - public interface SignalHandler { /** * Handle a Signal From 55003c51d2073027cd6b85d489ed203f06c54ba8 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 30 Apr 2024 09:03:05 +0100 Subject: [PATCH 28/43] Fix warnings following rebase with develop --- .../openhft/chronicle/core/pom/PomPropertiesTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/java/net/openhft/chronicle/core/pom/PomPropertiesTest.java b/src/test/java/net/openhft/chronicle/core/pom/PomPropertiesTest.java index eaaf97d0ee..09c5e5450c 100644 --- a/src/test/java/net/openhft/chronicle/core/pom/PomPropertiesTest.java +++ b/src/test/java/net/openhft/chronicle/core/pom/PomPropertiesTest.java @@ -4,6 +4,7 @@ import java.util.Properties; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; class PomPropertiesTest { @@ -15,13 +16,13 @@ void testCreateWithValidArguments() { @Test void testCreateWithNullGroupId() { - assertEquals("{}", - PomProperties.create(null, "chronicle-queue").toString()); + assertThrows(NullPointerException.class, + () -> PomProperties.create(null, "chronicle-queue").toString()); } @Test void testCreateWithNullArtifactId() { - assertEquals("{}", - PomProperties.create("net.openhft", null).toString()); + assertThrows(NullPointerException.class, + () -> PomProperties.create("net.openhft", null).toString()); } } From e8b7bc0eeefabe9b048083539b6b7e574498c2ad Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 7 May 2024 18:48:15 +0100 Subject: [PATCH 29/43] Fix newlines --- .../net/openhft/chronicle/core/benchmark/Interrupted.java | 1 - .../java/net/openhft/chronicle/core/benchmark/MatrixMain.java | 1 - src/main/java/net/openhft/chronicle/core/Jvm.java | 1 - .../chronicle/core/internal/announcer/InternalAnnouncer.java | 1 - .../chronicle/core/internal/util/DirectBufferUtil.java | 1 - .../net/openhft/chronicle/core/internal/util/MapUtil.java | 1 - .../core/internal/util/ThreadConfinementLifecycle.java | 1 - .../openhft/chronicle/core/io/ClosedIORuntimeException.java | 1 - src/main/java/net/openhft/chronicle/core/pool/EnumCache.java | 1 - .../chronicle/core/scoped/StrongReferenceScopedResource.java | 1 - .../net/openhft/chronicle/core/threads/CancellableTimer.java | 1 - .../java/net/openhft/chronicle/core/threads/EventHandler.java | 1 - .../net/openhft/chronicle/core/time/PosixTimeProvider.java | 1 - .../java/net/openhft/chronicle/core/time/TimeProvider.java | 1 - .../chronicle/core/util/InvocationTargetRuntimeException.java | 1 - src/main/java/net/openhft/chronicle/core/util/Longs.java | 1 - .../java/net/openhft/chronicle/core/util/ObjectUtils.java | 1 - .../chronicle/core/util/ThreadConfinementAsserter.java | 1 - src/main/java/net/openhft/chronicle/core/util/Time.java | 1 - src/main/java/net/openhft/chronicle/core/util/TypeOf.java | 1 - src/test/java/net/openhft/chronicle/core/CoreTestCommon.java | 1 - src/test/java/net/openhft/chronicle/core/JvmMain.java | 1 - .../java/net/openhft/chronicle/core/UnsafeMemory2Test.java | 1 - .../java/net/openhft/chronicle/core/UnsafeMemoryTest.java | 1 - .../net/openhft/chronicle/core/UnsafeMemoryTestMixin.java | 4 ---- .../openhft/chronicle/core/ZeroCostAssertionStatusTest.java | 1 - .../openhft/chronicle/core/annotation/ScopeConfinedTest.java | 1 - .../net/openhft/chronicle/core/benchmarks/Randomness.java | 1 - .../openhft/chronicle/core/cleaner/impl/CleanerTestUtil.java | 1 - .../openhft/chronicle/core/internal/CloseableUtilsTest.java | 3 +-- src/test/java/net/openhft/chronicle/core/io/IOToolsTest.java | 2 -- .../net/openhft/chronicle/core/pool/ClassAliasPoolTest.java | 1 - .../net/openhft/chronicle/core/pool/StringInternerTest.java | 2 -- .../java/net/openhft/chronicle/core/shutdown/HookletTest.java | 2 +- .../chronicle/core/threads/CleaningThreadLocalTest.java | 2 +- .../openhft/chronicle/core/time/SystemTimeProviderTest.java | 1 - .../chronicle/core/time/UniqueMicroTimeProviderTest.java | 1 - .../net/openhft/chronicle/core/util/ByteConsumerTest.java | 1 - .../net/openhft/chronicle/core/util/IntConditionTest.java | 1 - .../openhft/chronicle/core/util/RecordingHistogramTest.java | 1 - 40 files changed, 3 insertions(+), 46 deletions(-) diff --git a/benchmarks/src/main/java/net/openhft/chronicle/core/benchmark/Interrupted.java b/benchmarks/src/main/java/net/openhft/chronicle/core/benchmark/Interrupted.java index 6bf79d30d8..c10d41b7d7 100644 --- a/benchmarks/src/main/java/net/openhft/chronicle/core/benchmark/Interrupted.java +++ b/benchmarks/src/main/java/net/openhft/chronicle/core/benchmark/Interrupted.java @@ -91,4 +91,3 @@ public boolean isInterrupted() { } } } - diff --git a/benchmarks/src/main/java/net/openhft/chronicle/core/benchmark/MatrixMain.java b/benchmarks/src/main/java/net/openhft/chronicle/core/benchmark/MatrixMain.java index 0a52ea8c68..ac0f0335ca 100644 --- a/benchmarks/src/main/java/net/openhft/chronicle/core/benchmark/MatrixMain.java +++ b/benchmarks/src/main/java/net/openhft/chronicle/core/benchmark/MatrixMain.java @@ -162,4 +162,3 @@ public RealMatrix DoubleMatrix() { return matrix.multiply(matrix2); } } - diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index cdad510f84..fd0624ef01 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -1682,7 +1682,6 @@ private static void addSignalHandler(final String sig, final sun.misc.SignalHand Jvm.warn().on(signalHandler.getClass(), "Unable add a signal handler", e); } } - } static final class ChainedSignalHandler implements sun.misc.SignalHandler { diff --git a/src/main/java/net/openhft/chronicle/core/internal/announcer/InternalAnnouncer.java b/src/main/java/net/openhft/chronicle/core/internal/announcer/InternalAnnouncer.java index 90e5d1e4b1..8c5f6576eb 100644 --- a/src/main/java/net/openhft/chronicle/core/internal/announcer/InternalAnnouncer.java +++ b/src/main/java/net/openhft/chronicle/core/internal/announcer/InternalAnnouncer.java @@ -121,5 +121,4 @@ private static boolean alwaysAnnounce(@NotNull final Map propert return properties.containsKey("logo"); return true; } - } 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 f8bc36b8ce..b8fd49812a 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 @@ -70,5 +70,4 @@ public static long addressOrThrow(final ByteBuffer buffer) { requireNonNull(buffer); return ((DirectBuffer) buffer).address(); } - } diff --git a/src/main/java/net/openhft/chronicle/core/internal/util/MapUtil.java b/src/main/java/net/openhft/chronicle/core/internal/util/MapUtil.java index f4499d1b4e..1bf1da84d9 100644 --- a/src/main/java/net/openhft/chronicle/core/internal/util/MapUtil.java +++ b/src/main/java/net/openhft/chronicle/core/internal/util/MapUtil.java @@ -49,5 +49,4 @@ public static Map ofUnmodifiable(final Map.Entry... entries) .map(ObjectUtils::requireNonNull) .collect(collectingAndThen(toMap(Map.Entry::getKey, Map.Entry::getValue), Collections::unmodifiableMap)); } - } diff --git a/src/main/java/net/openhft/chronicle/core/internal/util/ThreadConfinementLifecycle.java b/src/main/java/net/openhft/chronicle/core/internal/util/ThreadConfinementLifecycle.java index 7fd8cb5f2f..5a1e755ddb 100644 --- a/src/main/java/net/openhft/chronicle/core/internal/util/ThreadConfinementLifecycle.java +++ b/src/main/java/net/openhft/chronicle/core/internal/util/ThreadConfinementLifecycle.java @@ -52,5 +52,4 @@ private static boolean testAssert(final AtomicBoolean ae) { ae.set(true); return true; } - } diff --git a/src/main/java/net/openhft/chronicle/core/io/ClosedIORuntimeException.java b/src/main/java/net/openhft/chronicle/core/io/ClosedIORuntimeException.java index c4d145cf5c..003d41c648 100644 --- a/src/main/java/net/openhft/chronicle/core/io/ClosedIORuntimeException.java +++ b/src/main/java/net/openhft/chronicle/core/io/ClosedIORuntimeException.java @@ -76,5 +76,4 @@ public ClosedIORuntimeException(String message) { public ClosedIORuntimeException(String message, Throwable thrown) { super(message, thrown); } - } 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 3bc409a75e..1975e8285b 100644 --- a/src/main/java/net/openhft/chronicle/core/pool/EnumCache.java +++ b/src/main/java/net/openhft/chronicle/core/pool/EnumCache.java @@ -138,5 +138,4 @@ private static , S extends Enum & CoreDynamic ? new DynamicEnumClass<>((Class) eClass) : new StaticEnumClass<>((Class) eClass)); } - } diff --git a/src/main/java/net/openhft/chronicle/core/scoped/StrongReferenceScopedResource.java b/src/main/java/net/openhft/chronicle/core/scoped/StrongReferenceScopedResource.java index 87abe6868f..e6d4478fd4 100644 --- a/src/main/java/net/openhft/chronicle/core/scoped/StrongReferenceScopedResource.java +++ b/src/main/java/net/openhft/chronicle/core/scoped/StrongReferenceScopedResource.java @@ -31,4 +31,3 @@ public Class getType() { return resource.getClass(); } } - diff --git a/src/main/java/net/openhft/chronicle/core/threads/CancellableTimer.java b/src/main/java/net/openhft/chronicle/core/threads/CancellableTimer.java index 364a3b69c1..3b912b53fd 100644 --- a/src/main/java/net/openhft/chronicle/core/threads/CancellableTimer.java +++ b/src/main/java/net/openhft/chronicle/core/threads/CancellableTimer.java @@ -193,4 +193,3 @@ public String toString() { } } } - diff --git a/src/main/java/net/openhft/chronicle/core/threads/EventHandler.java b/src/main/java/net/openhft/chronicle/core/threads/EventHandler.java index 8365e89149..8bef721e0e 100644 --- a/src/main/java/net/openhft/chronicle/core/threads/EventHandler.java +++ b/src/main/java/net/openhft/chronicle/core/threads/EventHandler.java @@ -81,4 +81,3 @@ default HandlerPriority priority() { return HandlerPriority.MEDIUM; } } - diff --git a/src/main/java/net/openhft/chronicle/core/time/PosixTimeProvider.java b/src/main/java/net/openhft/chronicle/core/time/PosixTimeProvider.java index 3f28da369e..1ad84d6280 100644 --- a/src/main/java/net/openhft/chronicle/core/time/PosixTimeProvider.java +++ b/src/main/java/net/openhft/chronicle/core/time/PosixTimeProvider.java @@ -72,4 +72,3 @@ public long currentTimeNanos() { return PosixAPI.posix().clock_gettime(ClockId.CLOCK_REALTIME); } } - diff --git a/src/main/java/net/openhft/chronicle/core/time/TimeProvider.java b/src/main/java/net/openhft/chronicle/core/time/TimeProvider.java index 1a473b87da..8405a40975 100644 --- a/src/main/java/net/openhft/chronicle/core/time/TimeProvider.java +++ b/src/main/java/net/openhft/chronicle/core/time/TimeProvider.java @@ -75,5 +75,4 @@ default long currentTimeMicros() throws IllegalStateException { default long currentTimeNanos() throws IllegalStateException { return currentTimeMicros() * 1000; } - } diff --git a/src/main/java/net/openhft/chronicle/core/util/InvocationTargetRuntimeException.java b/src/main/java/net/openhft/chronicle/core/util/InvocationTargetRuntimeException.java index 7564487f43..8122a6394e 100644 --- a/src/main/java/net/openhft/chronicle/core/util/InvocationTargetRuntimeException.java +++ b/src/main/java/net/openhft/chronicle/core/util/InvocationTargetRuntimeException.java @@ -55,4 +55,3 @@ public InvocationTargetRuntimeException(@NotNull Throwable cause) { super(cause instanceof InvocationTargetException ? cause.getCause() : cause); } } - diff --git a/src/main/java/net/openhft/chronicle/core/util/Longs.java b/src/main/java/net/openhft/chronicle/core/util/Longs.java index 15473e0096..0eee3e5f76 100644 --- a/src/main/java/net/openhft/chronicle/core/util/Longs.java +++ b/src/main/java/net/openhft/chronicle/core/util/Longs.java @@ -141,7 +141,6 @@ public static boolean assertIfEnabled(final LongBiPredicate requirement, return true; } - /** * Returns a human-readable form of a failure message provided that the provided {@code value} did not * satisfy the provided {@code requirement}. 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 71074f8c66..1d5de235bc 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java +++ b/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java @@ -939,5 +939,4 @@ public static T requireNonNull(T o) { o.getClass(); return o; } - } diff --git a/src/main/java/net/openhft/chronicle/core/util/ThreadConfinementAsserter.java b/src/main/java/net/openhft/chronicle/core/util/ThreadConfinementAsserter.java index 47b55789ab..06a3a4dc05 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ThreadConfinementAsserter.java +++ b/src/main/java/net/openhft/chronicle/core/util/ThreadConfinementAsserter.java @@ -49,5 +49,4 @@ static ThreadConfinementAsserter create() { static ThreadConfinementAsserter createEnabled() { return ThreadConfinementLifecycle.createEnabled(); } - } diff --git a/src/main/java/net/openhft/chronicle/core/util/Time.java b/src/main/java/net/openhft/chronicle/core/util/Time.java index 23cf3a8803..e6fa058774 100644 --- a/src/main/java/net/openhft/chronicle/core/util/Time.java +++ b/src/main/java/net/openhft/chronicle/core/util/Time.java @@ -41,5 +41,4 @@ public static String uniqueId() { } return Long.toString(l, 36); } - } diff --git a/src/main/java/net/openhft/chronicle/core/util/TypeOf.java b/src/main/java/net/openhft/chronicle/core/util/TypeOf.java index ab01a5f4e8..9779dc205c 100644 --- a/src/main/java/net/openhft/chronicle/core/util/TypeOf.java +++ b/src/main/java/net/openhft/chronicle/core/util/TypeOf.java @@ -64,4 +64,3 @@ private Type extractType() { return pt.getActualTypeArguments()[0]; } } - diff --git a/src/test/java/net/openhft/chronicle/core/CoreTestCommon.java b/src/test/java/net/openhft/chronicle/core/CoreTestCommon.java index 63ed04ec93..be6111a25e 100644 --- a/src/test/java/net/openhft/chronicle/core/CoreTestCommon.java +++ b/src/test/java/net/openhft/chronicle/core/CoreTestCommon.java @@ -78,5 +78,4 @@ public void afterChecks() { protected void assertReferencesReleased() { ReferenceCountedUtils.assertReferencesReleased(); } - } diff --git a/src/test/java/net/openhft/chronicle/core/JvmMain.java b/src/test/java/net/openhft/chronicle/core/JvmMain.java index a0099c866d..6584188d96 100644 --- a/src/test/java/net/openhft/chronicle/core/JvmMain.java +++ b/src/test/java/net/openhft/chronicle/core/JvmMain.java @@ -24,4 +24,3 @@ public static void main(String[] args) { assertTrue(!isWarn.isInfoEnabled() && isWarn.isWarnEnabled()); } } - diff --git a/src/test/java/net/openhft/chronicle/core/UnsafeMemory2Test.java b/src/test/java/net/openhft/chronicle/core/UnsafeMemory2Test.java index e476f94daa..e32c6e4bc7 100644 --- a/src/test/java/net/openhft/chronicle/core/UnsafeMemory2Test.java +++ b/src/test/java/net/openhft/chronicle/core/UnsafeMemory2Test.java @@ -616,5 +616,4 @@ public void directMemoryVolatileDouble() { static class MyDTO { int num; } - } diff --git a/src/test/java/net/openhft/chronicle/core/UnsafeMemoryTest.java b/src/test/java/net/openhft/chronicle/core/UnsafeMemoryTest.java index 5943fa81aa..61641cc43d 100644 --- a/src/test/java/net/openhft/chronicle/core/UnsafeMemoryTest.java +++ b/src/test/java/net/openhft/chronicle/core/UnsafeMemoryTest.java @@ -32,7 +32,6 @@ import static net.openhft.chronicle.core.UnsafeMemory.UNSAFE; import static org.junit.Assert.*; - @RunWith(Parameterized.class) public class UnsafeMemoryTest extends CoreTestCommon { diff --git a/src/test/java/net/openhft/chronicle/core/UnsafeMemoryTestMixin.java b/src/test/java/net/openhft/chronicle/core/UnsafeMemoryTestMixin.java index 6b581de825..28969c6bab 100644 --- a/src/test/java/net/openhft/chronicle/core/UnsafeMemoryTestMixin.java +++ b/src/test/java/net/openhft/chronicle/core/UnsafeMemoryTestMixin.java @@ -242,7 +242,6 @@ String name() { T operation() { return operation; } - } @FunctionalInterface @@ -368,7 +367,6 @@ public long addr() { public void close() { closer.run(); } - } static Mode mode(Arguments args) { @@ -401,7 +399,5 @@ enum Mode { public boolean isDirectAddressing() { return this == NATIVE_ADDRESS; } - } - } diff --git a/src/test/java/net/openhft/chronicle/core/ZeroCostAssertionStatusTest.java b/src/test/java/net/openhft/chronicle/core/ZeroCostAssertionStatusTest.java index 52a7cddb52..f0bf311ec9 100644 --- a/src/test/java/net/openhft/chronicle/core/ZeroCostAssertionStatusTest.java +++ b/src/test/java/net/openhft/chronicle/core/ZeroCostAssertionStatusTest.java @@ -42,5 +42,4 @@ void show() { System.out.println("Normal assertions are " + (ae ? "ON" : "OFF")); System.out.println("Zero-cost assertions are " + (zcae ? "ON" : "OFF")); } - } diff --git a/src/test/java/net/openhft/chronicle/core/annotation/ScopeConfinedTest.java b/src/test/java/net/openhft/chronicle/core/annotation/ScopeConfinedTest.java index c35d2b775c..d08e131156 100644 --- a/src/test/java/net/openhft/chronicle/core/annotation/ScopeConfinedTest.java +++ b/src/test/java/net/openhft/chronicle/core/annotation/ScopeConfinedTest.java @@ -48,5 +48,4 @@ interface Foo { Stream<@ScopeConfined T> stream(); } - } diff --git a/src/test/java/net/openhft/chronicle/core/benchmarks/Randomness.java b/src/test/java/net/openhft/chronicle/core/benchmarks/Randomness.java index 20eaf00961..75906aa7c9 100644 --- a/src/test/java/net/openhft/chronicle/core/benchmarks/Randomness.java +++ b/src/test/java/net/openhft/chronicle/core/benchmarks/Randomness.java @@ -58,5 +58,4 @@ public static void main(String[] args) { System.out.println("Average score: " + scoreSum / 500); System.out.printf("Average time %.3f us%n", time / timeCount / 1e3); } - } diff --git a/src/test/java/net/openhft/chronicle/core/cleaner/impl/CleanerTestUtil.java b/src/test/java/net/openhft/chronicle/core/cleaner/impl/CleanerTestUtil.java index 671c52baee..a3e1c9d0eb 100644 --- a/src/test/java/net/openhft/chronicle/core/cleaner/impl/CleanerTestUtil.java +++ b/src/test/java/net/openhft/chronicle/core/cleaner/impl/CleanerTestUtil.java @@ -66,5 +66,4 @@ public static void test(final Consumer cleaner) { fail(e); } } - } diff --git a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java index cd4fa1bfda..f54094a093 100644 --- a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java +++ b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java @@ -13,7 +13,6 @@ import java.nio.channels.ServerSocketChannel; import java.util.Collection; - import static net.openhft.chronicle.core.Jvm.uncheckedCast; import static org.junit.Assert.*; import static org.junit.Assume.assumeTrue; @@ -144,4 +143,4 @@ public void testCloseQuietlyHttpURLConnection() { verify(mockHttpURLConnection, times(1)).disconnect(); } -} \ No newline at end of file +} diff --git a/src/test/java/net/openhft/chronicle/core/io/IOToolsTest.java b/src/test/java/net/openhft/chronicle/core/io/IOToolsTest.java index 3227815d80..9bb2d3a638 100644 --- a/src/test/java/net/openhft/chronicle/core/io/IOToolsTest.java +++ b/src/test/java/net/openhft/chronicle/core/io/IOToolsTest.java @@ -136,8 +136,6 @@ public void testReadAsBytes() throws IOException { assertArrayEquals(testData.getBytes(), bytes); } - - @Test public void readFileManyTimesByPath() { final int iterations = 3_000; diff --git a/src/test/java/net/openhft/chronicle/core/pool/ClassAliasPoolTest.java b/src/test/java/net/openhft/chronicle/core/pool/ClassAliasPoolTest.java index eb77377584..b9b939e69b 100644 --- a/src/test/java/net/openhft/chronicle/core/pool/ClassAliasPoolTest.java +++ b/src/test/java/net/openhft/chronicle/core/pool/ClassAliasPoolTest.java @@ -33,7 +33,6 @@ public class ClassAliasPoolTest extends CoreTestCommon { - @Test public void testApplyAliasForSet() { assertEquals("!set", CLASS_ALIASES.applyAlias("Set").toString()); diff --git a/src/test/java/net/openhft/chronicle/core/pool/StringInternerTest.java b/src/test/java/net/openhft/chronicle/core/pool/StringInternerTest.java index 8b90b30ef8..0f648a08f2 100644 --- a/src/test/java/net/openhft/chronicle/core/pool/StringInternerTest.java +++ b/src/test/java/net/openhft/chronicle/core/pool/StringInternerTest.java @@ -41,7 +41,6 @@ public void testInternIndex() throws IllegalArgumentException { for (int i = 0; i < 100; i++) { assertEquals("" + i, si.get(si.index("" + i, null))); } - } private String[] uppercase; @@ -77,5 +76,4 @@ private String randomLowercaseString() { } return sb.toString(); } - } diff --git a/src/test/java/net/openhft/chronicle/core/shutdown/HookletTest.java b/src/test/java/net/openhft/chronicle/core/shutdown/HookletTest.java index 8859154a84..f958b4d893 100644 --- a/src/test/java/net/openhft/chronicle/core/shutdown/HookletTest.java +++ b/src/test/java/net/openhft/chronicle/core/shutdown/HookletTest.java @@ -74,4 +74,4 @@ public void testToString() { assertTrue(toStringResult.startsWith("Hooklet{ priority: 10, identity: ")); assertTrue(toStringResult.contains("HookletTest")); } -} \ No newline at end of file +} diff --git a/src/test/java/net/openhft/chronicle/core/threads/CleaningThreadLocalTest.java b/src/test/java/net/openhft/chronicle/core/threads/CleaningThreadLocalTest.java index 287b32bb13..4adb5da3b2 100644 --- a/src/test/java/net/openhft/chronicle/core/threads/CleaningThreadLocalTest.java +++ b/src/test/java/net/openhft/chronicle/core/threads/CleaningThreadLocalTest.java @@ -94,4 +94,4 @@ private void joinThread(Thread thread) { throw new RuntimeException(e); } } -} \ No newline at end of file +} diff --git a/src/test/java/net/openhft/chronicle/core/time/SystemTimeProviderTest.java b/src/test/java/net/openhft/chronicle/core/time/SystemTimeProviderTest.java index 9f9ac29bc5..d60c157678 100644 --- a/src/test/java/net/openhft/chronicle/core/time/SystemTimeProviderTest.java +++ b/src/test/java/net/openhft/chronicle/core/time/SystemTimeProviderTest.java @@ -139,6 +139,5 @@ public void resolution() { // Performance test assertTrue(h.totalCount() > 0); } - } } diff --git a/src/test/java/net/openhft/chronicle/core/time/UniqueMicroTimeProviderTest.java b/src/test/java/net/openhft/chronicle/core/time/UniqueMicroTimeProviderTest.java index 0b81da1023..976cefb89b 100644 --- a/src/test/java/net/openhft/chronicle/core/time/UniqueMicroTimeProviderTest.java +++ b/src/test/java/net/openhft/chronicle/core/time/UniqueMicroTimeProviderTest.java @@ -222,4 +222,3 @@ public void currentTimeNanosShouldBeCorrect() { } } } - diff --git a/src/test/java/net/openhft/chronicle/core/util/ByteConsumerTest.java b/src/test/java/net/openhft/chronicle/core/util/ByteConsumerTest.java index d3eb02bdcc..b0c46f033d 100644 --- a/src/test/java/net/openhft/chronicle/core/util/ByteConsumerTest.java +++ b/src/test/java/net/openhft/chronicle/core/util/ByteConsumerTest.java @@ -15,5 +15,4 @@ void acceptShouldPerformOperation() { assertEquals((byte) 10, resultContainer[0]); } - } diff --git a/src/test/java/net/openhft/chronicle/core/util/IntConditionTest.java b/src/test/java/net/openhft/chronicle/core/util/IntConditionTest.java index ceb4dbfd8b..49698f04d6 100644 --- a/src/test/java/net/openhft/chronicle/core/util/IntConditionTest.java +++ b/src/test/java/net/openhft/chronicle/core/util/IntConditionTest.java @@ -125,5 +125,4 @@ private void test(IntCondition predicate, private static Map.Entry entry(int value, boolean expected) { return new AbstractMap.SimpleImmutableEntry<>(value, expected); } - } diff --git a/src/test/java/net/openhft/chronicle/core/util/RecordingHistogramTest.java b/src/test/java/net/openhft/chronicle/core/util/RecordingHistogramTest.java index 3e48f45053..b43c0d3624 100644 --- a/src/test/java/net/openhft/chronicle/core/util/RecordingHistogramTest.java +++ b/src/test/java/net/openhft/chronicle/core/util/RecordingHistogramTest.java @@ -54,7 +54,6 @@ public void testReset() { histogram.reset(); } - @Test public void testSamples() { Histogram h = new MyRecordingHistogram(); From 5bd791b33d4bb4b9ba66f4475c5879bd9c8fd107 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 20 May 2024 11:08:34 +0100 Subject: [PATCH 30/43]

    tag in javadoc not allowed --- .../java/net/openhft/chronicle/core/pool/ClassLookup.java | 4 ++-- .../openhft/chronicle/core/time/UniqueMicroTimeProvider.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 4ec9517d86..0eec0534c0 100644 --- a/src/main/java/net/openhft/chronicle/core/pool/ClassLookup.java +++ b/src/main/java/net/openhft/chronicle/core/pool/ClassLookup.java @@ -110,12 +110,12 @@ default ClassLookup wrap(@NotNull ClassLoader classLoader) { * match is found, it attempts to find a match using a case-insensitive search. This dual-step lookup * ensures that aliases can be effectively used regardless of case sensitivity. If after both steps * no alias is found, the method returns the original class name, ensuring that the operation is - * always safe and will not result in a loss of reference.

    + * always safe and will not result in a loss of reference. * *

    Usage of this method can significantly reduce the verbosity of class references in scenarios * where short, memorable aliases are preferred over full class names. It is particularly useful * in configuration files, dynamic class loading scenarios, or any context where class names are - * used as strings and brevity or clarity is desired.

    + * used as strings and brevity or clarity is desired. * * @param name The CharSequence representing the class name or alias to be transformed. * @return A CharSequence representing the aliased class name if an alias exists, or the diff --git a/src/main/java/net/openhft/chronicle/core/time/UniqueMicroTimeProvider.java b/src/main/java/net/openhft/chronicle/core/time/UniqueMicroTimeProvider.java index d7e609e946..87d8d5ec2b 100644 --- a/src/main/java/net/openhft/chronicle/core/time/UniqueMicroTimeProvider.java +++ b/src/main/java/net/openhft/chronicle/core/time/UniqueMicroTimeProvider.java @@ -27,7 +27,7 @@ * even across rapid successive calls. * *

    This implementation is particularly useful in environments where unique time stamps are critical and - * the application might request them at a high rate.

    + * the application might request them at a high rate. */ public class UniqueMicroTimeProvider implements TimeProvider { public static final UniqueMicroTimeProvider INSTANCE = new UniqueMicroTimeProvider(); From 7b273762c537512ec2a169e2098b5628a5577dca Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Fri, 3 May 2024 11:35:54 +0100 Subject: [PATCH 31/43] Flaky test (#653) * Give more time for bg thread in flaky test * Give more time for bg thread in flaky test --- .../net/openhft/chronicle/core/threads/ThreadDumpTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/java/net/openhft/chronicle/core/threads/ThreadDumpTest.java b/src/test/java/net/openhft/chronicle/core/threads/ThreadDumpTest.java index 60d6b64abc..30f4d4620d 100644 --- a/src/test/java/net/openhft/chronicle/core/threads/ThreadDumpTest.java +++ b/src/test/java/net/openhft/chronicle/core/threads/ThreadDumpTest.java @@ -39,12 +39,15 @@ void testAssertNoNewThreads() { void testAssertNewThreads() { assumeFalse(Jvm.isArm()); Thread newThread = new Thread(() -> { - Jvm.pause(1000); + Jvm.pause(10000); }); newThread.start(); + // ensure the thread has started + Jvm.pause(100); + // Expect an AssertionError since a new thread is running - assertThrows(AssertionError.class, threadDump::assertNoNewThreads); + assertThrows(AssertionError.class, threadDump::assertNoNewThreads, "newThread.isAlive()= " + newThread.isAlive()); // Clean up newThread.interrupt(); From 09d9c6b897956ec549893b120bde7aef5ba55f36 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 20 May 2024 09:51:46 +0100 Subject: [PATCH 32/43] Core/issues/656 (#657) * don't use reflection and recursion in IOTools.unmonitor * Using reflection to unmonitor a reference results in errors in Java 17 Fixes #656 * Using reflection to unmonitor a reference results in errors in Java 17 Fixes https://github.com/OpenHFT/Chronicle-Core/issues/656 * Using reflection to unmonitor a reference results in errors in Java 17 Fixes https://github.com/OpenHFT/Chronicle-Core/issues/656 --------- Co-authored-by: Jerry Shea --- .../core/internal/CloseableUtils.java | 20 ++++---- .../chronicle/core/io/AbstractCloseable.java | 10 +++- .../io/AbstractCloseableReferenceCounted.java | 7 +++ .../core/io/AbstractReferenceCounted.java | 7 ++- .../openhft/chronicle/core/io/IOTools.java | 41 +--------------- .../chronicle/core/io/Monitorable.java | 47 +++++++++++++++++++ .../core/internal/CloseableUtilsTest.java | 30 ++++++++---- 7 files changed, 100 insertions(+), 62 deletions(-) create mode 100644 src/main/java/net/openhft/chronicle/core/io/Monitorable.java 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 f39bca052d..4515b22eb5 100644 --- a/src/main/java/net/openhft/chronicle/core/internal/CloseableUtils.java +++ b/src/main/java/net/openhft/chronicle/core/internal/CloseableUtils.java @@ -28,7 +28,7 @@ public final class CloseableUtils { * NOTE: This assumes the collection will not be replaced concurrently, and a particular lifecycle is used. * It is set and reset between tests in a single threaded manner. The set itself could be changed concurrently. */ - private static final AtomicReference> CLOSEABLES = new AtomicReference<>(); + private static final AtomicReference> CLOSEABLES = new AtomicReference<>(); private CloseableUtils() { } @@ -39,8 +39,8 @@ private CloseableUtils() { * * @param closeable The closeable resource to add. */ - public static void add(Closeable closeable) { - final Set set = CLOSEABLES.get(); + public static void add(ManagedCloseable closeable) { + final Set set = CLOSEABLES.get(); if (set != null) set.add(closeable); } @@ -123,7 +123,7 @@ protected void finalize() throws Throwable { * @return true if all closeable resources are closed within the time limit, false otherwise. */ public static boolean waitForCloseablesToClose(long millis) { - final Set traceSet = CLOSEABLES.get(); + final Set traceSet = CLOSEABLES.get(); if (traceSet == null) { return true; } @@ -172,7 +172,7 @@ public static boolean waitForCloseablesToClose(long millis) { * If any resources are found to be open, an AssertionError is thrown. */ public static void assertCloseablesClosed() { - final Set traceSet = CLOSEABLES.get(); + final Set traceSet = CLOSEABLES.get(); if (traceSet == null) { Jvm.warn().on(AbstractCloseable.class, "closable tracing disabled"); return; @@ -185,7 +185,7 @@ public static void assertCloseablesClosed() { AssertionError openFiles = new AssertionError("Closeables still open"); synchronized (traceSet) { - Set traceSet2 = Collections.newSetFromMap(new IdentityHashMap<>()); + Set traceSet2 = Collections.newSetFromMap(new IdentityHashMap<>()); if (waitForTraceSet(traceSet, traceSet2)) return; @@ -197,7 +197,7 @@ public static void assertCloseablesClosed() { } } - private static boolean waitForTraceSet(Set traceSet, Set traceSet2) { + private static boolean waitForTraceSet(Set traceSet, Set traceSet2) { traceSet.removeIf(o -> o == null || o.isClosing()); Set nested = Collections.newSetFromMap(new IdentityHashMap<>()); for (Closeable key : traceSet) { @@ -215,7 +215,7 @@ private static boolean waitForTraceSet(Set traceSet, Set t return false; } - private static void captureTheUnclosed(AssertionError openFiles, Set traceSet2) { + private static void captureTheUnclosed(AssertionError openFiles, Set traceSet2) { for (Closeable key : traceSet2) { Throwable t = null; try { @@ -267,8 +267,8 @@ private static void getCloseableFields(Class keyClass, Set fields) { /** * @param closeable to remove monitoring of */ - public static void unmonitor(Closeable closeable) { - final Set set = CLOSEABLES.get(); + public static void unmonitor(ManagedCloseable closeable) { + final Set set = CLOSEABLES.get(); if (set != null) set.remove(closeable); } 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 a30d6c1d49..d2d55dec94 100644 --- a/src/main/java/net/openhft/chronicle/core/io/AbstractCloseable.java +++ b/src/main/java/net/openhft/chronicle/core/io/AbstractCloseable.java @@ -54,7 +54,7 @@ *

    * Subclasses can also control the behavior of thread safety checks and background closing through provided methods. */ -public abstract class AbstractCloseable implements ReferenceOwner, ManagedCloseable, SingleThreadedChecked { +public abstract class AbstractCloseable implements ReferenceOwner, ManagedCloseable, SingleThreadedChecked, Monitorable { /** * Flag indicating whether discard warning is disabled. @@ -158,8 +158,9 @@ public static void assertCloseablesClosed() { * * @param closeable the closeable resource to unmonitor. */ + @Deprecated(/* to be removed in x.27, use Monitorable.unmonitor */) public static void unmonitor(Closeable closeable) { - CloseableUtils.unmonitor(closeable); + Monitorable.unmonitor(closeable); } /** @@ -453,6 +454,11 @@ public void singleThreadedCheckDisabled(boolean singleThreadedCheckDisabled) { } } + @Override + public void unmonitor() { + CloseableUtils.unmonitor(this); + } + /** * 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. 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 4f9d3e8272..5e36fa1ae5 100644 --- a/src/main/java/net/openhft/chronicle/core/io/AbstractCloseableReferenceCounted.java +++ b/src/main/java/net/openhft/chronicle/core/io/AbstractCloseableReferenceCounted.java @@ -21,6 +21,7 @@ import net.openhft.chronicle.core.Jvm; import net.openhft.chronicle.core.StackTrace; import net.openhft.chronicle.core.internal.CloseableUtils; +import net.openhft.chronicle.core.internal.ReferenceCountedUtils; /** * Represents a closeable resource with reference counting capabilities. @@ -210,4 +211,10 @@ protected void throwExceptionIfClosedInSetter() throws ClosedIllegalStateExcepti public boolean isClosed() { return refCount() <= 0 || closed; } + + @Override + public void unmonitor() { + CloseableUtils.unmonitor(this); + ReferenceCountedUtils.unmonitor(this); + } } 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 15d7fc88bb..897c8180b0 100644 --- a/src/main/java/net/openhft/chronicle/core/io/AbstractReferenceCounted.java +++ b/src/main/java/net/openhft/chronicle/core/io/AbstractReferenceCounted.java @@ -34,7 +34,7 @@ * reference counting mechanisms in resources, such as managing the number of * references and releasing resources when they are no longer needed. */ -public abstract class AbstractReferenceCounted implements ReferenceCountedTracer, ReferenceOwner, SingleThreadedChecked { +public abstract class AbstractReferenceCounted implements ReferenceCountedTracer, ReferenceOwner, SingleThreadedChecked, Monitorable { // Constants 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); @@ -334,4 +334,9 @@ public String toString() { public void referenceCountedUnmonitored(boolean unmonitored) { referenceCounted.unmonitored(unmonitored); } + + @Override + public void unmonitor() { + AbstractReferenceCounted.unmonitor(this); + } } 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 ad4c81b944..17159d0d02 100644 --- a/src/main/java/net/openhft/chronicle/core/io/IOTools.java +++ b/src/main/java/net/openhft/chronicle/core/io/IOTools.java @@ -27,8 +27,6 @@ import sun.nio.ch.IOStatus; import java.io.*; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; import java.net.InetSocketAddress; import java.net.MalformedURLException; import java.net.Socket; @@ -459,44 +457,7 @@ public static Path createTempDirectory(String s) { * @param t The object to stop monitoring */ public static void unmonitor(final Object t) { - unmonitor(t, 4); - } - - private static void unmonitor(final Object t, int depth) { - if (t == null) - return; - if (t instanceof Serializable || t instanceof MonitorReferenceCounted) // old school. - return; - if (t instanceof Closeable) - AbstractCloseable.unmonitor((Closeable) t); - if (t instanceof ReferenceCounted) - AbstractReferenceCounted.unmonitor((ReferenceCounted) t); - if (depth > 0) - unmonitor(t.getClass(), t, depth - 1); - } - - private static void unmonitor(Class aClass, Object t, int depth) { - if (aClass == null || aClass == Object.class) - return; - unmonitor(aClass.getSuperclass(), t, depth); - for (Field field : aClass.getDeclaredFields()) { - if (field.getType().isPrimitive() || Modifier.isStatic(field.getModifiers())) - continue; - try { - field.setAccessible(true); - } catch (Exception e) { - if (!Jvm.isJava9Plus()) - Jvm.warn().on(IOTools.class, e); - continue; - } - try { - Object o = field.get(t); - if (o != null) - unmonitor(o, depth); - } catch (IllegalAccessException | IllegalArgumentException e) { - Jvm.warn().on(IOTools.class, e); - } - } + Monitorable.unmonitor(t); } /** diff --git a/src/main/java/net/openhft/chronicle/core/io/Monitorable.java b/src/main/java/net/openhft/chronicle/core/io/Monitorable.java new file mode 100644 index 0000000000..5e37972125 --- /dev/null +++ b/src/main/java/net/openhft/chronicle/core/io/Monitorable.java @@ -0,0 +1,47 @@ +/* + * Copyright 2016-2022 chronicle.software + * + * https://chronicle.software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.openhft.chronicle.core.io; + +/** + * Interface for objects that can be monitored and unmonitored. + *

    + * This is useful for managing resources that need to be tracked and potentially cleaned up + * when they are no longer needed. + */ +public interface Monitorable { + + /** + * Stops monitoring the resource. + *

    + * Implementations of this method should ensure that the resource and any resources it uses + * are no longer being tracked for any purpose such as cleanup, resource management, or debugging. + * This is particularly important for resources that are explicitly managed to avoid leaks. + */ + void unmonitor(); + + /** + * Stops the monitoring of the specified object. + * + * @param t The object to stop monitoring + */ + static void unmonitor(final Object t) { + if (t instanceof Monitorable) + ((Monitorable) t).unmonitor(); + } +} diff --git a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java index f54094a093..c8f08b64dc 100644 --- a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java +++ b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java @@ -1,7 +1,7 @@ package net.openhft.chronicle.core.internal; import net.openhft.chronicle.core.Jvm; -import net.openhft.chronicle.core.io.Closeable; +import net.openhft.chronicle.core.io.*; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -19,11 +19,9 @@ import static org.mockito.Mockito.*; public class CloseableUtilsTest { - private Closeable mockCloseable; - private Collection mockCloseables; - private ServerSocketChannel mockServerSocketChannel; + private ManagedCloseable mockCloseable; + private AbstractCloseable anonCloseable; private AutoCloseable mockAutoCloseable; - private Reference mockReference; private HttpURLConnection mockHttpURLConnection; @Before @@ -34,18 +32,22 @@ public void mockitoNotSupportedOnJava21() { @Before public void setUp() { mockitoNotSupportedOnJava21(); - mockCloseable = mock(Closeable.class); + mockCloseable = mock(ManagedCloseable.class); + anonCloseable = new AbstractCloseable() { + @Override + protected void performClose() { + + } + }; CloseableUtils.enableCloseableTracing(); - mockCloseables = uncheckedCast(mock(Collection.class)); - mockServerSocketChannel = mock(ServerSocketChannel.class); mockAutoCloseable = mock(AutoCloseable.class); - mockReference = mock(Reference.class); mockHttpURLConnection = mock(HttpURLConnection.class); } @After public void tearDown() { CloseableUtils.disableCloseableTracing(); + anonCloseable.close(); } @Test @@ -119,6 +121,16 @@ public void testUnmonitor() { assertFalse(closeablesRef.get().contains(mockCloseable)); } + @Test + public void testIOToolsUnmonitor() { + IOTools.unmonitor(null); + IOTools.unmonitor("hello"); + CloseableUtils.add(anonCloseable); + IOTools.unmonitor(anonCloseable); + AtomicReference> closeablesRef = getCloseablesRef(); + assertFalse(closeablesRef.get().contains(mockCloseable)); + } + @Test public void testCloseQuietlyArray() { Object[] array = {mock(Closeable.class), mock(Closeable.class)}; From a6cceaa6878672231966af14a9bdc2fa6531bb6b Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 20 May 2024 13:47:19 +0100 Subject: [PATCH 33/43] Recover from java21 failure (#658) * Recover from failure on Java21 as mockito isn't supported. * Recover from failure on Java21 as mockito isn't supported. --- .../chronicle/core/internal/CloseableUtilsTest.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java index c8f08b64dc..7a6f49219d 100644 --- a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java +++ b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java @@ -6,14 +6,10 @@ import org.junit.Before; import org.junit.Test; +import java.net.HttpURLConnection; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; -import java.lang.ref.Reference; -import java.net.HttpURLConnection; -import java.nio.channels.ServerSocketChannel; -import java.util.Collection; -import static net.openhft.chronicle.core.Jvm.uncheckedCast; import static org.junit.Assert.*; import static org.junit.Assume.assumeTrue; import static org.mockito.Mockito.*; @@ -31,14 +27,14 @@ public void mockitoNotSupportedOnJava21() { @Before public void setUp() { - mockitoNotSupportedOnJava21(); - mockCloseable = mock(ManagedCloseable.class); anonCloseable = new AbstractCloseable() { @Override protected void performClose() { } }; + mockitoNotSupportedOnJava21(); + mockCloseable = mock(ManagedCloseable.class); CloseableUtils.enableCloseableTracing(); mockAutoCloseable = mock(AutoCloseable.class); mockHttpURLConnection = mock(HttpURLConnection.class); @@ -47,7 +43,7 @@ protected void performClose() { @After public void tearDown() { CloseableUtils.disableCloseableTracing(); - anonCloseable.close(); + Closeable.closeQuietly(anonCloseable); } @Test From 633919b11dec61331fc2d042b159615d054112d0 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 3 Apr 2024 09:49:32 +0100 Subject: [PATCH 34/43] review with lint:all (#641) --- .../openhft/chronicle/core/threads/CleaningThreadLocal.java | 2 ++ .../java/net/openhft/chronicle/core/util/ObjectUtils.java | 5 ++--- .../openhft/chronicle/core/internal/CloseableUtilsTest.java | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java b/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java index 58026d5048..e2994248a0 100644 --- a/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java +++ b/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java @@ -27,6 +27,8 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; + import static net.openhft.chronicle.core.Jvm.uncheckedCast; /** 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 1d5de235bc..225f6f6303 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java +++ b/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java @@ -36,6 +36,7 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; import static net.openhft.chronicle.core.internal.util.MapUtil.entry; import static net.openhft.chronicle.core.internal.util.MapUtil.ofUnmodifiable; import static net.openhft.chronicle.core.pool.ClassAliasPool.CLASS_ALIASES; @@ -397,9 +398,7 @@ public static > E getSingletonForEnum(Class eClass) { * @throws IllegalArgumentException If an illegal argument is provided. */ static E convertTo0(Class eClass, @Nullable Object o) throws NumberFormatException { - @SuppressWarnings("unchecked") - Class eClass0 = (Class) primToWrapper(eClass); - eClass = eClass0; + eClass = uncheckedCast(primToWrapper(eClass)); if (eClass.isInstance(o) || o == null) return (E) o; if (eClass == Void.class) return null; if (eClass == String.class) return (E) o.toString(); diff --git a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java index 7a6f49219d..37346cf5fe 100644 --- a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java +++ b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java @@ -10,6 +10,7 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicReference; +import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; import static org.junit.Assert.*; import static org.junit.Assume.assumeTrue; import static org.mockito.Mockito.*; From 768a692e6e949eb851f84b0abe79285957fe935d Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 3 Apr 2024 11:25:10 +0100 Subject: [PATCH 35/43] Tidy up compiler setting and some warnings --- .../java/net/openhft/chronicle/core/Jvm.java | 18 ++++++++++++++++++ .../chronicle/core/util/ObjectUtils.java | 2 +- .../core/internal/CloseableUtilsTest.java | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index fd0624ef01..03bcf7f7d0 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -1603,6 +1603,24 @@ public static long currentThreadId() { return Thread.currentThread().getId(); } + /** + * Performs an unchecked cast of an object to the target type {@code T}. This method + * bypasses generic type checks, allowing for casting without explicit type checking. + *

    + * Note: Use with caution as improper use can lead to {@link ClassCastException} at runtime + * if the object is not of type {@code T}. + * + * @param the target type to cast to + * @param o the object to be cast + * @return the casted object of type {@code T} + * @throws ClassCastException if the object cannot be casted to the target type {@code T} + * (this is a runtime possibility due to type erasure) + */ + @SuppressWarnings("unchecked") + public static T uncheckedCast(Object o) { + return (T) o; + } + public interface SignalHandler { /** * Handle a Signal 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 225f6f6303..b0f0532d73 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java +++ b/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java @@ -36,7 +36,7 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; -import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; +import static net.openhft.chronicle.core.Jvm.uncheckedCast; import static net.openhft.chronicle.core.internal.util.MapUtil.entry; import static net.openhft.chronicle.core.internal.util.MapUtil.ofUnmodifiable; import static net.openhft.chronicle.core.pool.ClassAliasPool.CLASS_ALIASES; diff --git a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java index 37346cf5fe..5afb46172f 100644 --- a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java +++ b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java @@ -10,7 +10,7 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicReference; -import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; +import static net.openhft.chronicle.core.Jvm.uncheckedCast; import static org.junit.Assert.*; import static org.junit.Assume.assumeTrue; import static org.mockito.Mockito.*; From bd456fcaed50f8149fb51965ccc25ec5c119a4d6 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 20 May 2024 14:34:28 +0100 Subject: [PATCH 36/43] Merge with develop --- .../net/openhft/chronicle/core/internal/CloseableUtilsTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java index 5afb46172f..7a6f49219d 100644 --- a/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java +++ b/src/test/java/net/openhft/chronicle/core/internal/CloseableUtilsTest.java @@ -10,7 +10,6 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicReference; -import static net.openhft.chronicle.core.Jvm.uncheckedCast; import static org.junit.Assert.*; import static org.junit.Assume.assumeTrue; import static org.mockito.Mockito.*; From 0926def0c85c724ed5f5b25f7ef4a1ae8763e8c1 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 20 May 2024 17:02:25 +0100 Subject: [PATCH 37/43] Merge with develop --- .../java/net/openhft/chronicle/core/Jvm.java | 18 ------------------ .../core/threads/CleaningThreadLocal.java | 2 -- .../chronicle/core/util/ObjectUtils.java | 5 +++-- 3 files changed, 3 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index 03bcf7f7d0..fd0624ef01 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -1603,24 +1603,6 @@ public static long currentThreadId() { return Thread.currentThread().getId(); } - /** - * Performs an unchecked cast of an object to the target type {@code T}. This method - * bypasses generic type checks, allowing for casting without explicit type checking. - *

    - * Note: Use with caution as improper use can lead to {@link ClassCastException} at runtime - * if the object is not of type {@code T}. - * - * @param the target type to cast to - * @param o the object to be cast - * @return the casted object of type {@code T} - * @throws ClassCastException if the object cannot be casted to the target type {@code T} - * (this is a runtime possibility due to type erasure) - */ - @SuppressWarnings("unchecked") - public static T uncheckedCast(Object o) { - return (T) o; - } - public interface SignalHandler { /** * Handle a Signal diff --git a/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java b/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java index e2994248a0..58026d5048 100644 --- a/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java +++ b/src/main/java/net/openhft/chronicle/core/threads/CleaningThreadLocal.java @@ -27,8 +27,6 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; -import static net.openhft.chronicle.core.internal.Bootstrap.uncheckedCast; - import static net.openhft.chronicle.core.Jvm.uncheckedCast; /** 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 b0f0532d73..1d5de235bc 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java +++ b/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java @@ -36,7 +36,6 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; -import static net.openhft.chronicle.core.Jvm.uncheckedCast; import static net.openhft.chronicle.core.internal.util.MapUtil.entry; import static net.openhft.chronicle.core.internal.util.MapUtil.ofUnmodifiable; import static net.openhft.chronicle.core.pool.ClassAliasPool.CLASS_ALIASES; @@ -398,7 +397,9 @@ public static > E getSingletonForEnum(Class eClass) { * @throws IllegalArgumentException If an illegal argument is provided. */ static E convertTo0(Class eClass, @Nullable Object o) throws NumberFormatException { - eClass = uncheckedCast(primToWrapper(eClass)); + @SuppressWarnings("unchecked") + Class eClass0 = (Class) primToWrapper(eClass); + eClass = eClass0; if (eClass.isInstance(o) || o == null) return (E) o; if (eClass == Void.class) return null; if (eClass == String.class) return (E) o.toString(); From d1e9cb1fa04b7174c759fadf5716fede1cccbcd4 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 3 Apr 2024 11:25:10 +0100 Subject: [PATCH 38/43] Tidy up compiler setting and some warnings --- .../java/net/openhft/chronicle/core/Jvm.java | 18 ++++++++++++++++++ .../chronicle/core/util/ObjectUtils.java | 1 + 2 files changed, 19 insertions(+) diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index fd0624ef01..03bcf7f7d0 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -1603,6 +1603,24 @@ public static long currentThreadId() { return Thread.currentThread().getId(); } + /** + * Performs an unchecked cast of an object to the target type {@code T}. This method + * bypasses generic type checks, allowing for casting without explicit type checking. + *

    + * Note: Use with caution as improper use can lead to {@link ClassCastException} at runtime + * if the object is not of type {@code T}. + * + * @param the target type to cast to + * @param o the object to be cast + * @return the casted object of type {@code T} + * @throws ClassCastException if the object cannot be casted to the target type {@code T} + * (this is a runtime possibility due to type erasure) + */ + @SuppressWarnings("unchecked") + public static T uncheckedCast(Object o) { + return (T) o; + } + public interface SignalHandler { /** * Handle a Signal 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 1d5de235bc..ac309595a2 100644 --- a/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java +++ b/src/main/java/net/openhft/chronicle/core/util/ObjectUtils.java @@ -36,6 +36,7 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; +import static net.openhft.chronicle.core.Jvm.uncheckedCast; import static net.openhft.chronicle.core.internal.util.MapUtil.entry; import static net.openhft.chronicle.core.internal.util.MapUtil.ofUnmodifiable; import static net.openhft.chronicle.core.pool.ClassAliasPool.CLASS_ALIASES; From 69ccb4eba80c82654811236789ea1992ed8e03ff Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 20 May 2024 17:23:53 +0100 Subject: [PATCH 39/43] remove duplicate --- .../java/net/openhft/chronicle/core/Jvm.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/core/Jvm.java b/src/main/java/net/openhft/chronicle/core/Jvm.java index 03bcf7f7d0..fd0624ef01 100644 --- a/src/main/java/net/openhft/chronicle/core/Jvm.java +++ b/src/main/java/net/openhft/chronicle/core/Jvm.java @@ -1603,24 +1603,6 @@ public static long currentThreadId() { return Thread.currentThread().getId(); } - /** - * Performs an unchecked cast of an object to the target type {@code T}. This method - * bypasses generic type checks, allowing for casting without explicit type checking. - *

    - * Note: Use with caution as improper use can lead to {@link ClassCastException} at runtime - * if the object is not of type {@code T}. - * - * @param the target type to cast to - * @param o the object to be cast - * @return the casted object of type {@code T} - * @throws ClassCastException if the object cannot be casted to the target type {@code T} - * (this is a runtime possibility due to type erasure) - */ - @SuppressWarnings("unchecked") - public static T uncheckedCast(Object o) { - return (T) o; - } - public interface SignalHandler { /** * Handle a Signal From 9f35eb79008bbaf8c75db3617781a47eeb1bd62e Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Wed, 22 May 2024 19:16:41 +0100 Subject: [PATCH 40/43] parent poms -> x.26.0 --- assertions-disabled/pom.xml | 2 +- assertions-enabled/pom.xml | 2 +- benchmarks/pom.xml | 4 ++-- checked-exceptions/pom.xml | 2 +- pom.xml | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/assertions-disabled/pom.xml b/assertions-disabled/pom.xml index 76c40f5db6..d91bf3a2b8 100644 --- a/assertions-disabled/pom.xml +++ b/assertions-disabled/pom.xml @@ -25,7 +25,7 @@ net.openhft java-parent-pom - 1.26.0-SNAPSHOT + 1.26.0 diff --git a/assertions-enabled/pom.xml b/assertions-enabled/pom.xml index c3f7125d34..25cb1371e0 100644 --- a/assertions-enabled/pom.xml +++ b/assertions-enabled/pom.xml @@ -25,7 +25,7 @@ net.openhft java-parent-pom - 1.26.0-SNAPSHOT + 1.26.0 diff --git a/benchmarks/pom.xml b/benchmarks/pom.xml index 8c1b7d3374..325b80bf31 100644 --- a/benchmarks/pom.xml +++ b/benchmarks/pom.xml @@ -22,7 +22,7 @@ net.openhft java-parent-pom - 1.26.0-SNAPSHOT + 1.26.0 @@ -41,7 +41,7 @@ net.openhft third-party-bom - 3.26.0-SNAPSHOT + 3.26.0 pom import diff --git a/checked-exceptions/pom.xml b/checked-exceptions/pom.xml index 0e858c84b9..e6f2121a0e 100644 --- a/checked-exceptions/pom.xml +++ b/checked-exceptions/pom.xml @@ -23,7 +23,7 @@ net.openhft java-parent-pom - 1.26.0-SNAPSHOT + 1.26.0 diff --git a/pom.xml b/pom.xml index 682d65f0af..1e3dcf1c7d 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ net.openhft java-parent-pom - 1.26.0-SNAPSHOT + 1.26.0 chronicle-core @@ -48,7 +48,7 @@ net.openhft third-party-bom - 3.26.0-SNAPSHOT + 3.26.0 pom import From 7f607b966dbd4706702d48871056702b1fcb1978 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 23 May 2024 16:00:13 +0100 Subject: [PATCH 41/43] Where marked for removal, also mark for deprecation --- .../net/openhft/chronicle/core/internal/CloseableUtils.java | 4 ++-- .../java/net/openhft/chronicle/core/io/AbstractCloseable.java | 2 +- .../openhft/chronicle/core/io/CleaningRandomAccessFile.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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 4515b22eb5..33ff7a9b98 100644 --- a/src/main/java/net/openhft/chronicle/core/internal/CloseableUtils.java +++ b/src/main/java/net/openhft/chronicle/core/internal/CloseableUtils.java @@ -78,7 +78,7 @@ public static void disableCloseableTracing() { * * @throws AssertionError If the finalizer does not complete within the specified timeout. */ - @SuppressWarnings("removal") + @SuppressWarnings({"deprecation", "removal"}) public static void gcAndWaitForCloseablesToClose() { CleaningThread.performCleanup(Thread.currentThread()); @@ -87,7 +87,7 @@ public static void gcAndWaitForCloseablesToClose() { // Anonymous inner class overriding the finalize() method to track finalization. new Object() { - @SuppressWarnings("removal") + @SuppressWarnings({"deprecation", "removal"}) @Override protected void finalize() throws Throwable { super.finalize(); 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 d2d55dec94..0cb3bcfee4 100644 --- a/src/main/java/net/openhft/chronicle/core/io/AbstractCloseable.java +++ b/src/main/java/net/openhft/chronicle/core/io/AbstractCloseable.java @@ -471,7 +471,7 @@ class Finalizer { * * @throws Throwable if an error occurs during finalization. */ - @SuppressWarnings("removal") + @SuppressWarnings({"deprecation", "removal"}) @Override protected void finalize() throws Throwable { warnAndCloseIfNotClosed(); diff --git a/src/main/java/net/openhft/chronicle/core/io/CleaningRandomAccessFile.java b/src/main/java/net/openhft/chronicle/core/io/CleaningRandomAccessFile.java index 8d2429172e..a360706020 100644 --- a/src/main/java/net/openhft/chronicle/core/io/CleaningRandomAccessFile.java +++ b/src/main/java/net/openhft/chronicle/core/io/CleaningRandomAccessFile.java @@ -37,7 +37,7 @@ public CleaningRandomAccessFile(File file, String mode) throws FileNotFoundExcep super(file, mode); } - @SuppressWarnings("removal") + @SuppressWarnings({"deprecation", "removal"}) @Override protected void finalize() throws Throwable { super.finalize(); From 442b218e2d065f874988ac1ce4d1a34a7a1ea422 Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Thu, 23 May 2024 16:29:15 +0100 Subject: [PATCH 42/43] Allow for aarch64 CPUs --- .../java/net/openhft/chronicle/core/internal/CpuClassTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/net/openhft/chronicle/core/internal/CpuClassTest.java b/src/test/java/net/openhft/chronicle/core/internal/CpuClassTest.java index 0c489ea794..4a33149937 100644 --- a/src/test/java/net/openhft/chronicle/core/internal/CpuClassTest.java +++ b/src/test/java/net/openhft/chronicle/core/internal/CpuClassTest.java @@ -15,7 +15,8 @@ public void getCpuModel() { assertTrue(cpuClass, cpuClass.startsWith("Apple M")); } else if (Jvm.isArm()) { - assertTrue(cpuClass, cpuClass.startsWith("ARMv")); + assertTrue(cpuClass, cpuClass.startsWith("ARMv") + || cpuClass.startsWith("aarch64")); } else { assertTrue(cpuClass, From 2c3a43d2dc3b300c4b595bc074beef5163629d1f Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Tue, 28 May 2024 17:40:55 +0100 Subject: [PATCH 43/43] This class was left here for backward compatibility. --- src/main/java/net/openhft/chronicle/core/Mocker.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/net/openhft/chronicle/core/Mocker.java b/src/main/java/net/openhft/chronicle/core/Mocker.java index f82a31164c..e6d45e1527 100644 --- a/src/main/java/net/openhft/chronicle/core/Mocker.java +++ b/src/main/java/net/openhft/chronicle/core/Mocker.java @@ -26,6 +26,7 @@ /** * The Mocker class provides utility methods for creating mocked instances of interfaces. + * This class was left here for backward compatibility. * @see net.openhft.chronicle.core.util.Mocker */ public final class Mocker {