Skip to content

Commit

Permalink
Removed JVMUtil.upcast(Buffer). (hazelcast#26073)
Browse files Browse the repository at this point in the history
The method isn't used any longer, so goodbye.

Follow up PR for: hazelcast#26067
  • Loading branch information
pveentjer committed Nov 28, 2023
1 parent 367a63a commit 88bf178
Showing 1 changed file with 0 additions and 31 deletions.
31 changes: 0 additions & 31 deletions hazelcast/src/main/java/com/hazelcast/internal/util/JVMUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import javax.management.ObjectName;
import javax.management.openmbean.CompositeDataSupport;
import java.lang.management.ManagementFactory;
import java.nio.Buffer;

import static com.hazelcast.internal.memory.impl.UnsafeUtil.UNSAFE;
import static com.hazelcast.internal.memory.impl.UnsafeUtil.UNSAFE_AVAILABLE;
Expand Down Expand Up @@ -99,36 +98,6 @@ public static long usedMemory(final Runtime runtime) {
return used;
}

/**
* Explicit cast to {@link Buffer} parent buffer type. It resolves issues with covariant return types in Java 9+ for
* {@link java.nio.ByteBuffer} and {@link java.nio.CharBuffer}. Explicit casting resolves the NoSuchMethodErrors (e.g
* java.lang.NoSuchMethodError: java.nio.ByteBuffer.limit(I)Ljava/nio/ByteBuffer) when the project is compiled with newer
* Java version and run on Java 8.
* <p/>
* <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html">Java 8</a> doesn't provide override the
* following Buffer methods in subclasses:
*
* <pre>
* Buffer clear​()
* Buffer flip​()
* Buffer limit​(int newLimit)
* Buffer mark​()
* Buffer position​(int newPosition)
* Buffer reset​()
* Buffer rewind​()
* </pre>
*
* <a href="https://docs.oracle.com/javase/9/docs/api/java/nio/ByteBuffer.html">Java 9</a> introduces the overrides in child
* classes (e.g the ByteBuffer), but the return type is the specialized one and not the abstract {@link Buffer}. So the code
* compiled with newer Java is not working on Java 8 unless a workaround with explicit casting is used.
*
* @param buf buffer to cast to the abstract {@link Buffer} parent type
* @return the provided buffer
*/
public static Buffer upcast(Buffer buf) {
return buf;
}

// not private for testing
@SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL")
static Boolean isHotSpotCompressedOopsOrNull() {
Expand Down

0 comments on commit 88bf178

Please sign in to comment.