With a static initializer that could be achieved.
But we need to import that static member in relevant place to make sure the
class is loaded (and initialised)

package com.mylibrary.internal;

import java.nio.ByteOrder;

// This class is not intended for public use, so we place it in an
'internal' package.
public final class LibraryInitializer {

    // A static field that can be referenced.
    public static final boolean IS_INITIALIZED;

    static {
        System.out.println("Library initializer is running...");
        if (ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN) {
            throw new ExceptionInInitializerError("Library is incompatible
with non Little-Endian systems.");
        }
        IS_INITIALIZED = true; // Set to true after successful
initialization
        System.out.println("Library initialization successful.");
    }

    // Private constructor to prevent instantiation.
    private LibraryInitializer() {}
}


On Sat, Aug 2, 2025, 7:31 PM leerho (via GitHub) <[email protected]> wrote:

>
> leerho commented on code in PR #675:
> URL:
> https://github.com/apache/datasketches-java/pull/675#discussion_r2249321757
>
>
> ##########
> src/main/java/org/apache/datasketches/hash/MurmurHash3.java:
> ##########
> @@ -306,42 +308,34 @@ public static long[] hash(final byte[] key, final
> int offsetBytes, final int len
>
>    //--Hash of
> ByteBuffer---------------------------------------------------
>    /**
> -   * Hash the remaining bytes of the given ByteBuffer starting at
> position().
> +   * Hash the remaining bytes of the given ByteBuffer starting at
> position() ending at limit (exclusive).
>     *
> -   * @param buf The input ByteBuffer. It must be non-null and non-empty.
> +   * @param buf The input ByteBuffer. It must be non-null and non-empty
> and using Little Endian.
>
> Review Comment:
>    Hmm. Let me check all the places in /main/ where BB is an import.
>
>    I wonder if there is a way to check endianness when the library (jar)
> is loaded into memory. We could check and issue at least a warning.
>
>
>
> --
> This is an automated message from the Apache Git Service.
> To respond to the message, please log on to GitHub and use the
> URL above to go to the specific comment.
>
> To unsubscribe, e-mail: [email protected]
>
> For queries about this service, please contact Infrastructure at:
> [email protected]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to