Skip to content

Commit

Permalink
Ensure we call flip() on Buffer to avoid Java8 problems (Fixes hieryn…
Browse files Browse the repository at this point in the history
…omus#705)

Signed-off-by: Jeroen van Erp <[email protected]>
  • Loading branch information
hierynomus committed Mar 19, 2023
1 parent c2afe0a commit 91e14ca
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private ByteBuffer prepareBufferToSend(P packet) {
toSend.order(ByteOrder.BIG_ENDIAN);
toSend.putInt(packetData.available()); // also writes the initial 0 byte
toSend.put(packetData.array(), packetData.rpos(), packetData.available());
toSend.flip();
((java.nio.Buffer) toSend).flip(); // Java8/9 compatibility
try {
packetData.skip(dataSize);
} catch (BufferException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public <P extends Packet<?>> PacketBufferReader() {


public byte[] readNext() {
readBuffer.flip(); // prepare to process received data
((java.nio.Buffer) readBuffer).flip(); // prepare to process received data (cast is to avoid Java 8/9 compatibility issues)
byte[] bytes = null;
if (isAwaitingHeader() && isHeaderAvailable()) {
currentPacketLength = readPacketHeader();
Expand Down

0 comments on commit 91e14ca

Please sign in to comment.