Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoiding NoSuchMethod exception #6658

Merged
merged 1 commit into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions java/com/google/flatbuffers/ByteBufferReadWriteBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.Buffer;

public class ByteBufferReadWriteBuf implements ReadWriteBuf {

Expand Down Expand Up @@ -117,9 +118,9 @@ public void set(int index, byte value) {
public void set(int index, byte[] value, int start, int length) {
requestCapacity(index + (length - start));
int curPos = buffer.position();
buffer.position(index);
((Buffer) buffer).position(index);
buffer.put(value, start, length);
buffer.position(curPos);
((Buffer) buffer).position(curPos);
}

@Override
Expand Down Expand Up @@ -154,7 +155,7 @@ public void setDouble(int index, double value) {

@Override
public int writePosition() {
return buffer.position();
return ((Buffer) buffer).position();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed?

}

@Override
Expand Down
3 changes: 2 additions & 1 deletion java/com/google/flatbuffers/ByteBufferUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.flatbuffers.Constants.*;

import java.nio.ByteBuffer;
import java.nio.Buffer;

/// @file
/// @addtogroup flatbuffers_java_api
Expand Down Expand Up @@ -49,7 +50,7 @@ public static int getSizePrefix(ByteBuffer bb) {
*/
public static ByteBuffer removeSizePrefix(ByteBuffer bb) {
ByteBuffer s = bb.duplicate();
s.position(s.position() + SIZE_PREFIX_LENGTH);
((Buffer) s).position(s.position() + SIZE_PREFIX_LENGTH);
return s;
}

Expand Down
22 changes: 11 additions & 11 deletions java/com/google/flatbuffers/FlatBufferBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ static ByteBuffer growByteBuffer(ByteBuffer bb, ByteBufferFactory bb_factory) {
new_buf_size = (old_buf_size & 0xC0000000) != 0 ? MAX_BUFFER_SIZE : old_buf_size << 1;
}

bb.position(0);
((Buffer) bb).position(0);
ByteBuffer nbb = bb_factory.newByteBuffer(new_buf_size);
new_buf_size = nbb.clear().capacity(); // Ensure the returned buffer is treated as empty
nbb.position(new_buf_size - old_buf_size);
((Buffer) nbb).position(new_buf_size - old_buf_size);
nbb.put(bb);
return nbb;
}
Expand Down Expand Up @@ -527,7 +527,7 @@ public ByteBuffer createUnintializedVector(int elem_size, int num_elems, int ali
int length = elem_size * num_elems;
startVector(elem_size, num_elems, alignment);

bb.position(space -= length);
((Buffer) bb).position(space -= length);

// Slice and limit the copy vector to point to the 'array'
ByteBuffer copy = bb.slice().order(ByteOrder.LITTLE_ENDIAN);
Expand Down Expand Up @@ -602,7 +602,7 @@ public int createString(CharSequence s) {
int length = utf8.encodedLength(s);
addByte((byte)0);
startVector(1, length, 1);
bb.position(space -= length);
((Buffer) bb).position(space -= length);
utf8.encodeUtf8(s, bb);
return endVector();
}
Expand All @@ -617,7 +617,7 @@ public int createString(ByteBuffer s) {
int length = s.remaining();
addByte((byte)0);
startVector(1, length, 1);
bb.position(space -= length);
((Buffer) bb).position(space -= length);
bb.put(s);
return endVector();
}
Expand All @@ -631,7 +631,7 @@ public int createString(ByteBuffer s) {
public int createByteVector(byte[] arr) {
int length = arr.length;
startVector(1, length, 1);
bb.position(space -= length);
((Buffer) bb).position(space -= length);
bb.put(arr);
return endVector();
}
Expand All @@ -646,7 +646,7 @@ public int createByteVector(byte[] arr) {
*/
public int createByteVector(byte[] arr, int offset, int length) {
startVector(1, length, 1);
bb.position(space -= length);
((Buffer) bb).position(space -= length);
bb.put(arr, offset, length);
return endVector();
}
Expand All @@ -663,7 +663,7 @@ public int createByteVector(byte[] arr, int offset, int length) {
public int createByteVector(ByteBuffer byteBuffer) {
int length = byteBuffer.remaining();
startVector(1, length, 1);
bb.position(space -= length);
((Buffer) bb).position(space -= length);
bb.put(byteBuffer);
return endVector();
}
Expand Down Expand Up @@ -953,7 +953,7 @@ protected void finish(int root_table, boolean size_prefix) {
if (size_prefix) {
addInt(bb.capacity() - space);
}
bb.position(space);
((Buffer) bb).position(space);
finished = true;
}

Expand Down Expand Up @@ -1067,7 +1067,7 @@ private int dataStart() {
public byte[] sizedByteArray(int start, int length){
finished();
byte[] array = new byte[length];
bb.position(start);
((Buffer) bb).position(start);
bb.get(array);
return array;
}
Expand All @@ -1090,7 +1090,7 @@ public byte[] sizedByteArray() {
public InputStream sizedInputStream() {
finished();
ByteBuffer duplicate = bb.duplicate();
duplicate.position(space);
((Buffer) duplicate).position(space);
duplicate.limit(bb.capacity());
return new ByteBufferBackedInputStream(duplicate);
}
Expand Down
3 changes: 2 additions & 1 deletion java/com/google/flatbuffers/FlexBuffers.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.Buffer;
import java.nio.charset.StandardCharsets;

/// @file
Expand Down Expand Up @@ -688,7 +689,7 @@ public static Blob empty() {
*/
public ByteBuffer data() {
ByteBuffer dup = ByteBuffer.wrap(bb.data());
dup.position(end);
((Buffer) dup).position(end);
dup.limit(end + size());
return dup.asReadOnlyBuffer().slice();
}
Expand Down
5 changes: 3 additions & 2 deletions java/com/google/flatbuffers/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.flatbuffers.Constants.*;
import java.nio.ByteBuffer;
import java.nio.Buffer;
import java.nio.ByteOrder;

/// @cond FLATBUFFERS_INTERNAL
Expand Down Expand Up @@ -152,7 +153,7 @@ protected ByteBuffer __vector_as_bytebuffer(int vector_offset, int elem_size) {
if (o == 0) return null;
ByteBuffer bb = this.bb.duplicate().order(ByteOrder.LITTLE_ENDIAN);
int vectorstart = __vector(o);
bb.position(vectorstart);
((Buffer) bb).position(vectorstart);
bb.limit(vectorstart + __vector_len(o) * elem_size);
return bb;
}
Expand All @@ -174,7 +175,7 @@ protected ByteBuffer __vector_in_bytebuffer(ByteBuffer bb, int vector_offset, in
int vectorstart = __vector(o);
bb.rewind();
bb.limit(vectorstart + __vector_len(o) * elem_size);
bb.position(vectorstart);
((Buffer) bb).position(vectorstart);
return bb;
}

Expand Down
3 changes: 2 additions & 1 deletion java/com/google/flatbuffers/Utf8Old.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.flatbuffers;

import java.nio.ByteBuffer;
import java.nio.Buffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetDecoder;
Expand Down Expand Up @@ -87,7 +88,7 @@ public String decodeUtf8(ByteBuffer buffer, int offset, int length) {
CharsetDecoder decoder = CACHE.get().decoder;
decoder.reset();
buffer = buffer.duplicate();
buffer.position(offset);
((Buffer) buffer).position(offset);
buffer.limit(offset + length);
try {
CharBuffer result = decoder.decode(buffer);
Expand Down
7 changes: 4 additions & 3 deletions java/com/google/flatbuffers/Utf8Safe.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
package com.google.flatbuffers;

import java.nio.ByteBuffer;
import java.nio.Buffer;
import static java.lang.Character.MAX_SURROGATE;
import static java.lang.Character.MIN_SUPPLEMENTARY_CODE_POINT;
import static java.lang.Character.MIN_SURROGATE;
Expand Down Expand Up @@ -310,7 +311,7 @@ private static void encodeUtf8Buffer(CharSequence in, ByteBuffer out) {
}
if (inIx == inLength) {
// Successfully encoded the entire string.
out.position(outIx + inIx);
((Buffer) out).position(outIx + inIx);
return;
}

Expand Down Expand Up @@ -353,7 +354,7 @@ private static void encodeUtf8Buffer(CharSequence in, ByteBuffer out) {
}

// Successfully encoded the entire string.
out.position(outIx);
((Buffer) out).position(outIx);
} catch (IndexOutOfBoundsException e) {
// TODO(nathanmittler): Consider making the API throw IndexOutOfBoundsException instead.

Expand Down Expand Up @@ -434,7 +435,7 @@ public void encodeUtf8(CharSequence in, ByteBuffer out) {
int start = out.arrayOffset();
int end = encodeUtf8Array(in, out.array(), start + out.position(),
out.remaining());
out.position(end - start);
((Buffer) out).position(end - start);
} else {
encodeUtf8Buffer(in, out);
}
Expand Down