Skip to content

Commit 2d47661

Browse files
Merge branch '144-flatbuffers-2.0.6' into 'dev'
Update to FlatBuffers 2.0.8 Closes #144 See merge request objectbox/objectbox-java!114
2 parents 499b52f + a8f110c commit 2d47661

25 files changed

+287
-89
lines changed

objectbox-java/src/main/java/io/objectbox/DebugFlags.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2022 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,5 +33,15 @@ private DebugFlags() { }
3333
public static final int LOG_CACHE_HITS = 32;
3434
public static final int LOG_CACHE_ALL = 64;
3535
public static final int LOG_TREE = 128;
36+
/**
37+
* For a limited number of error conditions, this will try to print stack traces.
38+
* Note: this is Linux-only, experimental, and has several limitations:
39+
* The usefulness of these stack traces depends on several factors and might not be helpful at all.
40+
*/
41+
public static final int LOG_EXCEPTION_STACK_TRACE = 256;
42+
/**
43+
* Run a quick self-test to verify basic threading; somewhat paranoia to check the platform and the library setup.
44+
*/
45+
public static final int RUN_THREADING_SELF_TEST = 512;
3646
}
3747

objectbox-java/src/main/java/io/objectbox/flatbuffers/ByteBufferReadWriteBuf.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.nio.ByteBuffer;
44
import java.nio.ByteOrder;
5-
import java.nio.Buffer;
65

76
public class ByteBufferReadWriteBuf implements ReadWriteBuf {
87

@@ -15,7 +14,7 @@ public ByteBufferReadWriteBuf(ByteBuffer bb) {
1514

1615
@Override
1716
public void clear() {
18-
((Buffer) buffer).clear();
17+
buffer.clear();
1918
}
2019

2120
@Override
@@ -118,9 +117,9 @@ public void set(int index, byte value) {
118117
public void set(int index, byte[] value, int start, int length) {
119118
requestCapacity(index + (length - start));
120119
int curPos = buffer.position();
121-
((Buffer) buffer).position(index);
120+
buffer.position(index);
122121
buffer.put(value, start, length);
123-
((Buffer) buffer).position(curPos);
122+
buffer.position(curPos);
124123
}
125124

126125
@Override

objectbox-java/src/main/java/io/objectbox/flatbuffers/ByteBufferUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static io.objectbox.flatbuffers.Constants.*;
2020

2121
import java.nio.ByteBuffer;
22-
import java.nio.Buffer;
2322

2423
/// @file
2524
/// @addtogroup flatbuffers_java_api
@@ -50,7 +49,7 @@ public static int getSizePrefix(ByteBuffer bb) {
5049
*/
5150
public static ByteBuffer removeSizePrefix(ByteBuffer bb) {
5251
ByteBuffer s = bb.duplicate();
53-
((Buffer) s).position(s.position() + SIZE_PREFIX_LENGTH);
52+
s.position(s.position() + SIZE_PREFIX_LENGTH);
5453
return s;
5554
}
5655

objectbox-java/src/main/java/io/objectbox/flatbuffers/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class Constants {
4646
Changes to the Java implementation need to be sure to change
4747
the version here and in the code generator on every possible
4848
incompatible change */
49-
public static void FLATBUFFERS_2_0_0() {}
49+
public static void FLATBUFFERS_2_0_8() {}
5050
}
5151

5252
/// @endcond

objectbox-java/src/main/java/io/objectbox/flatbuffers/FlatBufferBuilder.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public FlatBufferBuilder(int initial_size, ByteBufferFactory bb_factory,
9292
this.bb_factory = bb_factory;
9393
if (existing_bb != null) {
9494
bb = existing_bb;
95-
((Buffer) bb).clear();
95+
bb.clear();
9696
bb.order(ByteOrder.LITTLE_ENDIAN);
9797
} else {
9898
bb = bb_factory.newByteBuffer(initial_size);
@@ -154,7 +154,7 @@ public FlatBufferBuilder(ByteBuffer existing_bb) {
154154
public FlatBufferBuilder init(ByteBuffer existing_bb, ByteBufferFactory bb_factory){
155155
this.bb_factory = bb_factory;
156156
bb = existing_bb;
157-
((Buffer) bb).clear();
157+
bb.clear();
158158
bb.order(ByteOrder.LITTLE_ENDIAN);
159159
minalign = 1;
160160
space = bb.capacity();
@@ -235,7 +235,7 @@ public static boolean isFieldPresent(Table table, int offset) {
235235
*/
236236
public void clear(){
237237
space = bb.capacity();
238-
((Buffer) bb).clear();
238+
bb.clear();
239239
minalign = 1;
240240
while(vtable_in_use > 0) vtable[--vtable_in_use] = 0;
241241
vtable_in_use = 0;
@@ -273,10 +273,10 @@ static ByteBuffer growByteBuffer(ByteBuffer bb, ByteBufferFactory bb_factory) {
273273
new_buf_size = (old_buf_size & 0xC0000000) != 0 ? MAX_BUFFER_SIZE : old_buf_size << 1;
274274
}
275275

276-
((Buffer) bb).position(0);
276+
bb.position(0);
277277
ByteBuffer nbb = bb_factory.newByteBuffer(new_buf_size);
278-
new_buf_size = ((Buffer) nbb).clear().capacity(); // Ensure the returned buffer is treated as empty
279-
((Buffer) nbb).position(new_buf_size - old_buf_size);
278+
new_buf_size = nbb.clear().capacity(); // Ensure the returned buffer is treated as empty
279+
nbb.position(new_buf_size - old_buf_size);
280280
nbb.put(bb);
281281
return nbb;
282282
}
@@ -527,7 +527,7 @@ public ByteBuffer createUnintializedVector(int elem_size, int num_elems, int ali
527527
int length = elem_size * num_elems;
528528
startVector(elem_size, num_elems, alignment);
529529

530-
((Buffer) bb).position(space -= length);
530+
bb.position(space -= length);
531531

532532
// Slice and limit the copy vector to point to the 'array'
533533
ByteBuffer copy = bb.slice().order(ByteOrder.LITTLE_ENDIAN);
@@ -602,7 +602,7 @@ public int createString(CharSequence s) {
602602
int length = utf8.encodedLength(s);
603603
addByte((byte)0);
604604
startVector(1, length, 1);
605-
((Buffer) bb).position(space -= length);
605+
bb.position(space -= length);
606606
utf8.encodeUtf8(s, bb);
607607
return endVector();
608608
}
@@ -617,7 +617,7 @@ public int createString(ByteBuffer s) {
617617
int length = s.remaining();
618618
addByte((byte)0);
619619
startVector(1, length, 1);
620-
((Buffer) bb).position(space -= length);
620+
bb.position(space -= length);
621621
bb.put(s);
622622
return endVector();
623623
}
@@ -631,7 +631,7 @@ public int createString(ByteBuffer s) {
631631
public int createByteVector(byte[] arr) {
632632
int length = arr.length;
633633
startVector(1, length, 1);
634-
((Buffer) bb).position(space -= length);
634+
bb.position(space -= length);
635635
bb.put(arr);
636636
return endVector();
637637
}
@@ -646,7 +646,7 @@ public int createByteVector(byte[] arr) {
646646
*/
647647
public int createByteVector(byte[] arr, int offset, int length) {
648648
startVector(1, length, 1);
649-
((Buffer) bb).position(space -= length);
649+
bb.position(space -= length);
650650
bb.put(arr, offset, length);
651651
return endVector();
652652
}
@@ -663,7 +663,7 @@ public int createByteVector(byte[] arr, int offset, int length) {
663663
public int createByteVector(ByteBuffer byteBuffer) {
664664
int length = byteBuffer.remaining();
665665
startVector(1, length, 1);
666-
((Buffer) bb).position(space -= length);
666+
bb.position(space -= length);
667667
bb.put(byteBuffer);
668668
return endVector();
669669
}
@@ -953,7 +953,7 @@ protected void finish(int root_table, boolean size_prefix) {
953953
if (size_prefix) {
954954
addInt(bb.capacity() - space);
955955
}
956-
((Buffer) bb).position(space);
956+
bb.position(space);
957957
finished = true;
958958
}
959959

@@ -1067,7 +1067,7 @@ private int dataStart() {
10671067
public byte[] sizedByteArray(int start, int length){
10681068
finished();
10691069
byte[] array = new byte[length];
1070-
((Buffer) bb).position(start);
1070+
bb.position(start);
10711071
bb.get(array);
10721072
return array;
10731073
}
@@ -1090,7 +1090,7 @@ public byte[] sizedByteArray() {
10901090
public InputStream sizedInputStream() {
10911091
finished();
10921092
ByteBuffer duplicate = bb.duplicate();
1093-
((Buffer) duplicate).position(space);
1093+
duplicate.position(space);
10941094
duplicate.limit(bb.capacity());
10951095
return new ByteBufferBackedInputStream(duplicate);
10961096
}

objectbox-java/src/main/java/io/objectbox/flatbuffers/FlexBuffers.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import java.math.BigInteger;
2525
import java.nio.ByteBuffer;
26-
import java.nio.Buffer;
2726
import java.nio.charset.StandardCharsets;
2827

2928
/// @file
@@ -689,7 +688,7 @@ public static Blob empty() {
689688
*/
690689
public ByteBuffer data() {
691690
ByteBuffer dup = ByteBuffer.wrap(bb.data());
692-
((Buffer) dup).position(end);
691+
dup.position(end);
693692
dup.limit(end + size());
694693
return dup.asReadOnlyBuffer().slice();
695694
}
@@ -789,7 +788,12 @@ int compareTo(byte[] other) {
789788
if (io == other.length) {
790789
// in our buffer we have an additional \0 byte
791790
// but this does not exist in regular Java strings, so we return now
792-
return c1 - c2;
791+
int cmp = c1 - c2;
792+
if (cmp != 0 || bb.get(ia) == '\0') {
793+
return cmp;
794+
} else {
795+
return 1;
796+
}
793797
}
794798
}
795799
while (c1 == c2);
@@ -962,7 +966,12 @@ private int compareBytes(ReadBuf bb, int start, byte[] other) {
962966
if (l2 == other.length) {
963967
// in our buffer we have an additional \0 byte
964968
// but this does not exist in regular Java strings, so we return now
965-
return c1 - c2;
969+
int cmp = c1 - c2;
970+
if (cmp != 0 || bb.get(l1) == '\0') {
971+
return cmp;
972+
} else {
973+
return 1;
974+
}
966975
}
967976
}
968977
while (c1 == c2);

objectbox-java/src/main/java/io/objectbox/flatbuffers/FlexBuffersBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public int startVector() {
451451
/**
452452
* Finishes a vector, but writing the information in the buffer
453453
* @param key key used to store element in map
454-
* @param start reference for begining of the vector. Returned by {@link startVector()}
454+
* @param start reference for beginning of the vector. Returned by {@link startVector()}
455455
* @param typed boolean indicating whether vector is typed
456456
* @param fixed boolean indicating whether vector is fixed
457457
* @return Reference to the vector
@@ -602,7 +602,7 @@ public int startMap() {
602602
/**
603603
* Finishes a map, but writing the information in the buffer
604604
* @param key key used to store element in map
605-
* @param start reference for begining of the map. Returned by {@link startMap()}
605+
* @param start reference for beginning of the map. Returned by {@link startMap()}
606606
* @return Reference to the map
607607
*/
608608
public int endMap(String key, int start) {
@@ -763,7 +763,7 @@ private static int elemWidth(int type, int minBitWidth, long iValue, int bufSize
763763
// Compute relative offset.
764764
long offset = offsetLoc - iValue;
765765
// Does it fit?
766-
int bitWidth = widthUInBits((int) offset);
766+
int bitWidth = widthUInBits(offset);
767767
if (((1L) << bitWidth) == byteWidth)
768768
return bitWidth;
769769
}

0 commit comments

Comments
 (0)