Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically an else branch for isJavaVersionAtLeast(9). ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is, however it is much more explicit about what happens, that's why I chose this way.

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