diff options
author | Paulo Pinheiro <paulovictor.pinheiro@gmail.com> | 2019-09-30 23:05:19 +0200 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2019-09-30 14:05:19 -0700 |
commit | d4cae0a62344b37908b1c157fa1cac27270ea0d0 (patch) | |
tree | 72f9444c6fc127dca6e4caec9d49338e1dd46d68 /java | |
parent | f1147f65bbedeee0cf3843bb06313cbe11fc6191 (diff) | |
download | flatbuffers-d4cae0a62344b37908b1c157fa1cac27270ea0d0.tar.gz flatbuffers-d4cae0a62344b37908b1c157fa1cac27270ea0d0.tar.bz2 flatbuffers-d4cae0a62344b37908b1c157fa1cac27270ea0d0.zip |
Fix issue #5542 (#5543)
Empty objects that inherit from Sized would try to access internal
ByteBuffer when Sized::size was called. So we add a single byte in
the empty buffer, so when size() is called it would return 0
Diffstat (limited to 'java')
-rw-r--r-- | java/com/google/flatbuffers/FlexBuffers.java | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/java/com/google/flatbuffers/FlexBuffers.java b/java/com/google/flatbuffers/FlexBuffers.java index 7f71e050..1cd2227e 100644 --- a/java/com/google/flatbuffers/FlexBuffers.java +++ b/java/com/google/flatbuffers/FlexBuffers.java @@ -98,7 +98,7 @@ public class FlexBuffers { /** Represent a vector of booleans type */ public static final int FBT_VECTOR_BOOL = 36; // To Allow the same type of conversion of type to vector type - private static final ByteBuffer EMPTY_BB = ByteBuffer.allocate(0).asReadOnlyBuffer(); + private static final ByteBuffer EMPTY_BB = ByteBuffer.allocate(1).asReadOnlyBuffer(); /** * Checks where a type is a typed vector @@ -652,7 +652,7 @@ public class FlexBuffers { * have individual bytes accessed individually using {@link get(int)}</p> */ public static class Blob extends Sized { - static final Blob EMPTY = new Blob(EMPTY_BB, 0, 1); + static final Blob EMPTY = new Blob(EMPTY_BB, 1, 1); Blob(ByteBuffer buff, int end, int byteWidth) { super(buff, end, byteWidth); @@ -794,7 +794,7 @@ public class FlexBuffers { * Map object representing a set of key-value pairs. */ public static class Map extends Vector { - private static final Map EMPTY_MAP = new Map(EMPTY_BB, 0, 0); + private static final Map EMPTY_MAP = new Map(EMPTY_BB, 1, 1); Map(ByteBuffer bb, int end, int byteWidth) { super(bb, end, byteWidth); @@ -899,7 +899,7 @@ public class FlexBuffers { */ public static class Vector extends Sized { - private static final Vector EMPTY_VECTOR = new Vector(ByteBuffer.allocate(0), 1, 1); + private static final Vector EMPTY_VECTOR = new Vector(EMPTY_BB, 1, 1); Vector(ByteBuffer bb, int end, int byteWidth) { super(bb, end, byteWidth); @@ -960,7 +960,7 @@ public class FlexBuffers { */ public static class TypedVector extends Vector { - private static final TypedVector EMPTY_VECTOR = new TypedVector(EMPTY_BB, 0, 1, FBT_INT); + private static final TypedVector EMPTY_VECTOR = new TypedVector(EMPTY_BB, 1, 1, FBT_INT); private final int elemType; |