This is an automated email from the ASF dual-hosted git repository.

dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new e208f4b  [AVRO-2624] Bunch of casts to just Buffer so that avro built 
with Java11 will work at runtime with Java 8.
e208f4b is described below

commit e208f4b2d442bc14aaba3dad86e8122b83a0873c
Author: Daniel Kulp <dk...@apache.org>
AuthorDate: Fri May 22 17:13:44 2020 -0400

    [AVRO-2624] Bunch of casts to just Buffer so that avro built with Java11 
will work at runtime with Java 8.
---
 .../main/java/org/apache/avro/SchemaBuilder.java    |  5 +++--
 .../java/org/apache/avro/data/TimeConversions.java  | 10 +++++-----
 .../main/java/org/apache/avro/file/SnappyCodec.java |  7 ++++---
 .../java/org/apache/avro/generic/GenericData.java   |  3 ++-
 .../main/java/org/apache/avro/io/BinaryDecoder.java |  5 +++--
 .../org/apache/avro/io/DirectBinaryDecoder.java     |  5 +++--
 .../apache/avro/util/ByteBufferOutputStream.java    |  8 +++++---
 .../main/java/org/apache/avro/util/RandomData.java  |  3 ++-
 .../avro/util/ReusableByteBufferInputStream.java    | 13 +++++++++----
 .../apache/avro/ipc/netty/NettyTransportCodec.java  |  7 ++++---
 .../org/apache/avro/ipc/DatagramTransceiver.java    | 13 +++++++------
 .../java/org/apache/avro/ipc/HttpTransceiver.java   |  7 ++++---
 .../org/apache/avro/ipc/SaslSocketTransceiver.java  | 21 +++++++++++----------
 .../java/org/apache/avro/ipc/SocketTransceiver.java | 11 ++++++-----
 .../apache/avro/mapred/AvroTextOutputFormat.java    |  3 ++-
 .../org/apache/avro/protobuf/ProtoConversions.java  |  8 ++++----
 .../java/org/apache/avro/tool/FromTextTool.java     | 11 ++++++-----
 .../main/java/org/apache/trevni/Crc32Checksum.java  |  3 ++-
 .../main/java/org/apache/trevni/InputBuffer.java    |  5 +++--
 .../main/java/org/apache/trevni/SnappyCodec.java    |  5 +++--
 .../test/java/org/apache/trevni/TestAllCodecs.java  | 13 +++++++------
 21 files changed, 95 insertions(+), 71 deletions(-)

diff --git a/lang/java/avro/src/main/java/org/apache/avro/SchemaBuilder.java 
b/lang/java/avro/src/main/java/org/apache/avro/SchemaBuilder.java
index e5b93d8..ffb198f 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/SchemaBuilder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/SchemaBuilder.java
@@ -18,6 +18,7 @@
 package org.apache.avro;
 
 import java.io.IOException;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
@@ -2701,10 +2702,10 @@ public class SchemaBuilder {
         // special case since GenericData.toString() is incorrect for bytes
         // note that this does not handle the case of a default value with 
nested bytes
         ByteBuffer bytes = ((ByteBuffer) o);
-        bytes.mark();
+        ((Buffer) bytes).mark();
         byte[] data = new byte[bytes.remaining()];
         bytes.get(data);
-        bytes.reset(); // put the buffer back the way we got it
+        ((Buffer) bytes).reset(); // put the buffer back the way we got it
         s = new String(data, StandardCharsets.ISO_8859_1);
         char[] quoted = JsonStringEncoder.getInstance().quoteAsString(s);
         s = "\"" + new String(quoted) + "\"";
diff --git 
a/lang/java/avro/src/main/java/org/apache/avro/data/TimeConversions.java 
b/lang/java/avro/src/main/java/org/apache/avro/data/TimeConversions.java
index 52ec426..785d31a 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/data/TimeConversions.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/data/TimeConversions.java
@@ -175,8 +175,8 @@ public class TimeConversions {
 
     @Override
     public Instant fromLong(Long microsFromEpoch, Schema schema, LogicalType 
type) {
-      long epochSeconds = microsFromEpoch / (1_000_000);
-      long nanoAdjustment = (microsFromEpoch % (1_000_000)) * 1_000;
+      long epochSeconds = microsFromEpoch / (1_000_000L);
+      long nanoAdjustment = (microsFromEpoch % (1_000_000L)) * 1_000L;
 
       return Instant.ofEpochSecond(epochSeconds, nanoAdjustment);
     }
@@ -187,14 +187,14 @@ public class TimeConversions {
       int nanos = instant.getNano();
 
       if (seconds < 0 && nanos > 0) {
-        long micros = Math.multiplyExact(seconds + 1, 1_000_000);
+        long micros = Math.multiplyExact(seconds + 1, 1_000_000L);
         long adjustment = (nanos / 1_000L) - 1_000_000;
 
         return Math.addExact(micros, adjustment);
       } else {
-        long micros = Math.multiplyExact(seconds, 1_000_000);
+        long micros = Math.multiplyExact(seconds, 1_000_000L);
 
-        return Math.addExact(micros, nanos / 1_000);
+        return Math.addExact(micros, nanos / 1_000L);
       }
     }
 
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java 
b/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java
index fddba65..72bf0b7 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java
@@ -18,6 +18,7 @@
 package org.apache.avro.file;
 
 import java.io.IOException;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.util.zip.CRC32;
 
@@ -57,7 +58,7 @@ public class SnappyCodec extends Codec {
     crc32.update(in.array(), offset, in.remaining());
     out.putInt(size, (int) crc32.getValue());
 
-    out.limit(size + 4);
+    ((Buffer) out).limit(size + 4);
 
     return out;
   }
@@ -67,11 +68,11 @@ public class SnappyCodec extends Codec {
     int offset = computeOffset(in);
     ByteBuffer out = ByteBuffer.allocate(Snappy.uncompressedLength(in.array(), 
offset, in.remaining() - 4));
     int size = Snappy.uncompress(in.array(), offset, in.remaining() - 4, 
out.array(), 0);
-    out.limit(size);
+    ((Buffer) out).limit(size);
 
     crc32.reset();
     crc32.update(out.array(), 0, size);
-    if (in.getInt(in.limit() - 4) != (int) crc32.getValue())
+    if (in.getInt(((Buffer) in).limit() - 4) != (int) crc32.getValue())
       throw new IOException("Checksum failure");
 
     return out;
diff --git 
a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java 
b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
index 77cd4af..60fca8e 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
@@ -19,6 +19,7 @@ package org.apache.avro.generic;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 import java.util.AbstractList;
@@ -1252,7 +1253,7 @@ public class GenericData {
       int length = byteBufferValue.limit() - start;
       byte[] bytesCopy = new byte[length];
       byteBufferValue.get(bytesCopy, 0, length);
-      byteBufferValue.position(start);
+      ((Buffer) byteBufferValue).position(start);
       return ByteBuffer.wrap(bytesCopy, 0, length);
     case DOUBLE:
       return value; // immutable
diff --git a/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java 
b/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
index c36c743..7091a5c 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
@@ -20,6 +20,7 @@ package org.apache.avro.io;
 import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.util.Arrays;
 
@@ -309,12 +310,12 @@ public class BinaryDecoder extends Decoder {
     final ByteBuffer result;
     if (old != null && length <= old.capacity()) {
       result = old;
-      result.clear();
+      ((Buffer) result).clear();
     } else {
       result = ByteBuffer.allocate(length);
     }
     doReadBytes(result.array(), result.position(), length);
-    result.limit(length);
+    ((Buffer) result).limit(length);
     return result;
   }
 
diff --git 
a/lang/java/avro/src/main/java/org/apache/avro/io/DirectBinaryDecoder.java 
b/lang/java/avro/src/main/java/org/apache/avro/io/DirectBinaryDecoder.java
index fd92232..7b05655 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/io/DirectBinaryDecoder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/io/DirectBinaryDecoder.java
@@ -20,6 +20,7 @@ package org.apache.avro.io;
 import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 
 import org.apache.avro.InvalidNumberEncodingException;
@@ -42,12 +43,12 @@ class DirectBinaryDecoder extends BinaryDecoder {
       ByteBuffer result;
       if (old != null && length <= old.capacity()) {
         result = old;
-        result.clear();
+        ((Buffer) result).clear();
       } else {
         result = ByteBuffer.allocate(length);
       }
       doReadBytes(result.array(), result.position(), length);
-      result.limit(length);
+      ((Buffer) result).limit(length);
       return result;
     }
   }
diff --git 
a/lang/java/avro/src/main/java/org/apache/avro/util/ByteBufferOutputStream.java 
b/lang/java/avro/src/main/java/org/apache/avro/util/ByteBufferOutputStream.java
index ddb44a6..00fe1b1 100644
--- 
a/lang/java/avro/src/main/java/org/apache/avro/util/ByteBufferOutputStream.java
+++ 
b/lang/java/avro/src/main/java/org/apache/avro/util/ByteBufferOutputStream.java
@@ -20,6 +20,7 @@ package org.apache.avro.util;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 
 import java.util.ArrayList;
@@ -42,14 +43,15 @@ public class ByteBufferOutputStream extends OutputStream {
   public List<ByteBuffer> getBufferList() {
     List<ByteBuffer> result = buffers;
     reset();
-    for (ByteBuffer buffer : result)
+    for (Buffer buffer : result) {
       buffer.flip();
+    }
     return result;
   }
 
   /** Prepend a list of ByteBuffers to this stream. */
   public void prepend(List<ByteBuffer> lists) {
-    for (ByteBuffer buffer : lists) {
+    for (Buffer buffer : lists) {
       buffer.position(buffer.limit());
     }
     buffers.addAll(0, lists);
@@ -57,7 +59,7 @@ public class ByteBufferOutputStream extends OutputStream {
 
   /** Append a list of ByteBuffers to this stream. */
   public void append(List<ByteBuffer> lists) {
-    for (ByteBuffer buffer : lists) {
+    for (Buffer buffer : lists) {
       buffer.position(buffer.limit());
     }
     buffers.addAll(lists);
diff --git a/lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java 
b/lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java
index 84224dc..e4623fc 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java
@@ -18,6 +18,7 @@
 package org.apache.avro.util;
 
 import java.io.File;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 import java.util.HashMap;
@@ -155,7 +156,7 @@ public class RandomData implements Iterable<Object> {
 
   private static ByteBuffer randomBytes(Random rand, int maxLength) {
     ByteBuffer bytes = ByteBuffer.allocate(rand.nextInt(maxLength));
-    bytes.limit(bytes.capacity());
+    ((Buffer) bytes).limit(bytes.capacity());
     rand.nextBytes(bytes.array());
     return bytes;
   }
diff --git 
a/lang/java/avro/src/main/java/org/apache/avro/util/ReusableByteBufferInputStream.java
 
b/lang/java/avro/src/main/java/org/apache/avro/util/ReusableByteBufferInputStream.java
index 9cf9026..942cddc 100644
--- 
a/lang/java/avro/src/main/java/org/apache/avro/util/ReusableByteBufferInputStream.java
+++ 
b/lang/java/avro/src/main/java/org/apache/avro/util/ReusableByteBufferInputStream.java
@@ -21,25 +21,30 @@ package org.apache.avro.util;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 
 public class ReusableByteBufferInputStream extends InputStream {
 
   private static final ByteBuffer EMPTY_BUFFER = ByteBuffer.allocate(0);
 
-  private ByteBuffer buffer = EMPTY_BUFFER;
+  // work around issues compiling with Java11 but running with 8
+  // due to ByteBuffer overriding several methods
+  private ByteBuffer byteBuffer = EMPTY_BUFFER;
+  private Buffer buffer = byteBuffer;
   private int mark = 0;
 
   public void setByteBuffer(ByteBuffer buf) {
     // do not modify the buffer that is passed in
-    this.buffer = buf.duplicate();
+    this.byteBuffer = buf.duplicate();
+    this.buffer = byteBuffer;
     this.mark = buf.position();
   }
 
   @Override
   public int read() throws IOException {
     if (buffer.hasRemaining()) {
-      return buffer.get() & 0xff;
+      return byteBuffer.get() & 0xff;
     } else {
       return -1;
     }
@@ -52,7 +57,7 @@ public class ReusableByteBufferInputStream extends 
InputStream {
     }
     // allow IndexOutOfBoundsException to be thrown by ByteBuffer#get
     int bytesToRead = Math.min(len, buffer.remaining());
-    buffer.get(b, off, bytesToRead);
+    byteBuffer.get(b, off, bytesToRead);
     return bytesToRead;
   }
 
diff --git 
a/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyTransportCodec.java
 
b/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyTransportCodec.java
index cd006a7..6e3ef1f 100644
--- 
a/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyTransportCodec.java
+++ 
b/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyTransportCodec.java
@@ -18,6 +18,7 @@
 
 package org.apache.avro.ipc.netty;
 
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
@@ -98,14 +99,14 @@ public class NettyTransportCodec {
       ByteBuffer header = ByteBuffer.allocate(8);
       header.putInt(dataPack.getSerial());
       header.putInt(dataPack.getDatas().size());
-      header.flip();
+      ((Buffer) header).flip();
       return header;
     }
 
     private ByteBuffer getLengthHeader(ByteBuffer buf) {
       ByteBuffer header = ByteBuffer.allocate(4);
       header.putInt(buf.limit());
-      header.flip();
+      ((Buffer) header).flip();
       return header;
     }
   }
@@ -186,7 +187,7 @@ public class NettyTransportCodec {
 
       ByteBuffer bb = ByteBuffer.allocate(length);
       buffer.readBytes(bb);
-      bb.flip();
+      ((Buffer) bb).flip();
       dataPack.getDatas().add(bb);
 
       return dataPack.getDatas().size() == listSize;
diff --git 
a/lang/java/ipc/src/main/java/org/apache/avro/ipc/DatagramTransceiver.java 
b/lang/java/ipc/src/main/java/org/apache/avro/ipc/DatagramTransceiver.java
index edef5a9..8c21779 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/DatagramTransceiver.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/DatagramTransceiver.java
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.ArrayList;
 import java.io.IOException;
 import java.net.SocketAddress;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.nio.channels.DatagramChannel;
 
@@ -57,10 +58,10 @@ public class DatagramTransceiver extends Transceiver {
 
   @Override
   public synchronized List<ByteBuffer> readBuffers() throws IOException {
-    buffer.clear();
+    ((Buffer) buffer).clear();
     remote = channel.receive(buffer);
     LOG.info("received from " + remote);
-    buffer.flip();
+    ((Buffer) buffer).flip();
     List<ByteBuffer> buffers = new ArrayList<>();
     while (true) {
       int length = buffer.getInt();
@@ -68,21 +69,21 @@ public class DatagramTransceiver extends Transceiver {
         return buffers;
       }
       ByteBuffer chunk = buffer.slice(); // use data without copying
-      chunk.limit(length);
-      buffer.position(buffer.position() + length);
+      ((Buffer) chunk).limit(length);
+      ((Buffer) buffer).position(buffer.position() + length);
       buffers.add(chunk);
     }
   }
 
   @Override
   public synchronized void writeBuffers(List<ByteBuffer> buffers) throws 
IOException {
-    buffer.clear();
+    ((Buffer) buffer).clear();
     for (ByteBuffer b : buffers) {
       buffer.putInt(b.remaining());
       buffer.put(b); // copy data. sigh.
     }
     buffer.putInt(0);
-    buffer.flip();
+    ((Buffer) buffer).flip();
     channel.send(buffer, remote);
     LOG.info("sent to " + remote);
   }
diff --git 
a/lang/java/ipc/src/main/java/org/apache/avro/ipc/HttpTransceiver.java 
b/lang/java/ipc/src/main/java/org/apache/avro/ipc/HttpTransceiver.java
index f4b47e1..86737d6 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/HttpTransceiver.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/HttpTransceiver.java
@@ -23,6 +23,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.EOFException;
 import java.net.Proxy;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
@@ -106,9 +107,9 @@ public class HttpTransceiver extends Transceiver {
         int i = in.read(buffer.array(), p, buffer.remaining());
         if (i < 0)
           throw new EOFException("Unexpected EOF");
-        buffer.position(p + i);
+        ((Buffer) buffer).position(p + i);
       }
-      buffer.flip();
+      ((Buffer) buffer).flip();
       buffers.add(buffer);
     }
   }
@@ -117,7 +118,7 @@ public class HttpTransceiver extends Transceiver {
     for (ByteBuffer buffer : buffers) {
       writeLength(buffer.limit(), out); // length-prefix
       out.write(buffer.array(), buffer.position(), buffer.remaining());
-      buffer.position(buffer.limit());
+      ((Buffer) buffer).position(buffer.limit());
     }
     writeLength(0, out); // null-terminate
   }
diff --git 
a/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java 
b/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java
index 3866598..d0e9dd0 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java
@@ -24,6 +24,7 @@ import java.io.EOFException;
 import java.net.SocketAddress;
 import java.nio.channels.SocketChannel;
 import java.nio.charset.StandardCharsets;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
@@ -187,7 +188,7 @@ public class SaslSocketTransceiver extends Transceiver {
     List<ByteBuffer> buffers = new ArrayList<>();
     while (true) {
       ByteBuffer buffer = readFrameAndUnwrap();
-      if (buffer.remaining() == 0)
+      if (((Buffer) buffer).remaining() == 0)
         return buffers;
       buffers.add(buffer);
     }
@@ -220,11 +221,11 @@ public class SaslSocketTransceiver extends Transceiver {
   }
 
   private void read(ByteBuffer buffer) throws IOException {
-    buffer.clear();
+    ((Buffer) buffer).clear();
     while (buffer.hasRemaining())
       if (channel.read(buffer) == -1)
         throw new EOFException();
-    buffer.flip();
+    ((Buffer) buffer).flip();
   }
 
   @Override
@@ -247,7 +248,7 @@ public class SaslSocketTransceiver extends Transceiver {
         if (currentLength == 0)
           writes.add(currentHeader);
         currentLength += length;
-        currentHeader.clear();
+        ((Buffer) currentHeader).clear();
         currentHeader.putInt(currentLength);
         LOG.debug("adding {} to write, total now {}", length, currentLength);
       } else {
@@ -256,10 +257,10 @@ public class SaslSocketTransceiver extends Transceiver {
         writes.add(currentHeader);
         LOG.debug("planning write of {}", length);
       }
-      currentHeader.flip();
+      ((Buffer) currentHeader).flip();
       writes.add(buffer);
     }
-    zeroHeader.flip(); // zero-terminate
+    ((Buffer) zeroHeader).flip(); // zero-terminate
     writes.add(zeroHeader);
 
     writeFully(writes.toArray(new ByteBuffer[0]));
@@ -278,16 +279,16 @@ public class SaslSocketTransceiver extends Transceiver {
   private void write(Status status, ByteBuffer response) throws IOException {
     LOG.debug("write status: {}", status);
     ByteBuffer statusBuffer = ByteBuffer.allocate(1);
-    statusBuffer.clear();
-    statusBuffer.put((byte) (status.ordinal())).flip();
+    ((Buffer) statusBuffer).clear();
+    ((Buffer) statusBuffer.put((byte) (status.ordinal()))).flip();
     writeFully(statusBuffer);
     write(response);
   }
 
   private void write(ByteBuffer response) throws IOException {
     LOG.debug("writing: {}", response.remaining());
-    writeHeader.clear();
-    writeHeader.putInt(response.remaining()).flip();
+    ((Buffer) writeHeader).clear();
+    ((Buffer) writeHeader.putInt(response.remaining())).flip();
     writeFully(writeHeader, response);
   }
 
diff --git 
a/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketTransceiver.java 
b/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketTransceiver.java
index 14af79e..909dbe1 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketTransceiver.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketTransceiver.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.net.SocketAddress;
 import java.nio.channels.SocketChannel;
 import java.nio.channels.ClosedChannelException;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
@@ -64,12 +65,12 @@ public class SocketTransceiver extends Transceiver {
   public synchronized List<ByteBuffer> readBuffers() throws IOException {
     List<ByteBuffer> buffers = new ArrayList<>();
     while (true) {
-      header.clear();
+      ((Buffer) header).clear();
       while (header.hasRemaining()) {
         if (channel.read(header) < 0)
           throw new ClosedChannelException();
       }
-      header.flip();
+      ((Buffer) header).flip();
       int length = header.getInt();
       if (length == 0) { // end of buffers
         return buffers;
@@ -79,7 +80,7 @@ public class SocketTransceiver extends Transceiver {
         if (channel.read(buffer) < 0)
           throw new ClosedChannelException();
       }
-      buffer.flip();
+      ((Buffer) buffer).flip();
       buffers.add(buffer);
     }
   }
@@ -98,9 +99,9 @@ public class SocketTransceiver extends Transceiver {
   }
 
   private void writeLength(int length) throws IOException {
-    header.clear();
+    ((Buffer) header).clear();
     header.putInt(length);
-    header.flip();
+    ((Buffer) header).flip();
     channel.write(header);
   }
 
diff --git 
a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroTextOutputFormat.java
 
b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroTextOutputFormat.java
index f3fb631..6a0e37c 100644
--- 
a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroTextOutputFormat.java
+++ 
b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroTextOutputFormat.java
@@ -21,6 +21,7 @@ package org.apache.avro.mapred;
 import static org.apache.avro.mapred.AvroOutputFormat.EXT;
 
 import java.io.IOException;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 
@@ -123,7 +124,7 @@ public class AvroTextOutputFormat<K, V> extends 
FileOutputFormat<K, V> {
       buf.put(keyBytes, 0, keyLength);
       buf.put(sep);
       buf.put(valBytes, 0, valLength);
-      buf.rewind();
+      ((Buffer) buf).rewind();
       return buf;
     }
 
diff --git 
a/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtoConversions.java
 
b/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtoConversions.java
index 1c8c109..424e94c 100644
--- 
a/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtoConversions.java
+++ 
b/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtoConversions.java
@@ -117,12 +117,12 @@ public class ProtoConversions {
 
     switch (precise) {
     case Millis:
-      seconds = Math.floorDiv(elapsedSinceEpoch, THOUSAND);
-      nanos = (int) Math.floorMod(elapsedSinceEpoch, THOUSAND) * MILLION;
+      seconds = Math.floorDiv(elapsedSinceEpoch, (long) THOUSAND);
+      nanos = (int) Math.floorMod(elapsedSinceEpoch, (long) THOUSAND) * 
MILLION;
       break;
     case Micros:
-      seconds = Math.floorDiv(elapsedSinceEpoch, MILLION);
-      nanos = (int) Math.floorMod(elapsedSinceEpoch, MILLION) * THOUSAND;
+      seconds = Math.floorDiv(elapsedSinceEpoch, (long) MILLION);
+      nanos = (int) Math.floorMod(elapsedSinceEpoch, (long) MILLION) * 
THOUSAND;
       break;
     }
 
diff --git 
a/lang/java/tools/src/main/java/org/apache/avro/tool/FromTextTool.java 
b/lang/java/tools/src/main/java/org/apache/avro/tool/FromTextTool.java
index e632c1e..2c7da31 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/FromTextTool.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/FromTextTool.java
@@ -21,6 +21,7 @@ import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.InputStream;
 import java.io.PrintStream;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.util.List;
 
@@ -86,21 +87,21 @@ public class FromTextTool implements Tool {
         if (b == '\n') { // newline
           if (!returnSeen) {
             System.out.println("Writing line = " + line.position());
-            line.flip();
+            ((Buffer) line).flip();
             writer.append(line);
-            line.clear();
+            ((Buffer) line).clear();
           } else {
             returnSeen = false;
           }
         } else if (b == '\r') { // return
-          line.flip();
+          ((Buffer) line).flip();
           writer.append(line);
-          line.clear();
+          ((Buffer) line).clear();
           returnSeen = true;
         } else {
           if (line.position() == line.limit()) { // reallocate longer line
             ByteBuffer tempLine = ByteBuffer.allocate(line.limit() * 2);
-            line.flip();
+            ((Buffer) line).flip();
             tempLine.put(line);
             line = tempLine;
           }
diff --git 
a/lang/java/trevni/core/src/main/java/org/apache/trevni/Crc32Checksum.java 
b/lang/java/trevni/core/src/main/java/org/apache/trevni/Crc32Checksum.java
index 453ca06..3bb765a 100644
--- a/lang/java/trevni/core/src/main/java/org/apache/trevni/Crc32Checksum.java
+++ b/lang/java/trevni/core/src/main/java/org/apache/trevni/Crc32Checksum.java
@@ -17,6 +17,7 @@
  */
 package org.apache.trevni;
 
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.util.zip.CRC32;
 
@@ -36,7 +37,7 @@ final class Crc32Checksum extends Checksum {
 
     ByteBuffer result = ByteBuffer.allocate(size());
     result.putInt((int) crc32.getValue());
-    result.flip();
+    ((Buffer) result).flip();
     return result;
   }
 
diff --git 
a/lang/java/trevni/core/src/main/java/org/apache/trevni/InputBuffer.java 
b/lang/java/trevni/core/src/main/java/org/apache/trevni/InputBuffer.java
index c66e292..2234a1f 100644
--- a/lang/java/trevni/core/src/main/java/org/apache/trevni/InputBuffer.java
+++ b/lang/java/trevni/core/src/main/java/org/apache/trevni/InputBuffer.java
@@ -19,6 +19,7 @@ package org.apache.trevni;
 
 import java.io.EOFException;
 import java.io.IOException;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
@@ -327,12 +328,12 @@ class InputBuffer {
     ByteBuffer result;
     if (old != null && length <= old.capacity()) {
       result = old;
-      result.clear();
+      ((Buffer) result).clear();
     } else {
       result = ByteBuffer.allocate(length);
     }
     readFully(result.array(), result.position(), length);
-    result.limit(length);
+    ((Buffer) result).limit(length);
     return result;
   }
 
diff --git 
a/lang/java/trevni/core/src/main/java/org/apache/trevni/SnappyCodec.java 
b/lang/java/trevni/core/src/main/java/org/apache/trevni/SnappyCodec.java
index 0b7aa4a..94bc7cd 100644
--- a/lang/java/trevni/core/src/main/java/org/apache/trevni/SnappyCodec.java
+++ b/lang/java/trevni/core/src/main/java/org/apache/trevni/SnappyCodec.java
@@ -18,6 +18,7 @@
 package org.apache.trevni;
 
 import java.io.IOException;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import org.xerial.snappy.Snappy;
 
@@ -29,7 +30,7 @@ final class SnappyCodec extends Codec {
     int offset = computeOffset(in);
     ByteBuffer out = 
ByteBuffer.allocate(Snappy.maxCompressedLength(in.remaining()));
     int size = Snappy.compress(in.array(), offset, in.remaining(), 
out.array(), 0);
-    out.limit(size);
+    ((Buffer) out).limit(size);
     return out;
   }
 
@@ -38,7 +39,7 @@ final class SnappyCodec extends Codec {
     int offset = computeOffset(in);
     ByteBuffer out = ByteBuffer.allocate(Snappy.uncompressedLength(in.array(), 
offset, in.remaining()));
     int size = Snappy.uncompress(in.array(), offset, in.remaining(), 
out.array(), 0);
-    out.limit(size);
+    ((Buffer) out).limit(size);
     return out;
   }
 
diff --git 
a/lang/java/trevni/core/src/test/java/org/apache/trevni/TestAllCodecs.java 
b/lang/java/trevni/core/src/test/java/org/apache/trevni/TestAllCodecs.java
index ae535b9..c588046 100644
--- a/lang/java/trevni/core/src/test/java/org/apache/trevni/TestAllCodecs.java
+++ b/lang/java/trevni/core/src/test/java/org/apache/trevni/TestAllCodecs.java
@@ -23,6 +23,7 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
 import java.io.IOException;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.util.Arrays;
 import java.util.Collection;
@@ -71,7 +72,7 @@ public class TestAllCodecs {
     ByteBuffer decompressedBuffer = codecInstance.decompress(compressedBuffer);
 
     // Validate the the input and output are equal.
-    inputByteBuffer.rewind();
+    ((Buffer) inputByteBuffer).rewind();
     assertEquals(decompressedBuffer, inputByteBuffer);
   }
 
@@ -82,7 +83,7 @@ public class TestAllCodecs {
 
     Codec codecInstance = getCodec(codec);
     ByteBuffer partialBuffer = ByteBuffer.wrap(input);
-    partialBuffer.position(17);
+    ((Buffer) partialBuffer).position(17);
 
     ByteBuffer inputByteBuffer = partialBuffer.slice();
     ByteBuffer compressedBuffer = codecInstance.compress(inputByteBuffer);
@@ -94,16 +95,16 @@ public class TestAllCodecs {
 
     // Create a slice from the compressed buffer
     ByteBuffer sliceBuffer = ByteBuffer.allocate(compressedSize + 100);
-    sliceBuffer.position(50);
+    ((Buffer) sliceBuffer).position(50);
     sliceBuffer.put(compressedBuffer);
-    sliceBuffer.limit(compressedSize + 50);
-    sliceBuffer.position(50);
+    ((Buffer) sliceBuffer).limit(compressedSize + 50);
+    ((Buffer) sliceBuffer).position(50);
 
     // Decompress the data
     ByteBuffer decompressedBuffer = 
codecInstance.decompress(sliceBuffer.slice());
 
     // Validate the the input and output are equal.
-    inputByteBuffer.rewind();
+    ((Buffer) inputByteBuffer).rewind();
     assertEquals(decompressedBuffer, inputByteBuffer);
   }
 

Reply via email to