Skip to content

Commit

Permalink
HDDS-11392. ChecksumByteBufferImpl's static initializer fails with ja…
Browse files Browse the repository at this point in the history
…va 17+ (apache#7135)
  • Loading branch information
fapifta authored Sep 1, 2024
1 parent b5e1a8b commit 814f78f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,24 @@ public final class JavaUtils {
* is equal or greater than the parameter.
*
* @param version 8, 9, 10 etc.
* @return comparison with system property, always true for 8
* @return comparison with system property, always true for any int up to 8
*/
public static boolean isJavaVersionAtLeast(int version) {
return JAVA_SPEC_VER >= version;
}

/**
* Query to see if major version of Java specification of the system
* is equal or less than the parameter.
*
* @param version 8, 9, 10 etc.
* @return comparison with system property
*/
public static boolean isJavaVersionAtMost(int version) {
return JAVA_SPEC_VER <= version;
}


/**
* Private constructor.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ public class ChecksumByteBufferImpl implements ChecksumByteBuffer {

static {
Field f = null;
try {
f = ByteBuffer.class
.getDeclaredField("isReadOnly");
f.setAccessible(true);
} catch (NoSuchFieldException e) {
LOG.error("No isReadOnly field in ByteBuffer", e);
if (JavaUtils.isJavaVersionAtMost(8)) {
try {
f = ByteBuffer.class
.getDeclaredField("isReadOnly");
f.setAccessible(true);
} catch (NoSuchFieldException e) {
LOG.error("No isReadOnly field in ByteBuffer", e);
}
}
IS_READY_ONLY_FIELD = f;

Expand Down

0 comments on commit 814f78f

Please sign in to comment.