Skip to content

Conversation

@pniedzielski
Copy link
Collaborator

@pniedzielski pniedzielski commented Dec 2, 2025

Working my way up to Java 25 incrementally. There's several issues to solve first.

Includes #65.

CI is failing because of the deprecated version of
`actions/upload-artifact`.  According to the documentation linked in
https://github.blog/changelog/2024-04-16-deprecation-notice-v3-of-the-artifact-actions/,
our usage of this action is safe to just bump the version number from
`v3` to `v4`.

Signed-off-by: Patrick M. Niedzielski <[email protected]>
@pniedzielski pniedzielski force-pushed the chore/java-versions branch 5 times, most recently from 1c28753 to 8cf77ca Compare December 2, 2025 23:22
Signed-off-by: Patrick M. Niedzielski <[email protected]>
As it stands, our SDK only supports three old LTS versions of Java.
Any user who wants to use the SDK on non-LTS versions, or on
reasonably new versions of Java, will be prevented.  However, what the
code really wants is to know whether we’re on a version of Java before
or after Java 9, with which we determine which CRC32 implementation to
use.

This patch *removes* explicit JDK versioning from `SystemUtil`, which
is a breaking change.

Signed-off-by: Patrick M. Niedzielski <[email protected]>
Signed-off-by: Patrick M. Niedzielski <[email protected]>
@pniedzielski pniedzielski force-pushed the chore/java-versions branch 2 times, most recently from 086f15a to 9be0beb Compare December 2, 2025 23:37
Since Java16, we get a number of warnings of the sort

    [WARNING] blazingmq-sdk-java/bmq-sdk/src/main/java/com/bloomberg/bmq/impl/infr/proto/BoolMessageProperty.java:[27,25] possible 'this' escape before subclass is fully initialized

These warnings are shown when a class that may serve as a superclass
calls an overridable method in its constructor.  If some other class
inherits from that superclass and overrides that method, the
overridden implementation will be called on an object that was not
fully initialized.

We can fix this in a few ways.  On one hand, we can avoid calling
methods in class constructors.  This works nicely in cases like
`ControlMessageChoice`, which directly forwards to an `init()` method
to null out its member variables.  Duplicating this code is not
terrible.  However, in more complicated cases, like `PutHeader` and
the like, the methods we call abstract bit manupulation that’s easy to
get wrong.  It’s best not to inline that code in the constructors.

On the other hand, we can prevent the methods we call from the class
constructor from being overriden.  In all cases we have this warning,
there is a strong case to be made that we don’t want to allow
inheritance.  The message classes need to follow the protocol schema
directly, and the protocol classes are also directly tied to the
binary protocol that the BlazingMQ broker uses.  We should not allow
users to inject their own behaviors into this parsing.

This patch fixes all “`this` escape” warnings that newer JDK versions
give by marking the classes they’re shown for as `final`.

Signed-off-by: Patrick M. Niedzielski <[email protected]>
Compiling on modern JDKs results in the following warning:

    blazingmq-sdk-java/bmq-sdk/src/main/java/com/bloomberg/bmq/impl/infr/proto/EventHeader.java:[255,31] implicit cast from int to byte in compound assignment is possibly lossy

This patch fixes this warning by making the cast explicit.

In Java all bitshift operations result in integral types like `int`
or `long`, never `byte`.  So, even though we guarantee that the result
of our bitshift operation must fit within eight bits, its type is
`int`.  To silence the warning, we make the cast explicit.

Signed-off-by: Patrick M. Niedzielski <[email protected]>
Compiling on modern JDKs results in the following warning:

    [WARNING] blazingmq-sdk-java/bmq-sdk/src/main/java/com/bloomberg/bmq/impl/infr/proto/MessagePropertiesImpl.java:[234,24] implicit cast from long to int in compound assignment is possibly lossy

This is fired on the line:

    // Add padding bytes
    totalLength += numPaddingBytes;

where `totalLength` is an `int` and `numPaddingBytes` is a `long`.
However, `numPaddingBytes` is initialized few lines above as

    // Read padding bytes
    final long numPaddingBytes = input.readByte();

Since `readByte()` returns a `byte`, there’s no reason for this
constant to be `long`.  This patch fixes the above warning by avoiding
the needless conversion to `long`.

Signed-off-by: Patrick M. Niedzielski <[email protected]>
    [WARNING] blazingmq-sdk-java/bmq-sdk/src/test/java/com/bloomberg/bmq/it/util/TestTools.java:[152,16] redundant cast to java.nio.ByteBuffer

Signed-off-by: Patrick M. Niedzielski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant