From a50f76e851d0abd135c415ee5a83d39b6f85a779 Mon Sep 17 00:00:00 2001 From: druzhynin-oleksii Date: Tue, 23 Nov 2021 16:08:04 -0800 Subject: [PATCH] Fix Java 1.8 NoSuchMethodError: java.nio.ByteBuffer.flip() --- .../src/main/java/com/google/caliper/util/Uuids.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/caliper-util/src/main/java/com/google/caliper/util/Uuids.java b/caliper-util/src/main/java/com/google/caliper/util/Uuids.java index 05bf710c..52d5e888 100644 --- a/caliper-util/src/main/java/com/google/caliper/util/Uuids.java +++ b/caliper-util/src/main/java/com/google/caliper/util/Uuids.java @@ -34,11 +34,12 @@ public final class Uuids { private Uuids() {} /** Returns a buffer containing the 16 bytes of the given UUID. */ + @SuppressWarnings("RedundantCast") public static ByteBuffer toBytes(UUID uuid) { ByteBuffer buf = ByteBuffer.allocate(UUID_BYTES); buf.putLong(uuid.getMostSignificantBits()); buf.putLong(uuid.getLeastSignificantBits()); - buf.flip(); + ((java.nio.Buffer) buf).flip(); // for Java 1.8 compatibility return buf; } @@ -57,6 +58,7 @@ public static UUID fromBytes(ByteBuffer buf) { } /** Reads the next 16 bytes from the given channel as a UUID. */ + @SuppressWarnings("RedundantCast") public static UUID readFromChannel(ReadableByteChannel channel) throws IOException { ByteBuffer buf = ByteBuffer.allocate(UUID_BYTES); while (buf.hasRemaining()) { @@ -64,7 +66,7 @@ public static UUID readFromChannel(ReadableByteChannel channel) throws IOExcepti throw new EOFException("unexpected EOF while reading UUID"); } } - buf.flip(); + ((java.nio.Buffer) buf).flip(); // for Java 1.8 compatibility return fromBytes(buf); } }