Skip to content

Comments

Fix JDK 26 compatibility in CharsetsTest for ArrayEncoder API change#6902

Merged
JasonFengJ9 merged 1 commit intoadoptium:masterfrom
rishabh-ibm:CharsetsTests_JDK26
Feb 13, 2026
Merged

Fix JDK 26 compatibility in CharsetsTest for ArrayEncoder API change#6902
JasonFengJ9 merged 1 commit intoadoptium:masterfrom
rishabh-ibm:CharsetsTests_JDK26

Conversation

@rishabh-ibm
Copy link
Contributor

This PR updates CharsetsTest to support both JDK 26+ (with new encodeFromUTF16 API) and earlier JDK versions (with old encode API) using version-aware method selection.

Problem

JDK 26 removed the unused sun.nio.cs.ArrayEncoder::encode method as part of cleanup, causing CharsetsTest to fail.

API Change in JDK 26

JDK-8363925: Remove unused sun.nio.cs.ArrayEncoder::encode
🔗 https://bugs.openjdk.org/browse/JDK-8363925

Aspect JDK < 26 (Old API) JDK 26+ (New API)
Method encode() encodeFromUTF16()
Input Type char[] array UTF-16 LE byte[] array
Signature encode(char[] src, int srcOff, int srcLen, byte[] dst) encodeFromUTF16(byte[] src, int srcOff, int srcLen, byte[] dst, int dstOff)
Parameters 4 parameters 5 parameters (added dstOff)

Why the Change?

The old encode(char[]) method was unused in the JDK codebase and was removed as part of code cleanup. The new encodeFromUTF16(byte[]) method provides better performance and more control over encoding by working directly with UTF-16 encoded bytes.

Solution

1. Created JavaVersion.java

Version detection utility to determine JDK feature version at runtime.

public static long getFeature() {
    return feature;  // Returns 21, 26, etc.
}

Adapt CharsetsTest to support both JDK 26+ (new encodeFromUTF16 API) and
earlier JDK versions (old encode API) using version-aware method selection.

JDK 26 removed the unused sun.nio.cs.ArrayEncoder::encode method and
replaced it with encodeFromUTF16 which accepts UTF-16 encoded byte arrays
instead of char arrays (JDK-8363925).

Changes:
- Add JavaVersion utility for JDK version detection
- Update static initialization to load appropriate method based on JDK version
- Modify encode_data to use encodeFromUTF16 for JDK 26+ and encode for earlier versions
- Convert char[] to UTF-16 LE byte array when using new API

Files Modified:
- functional/MBCS_Tests/charsets/src/CharsetsTest.java

Files Created:
- functional/MBCS_Tests/charsets/src/JavaVersion.java

Fixes test failures caused by JDK 26's ArrayEncoder API change (JDK-8363925).

Reference: https://bugs.openjdk.org/browse/JDK-8363925

Signed-off-by: Rishabh Thakur <rishabh@ibm.com>
@rishabh-ibm
Copy link
Contributor Author

@JasonFengJ9 @pshipton ,

This fixes Charsets test case for JDK26. We have added JavaVersion class to detect which encode method to use. Detailed information is present in the PR.

@psawant19
Copy link
Contributor

Grinder was triggered and test passed: https://hyc-runtimes-jenkins.swg-devops.com/job/Grinder/58338/

@pshipton pshipton requested a review from JasonFengJ9 February 13, 2026 16:17
@pshipton
Copy link
Member

jdk21 grinder also passed https://hyc-runtimes-jenkins.swg-devops.com/job/Grinder/58344

@JasonFengJ9 JasonFengJ9 merged commit 0d0564c into adoptium:master Feb 13, 2026
2 checks passed
@pshipton
Copy link
Member

Pls port this to the v1.0.12-release branch.

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.

4 participants