Skip to content

Commit

Permalink
apacheGH-35053: [Java] Fix MemoryUtil to support Java 21
Browse files Browse the repository at this point in the history
  • Loading branch information
dongjoon-hyun committed Jun 29, 2023
1 parent c35a35d commit 252f068
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public class MemoryUtil {
*/
public static final boolean LITTLE_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN;

// Java 1.8, 9, 11, 17, 21 becomes 1, 9, 11, 17, and 21.
private static final int majorVersion =
Integer.parseInt(System.getProperty("java.specification.version").split("\\D+")[0]);

static {
try {
// try to get the unsafe object
Expand Down Expand Up @@ -94,8 +98,9 @@ public Object run() {
@Override
public Object run() {
try {
final Constructor<?> constructor =
final Constructor<?> constructor = (majorVersion < 21) ?
direct.getClass().getDeclaredConstructor(long.class, int.class);
direct.getClass().getDeclaredConstructor(long.class, long.class);
constructor.setAccessible(true);
logger.debug("Constructor for direct buffer found and made accessible");
return constructor;
Expand Down

0 comments on commit 252f068

Please sign in to comment.