Skip to content

Fix init order of PlatformDependent0 fields - #15077

Merged
normanmaurer merged 1 commit into
netty:4.2from
Spasi:4.2
Apr 24, 2025
Merged

normanmaurer merged 1 commit into
netty:4.2from
Spasi:4.2

Conversation

@Spasi

@Spasi Spasi commented Apr 24, 2025

Copy link
Copy Markdown
Contributor

Motivation:

After #14975, EXPLICIT_NO_UNSAFE_CAUSE has a dependency to JAVA_VERSION, which is initialized after it. When explicitNoUnsafeCause0() tries to set io.netty.noUnsafe to true by default on Java 24, it fails, because javaVersion() always returns 0 at that point.

Also, isAndroid0() is called twice, once in javaVersion0() and once to initialize IS_ANDROID. This is not a bug or a performance issue, but it does have a visible side-effect when debug logging is enabled.

Modification:

The declaration of EXPLICIT_NO_UNSAFE_CAUSE is moved after JAVA_VERSION, ensuring javaVersion() returns the correct version when explicitNoUnsafeCause0() calls it.

IS_ANDROID is also moved before JAVA_VERSION, such that the isAndroid0() method is called only once.

Result:

Fixes #14942 correctly

Motivation:

After netty#14975, EXPLICIT_NO_UNSAFE_CAUSE has a dependency to JAVA_VERSION,
which is initialized after it. When explicitNoUnsafeCause0() tries to
set io.netty.noUnsafe to true by default on Java 24, it fails, because
javaVersion() always returns 0 at that point.

Also, isAndroid0() is called twice, once in javaVersion0() and once to
initialize IS_ANDROID. This is not a bug or a performance issue, but it
does have a visible side-effect when debug logging is enabled.

Modification:

The declaration of EXPLICIT_NO_UNSAFE_CAUSE is moved after JAVA_VERSION,
ensuring javaVersion() returns the correct version when
explicitNoUnsafeCause0() calls it.

IS_ANDROID is also moved before JAVA_VERSION, such that the isAndroid0()
method is called only once.

Result:

Fixes netty#14942 correctly
@normanmaurer normanmaurer added this to the 4.2.1.Final milestone Apr 24, 2025
@normanmaurer
normanmaurer merged commit 7611905 into netty:4.2 Apr 24, 2025
@normanmaurer

Copy link
Copy Markdown
Member

@Spasi thanks!

chrisvest pushed a commit to chrisvest/netty that referenced this pull request Apr 25, 2025
Motivation:

After netty#14975, `EXPLICIT_NO_UNSAFE_CAUSE` has a dependency to
`JAVA_VERSION`, which is initialized after it. When
`explicitNoUnsafeCause0()` tries to set `io.netty.noUnsafe` to true by
default on Java 24, it fails, because `javaVersion()` always returns 0
at that point.

Also, `isAndroid0()` is called twice, once in `javaVersion0()` and once
to initialize `IS_ANDROID`. This is not a bug or a performance issue,
but it does have a visible side-effect when debug logging is enabled.

Modification:

The declaration of `EXPLICIT_NO_UNSAFE_CAUSE` is moved after
`JAVA_VERSION`, ensuring `javaVersion()` returns the correct version
when `explicitNoUnsafeCause0()` calls it.

`IS_ANDROID` is also moved before `JAVA_VERSION`, such that the
`isAndroid0()` method is called only once.

Result:

Fixes netty#14942 correctly
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.

PlatformDependent0: A terminally deprecated method in sun.misc.Unsafe has been called

3 participants