Flip buffers using helper method (#3311)

* flip buffer using helper method

* make constructor private

* make class final

* move constructor to top of class

* no-op

* empty commit to re-trigger CI

* final try for flaky integration tests
diff --git a/heron/common/src/java/org/apache/heron/common/network/BufferHelper.java b/heron/common/src/java/org/apache/heron/common/network/BufferHelper.java
new file mode 100644
index 0000000..2849923
--- /dev/null
+++ b/heron/common/src/java/org/apache/heron/common/network/BufferHelper.java
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.heron.common.network;
+
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+
+/**
+ * Helper methods for working with {@link Buffer} objects.
+ */
+final class BufferHelper {
+
+  private BufferHelper() {
+  }
+
+  /**
+   * Flip the provided buffer.
+   * <p>
+   * This wrapper around {@link Buffer#flip()} is required because of
+   * incompatible ABI changes between Java 8 and 11. In Java 8, {@link ByteBuffer#flip()} returns
+   * a {@link Buffer}, whereas in Java 11, this method returns a {@link ByteBuffer}.
+   * <p>
+   * If this function is used, any object of {@link Buffer} (and subclasses) are first cast to
+   * {@link Buffer} objects, then flipped, thus avoiding the binary incompatibility.
+   *
+   * @param buffer The buffer to flip
+   */
+  static void flip(Buffer buffer) {
+    buffer.flip();
+  }
+}
diff --git a/heron/common/src/java/org/apache/heron/common/network/IncomingPacket.java b/heron/common/src/java/org/apache/heron/common/network/IncomingPacket.java
index 045602e..b1bf26c 100644
--- a/heron/common/src/java/org/apache/heron/common/network/IncomingPacket.java
+++ b/heron/common/src/java/org/apache/heron/common/network/IncomingPacket.java
@@ -76,7 +76,7 @@
       }
       // We read the header fully
       headerRead = true;
-      header.flip();
+      BufferHelper.flip(header);
       int size = header.getInt();
       if (size > limit) {
         LOG.log(Level.SEVERE, "packet size " + size + " exceeds limit " + limit);
@@ -86,7 +86,7 @@
     }
     int retval = readFromChannel(channel, data);
     if (retval == 0) {
-      data.flip();
+      BufferHelper.flip(data);
     }
     return retval;
   }
diff --git a/heron/common/src/java/org/apache/heron/common/network/OutgoingPacket.java b/heron/common/src/java/org/apache/heron/common/network/OutgoingPacket.java
index 2b91077..63983db 100644
--- a/heron/common/src/java/org/apache/heron/common/network/OutgoingPacket.java
+++ b/heron/common/src/java/org/apache/heron/common/network/OutgoingPacket.java
@@ -82,7 +82,7 @@
     buffer.put(message.toByteArray());
 
     // Make the buffer ready for writing out
-    buffer.flip();
+    BufferHelper.flip(buffer);
   }
 
   public static int sizeRequiredToPackString(String str) {