This is an automated email from the ASF dual-hosted git repository.
pifta pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 814f78f9ff HDDS-11392. ChecksumByteBufferImpl's static initializer
fails with java 17+ (#7135)
814f78f9ff is described below
commit 814f78f9ff3f7c1cbb369a01baed25745cfd0030
Author: Istvan Fajth <[email protected]>
AuthorDate: Sun Sep 1 22:57:25 2024 +0200
HDDS-11392. ChecksumByteBufferImpl's static initializer fails with java 17+
(#7135)
---
.../src/main/java/org/apache/hadoop/hdds/JavaUtils.java | 14 +++++++++++++-
.../apache/hadoop/ozone/common/ChecksumByteBufferImpl.java | 14 ++++++++------
2 files changed, 21 insertions(+), 7 deletions(-)
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/JavaUtils.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/JavaUtils.java
index 63c29ba7c9..804e655248 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/JavaUtils.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/JavaUtils.java
@@ -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.
*/
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/ChecksumByteBufferImpl.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/ChecksumByteBufferImpl.java
index 1d596bf700..a523597832 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/ChecksumByteBufferImpl.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/ChecksumByteBufferImpl.java
@@ -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;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]