From 4c954181cdfbd88d95e37d734cbd4961e54b8afc Mon Sep 17 00:00:00 2001 From: Paulo Pinheiro Date: Fri, 2 Sep 2022 07:04:18 +0200 Subject: [PATCH] [Java][FlexBuffers] throwing exception for untyped fixed vectors (#7507) Untyped fixed vectors are not supported in FlexBuffers. There was an assert to check for it, but on java, asserts are optional. This change converts the assertion into a runtime exception. Fixes #7358 Co-authored-by: Derek Bailey --- java/com/google/flatbuffers/FlexBuffersBuilder.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/java/com/google/flatbuffers/FlexBuffersBuilder.java b/java/com/google/flatbuffers/FlexBuffersBuilder.java index 08ed72f42..6b0cf43a5 100644 --- a/java/com/google/flatbuffers/FlexBuffersBuilder.java +++ b/java/com/google/flatbuffers/FlexBuffersBuilder.java @@ -502,7 +502,9 @@ public class FlexBuffersBuilder { * @return Value representing the created vector */ private Value createVector(int key, int start, int length, boolean typed, boolean fixed, Value keys) { - assert (!fixed || typed); // typed=false, fixed=true combination is not supported. + if (fixed & !typed) + throw new UnsupportedOperationException("Untyped fixed vector is not supported"); + // Figure out smallest bit width we can store this vector with. int bitWidth = Math.max(WIDTH_8, widthUInBits(length)); int prefixElems = 1;