File tree Expand file tree Collapse file tree
hadoop-hdds/common/src/main/java/org/apache/hadoop Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,12 +30,24 @@ public final class JavaUtils {
3030 * is equal or greater than the parameter.
3131 *
3232 * @param version 8, 9, 10 etc.
33- * @return comparison with system property, always true for 8
33+ * @return comparison with system property, always true for any int up to 8
3434 */
3535 public static boolean isJavaVersionAtLeast (int version ) {
3636 return JAVA_SPEC_VER >= version ;
3737 }
3838
39+ /**
40+ * Query to see if major version of Java specification of the system
41+ * is equal or less than the parameter.
42+ *
43+ * @param version 8, 9, 10 etc.
44+ * @return comparison with system property
45+ */
46+ public static boolean isJavaVersionAtMost (int version ) {
47+ return JAVA_SPEC_VER <= version ;
48+ }
49+
50+
3951 /**
4052 * Private constructor.
4153 */
Original file line number Diff line number Diff line change 1717 */
1818package org .apache .hadoop .ozone .common ;
1919
20+ import org .apache .hadoop .hdds .JavaUtils ;
2021import org .slf4j .Logger ;
2122import org .slf4j .LoggerFactory ;
2223
@@ -38,12 +39,14 @@ public class ChecksumByteBufferImpl implements ChecksumByteBuffer {
3839
3940 static {
4041 Field f = null ;
41- try {
42- f = ByteBuffer .class
43- .getDeclaredField ("isReadOnly" );
44- f .setAccessible (true );
45- } catch (NoSuchFieldException e ) {
46- LOG .error ("No isReadOnly field in ByteBuffer" , e );
42+ if (JavaUtils .isJavaVersionAtMost (8 )) {
43+ try {
44+ f = ByteBuffer .class
45+ .getDeclaredField ("isReadOnly" );
46+ f .setAccessible (true );
47+ } catch (NoSuchFieldException e ) {
48+ LOG .error ("No isReadOnly field in ByteBuffer" , e );
49+ }
4750 }
4851 IS_READY_ONLY_FIELD = f ;
4952 }
You can’t perform that action at this time.
0 commit comments