From a3e9548e4656fdcc824bea00e4a64479cf854e36 Mon Sep 17 00:00:00 2001 From: Bernard Ladenthin Date: Wed, 30 Sep 2026 23:32:21 +0200 Subject: [PATCH] fix: declare MAX_ARRAY_LENGTH before instance fields (SpotBugs IMC) fb-contrib IMC_IMMATURE_CLASS_WRONG_FIELD_ORDER failed the spotbugs-check (verify phase) after #163 placed the static constant between instance fields. Moved it next to the other static field; no behavior change. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_018mLGtytvtJU7aNshBpnrB5 --- .../ladenthin/streambuffer/StreamBuffer.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/ladenthin/streambuffer/StreamBuffer.java b/src/main/java/net/ladenthin/streambuffer/StreamBuffer.java index 15bab5af..54ebe7e1 100644 --- a/src/main/java/net/ladenthin/streambuffer/StreamBuffer.java +++ b/src/main/java/net/ladenthin/streambuffer/StreamBuffer.java @@ -28,6 +28,15 @@ public class StreamBuffer implements Closeable { static final String EXCEPTION_MESSAGE_VALIDATE_OFFSET_AND_LENGTH_TO_WRITE_INDEX_OUT_OF_BOUNDS_EXCEPTION = "Invalid offset or length given to validateOffsetAndLengthToWrite."; + /** + * Largest {@code byte[]} length this class allocates: {@code Integer.MAX_VALUE - 8}. + * Same value as {@code jdk.internal.util.ArraysSupport.SOFT_MAX_ARRAY_LENGTH}, mirrored + * because that class is JDK-internal (not exported, absent on Java 8). + * Reason: VMs reserve array header words; HotSpot rejects {@code Integer.MAX_VALUE} and + * {@code Integer.MAX_VALUE - 1} with "Requested array size exceeds VM limit", on any heap size. + */ + static final int MAX_ARRAY_LENGTH = Integer.MAX_VALUE - 8; + /** * An object to get an unique access to the {@link #buffer}. It is needed to * get an exclusive access for read and write operations. @@ -132,15 +141,6 @@ public class StreamBuffer implements Closeable { */ private final AtomicLong totalBytesRead = new AtomicLong(); - /** - * Largest {@code byte[]} length this class allocates: {@code Integer.MAX_VALUE - 8}. - * Same value as {@code jdk.internal.util.ArraysSupport.SOFT_MAX_ARRAY_LENGTH}, mirrored - * because that class is JDK-internal (not exported, absent on Java 8). - * Reason: VMs reserve array header words; HotSpot rejects {@code Integer.MAX_VALUE} and - * {@code Integer.MAX_VALUE - 1} with "Requested array size exceeds VM limit", on any heap size. - */ - static final int MAX_ARRAY_LENGTH = Integer.MAX_VALUE - 8; - /** * Maximum size of a single byte array during consolidation. Default {@link #MAX_ARRAY_LENGTH}. */