arangodb/java-velocypack

VPackBuilder builds invalid unindexed single (small) value array

CuriusAlgo opened this issue · 1 comments

Consider the following (kotlin) code, using java-velocypack 2.2.1:

val slice = with(VPackBuilder(object : VPackBuilder.BuilderOptions {
	override fun isBuildUnindexedArrays() = true
	override fun isBuildUnindexedObjects() = true

	override fun setBuildUnindexedArrays(buildUnindexedArrays : Boolean) = throw NotImplementedError()
	override fun setBuildUnindexedObjects(buildUnindexedObjects : Boolean) = throw NotImplementedError()
}))
{
	add(ValueType.ARRAY)
	add(1)
	close()
	slice()
}

println(slice)
println(slice.toByteArray().toList())

Expected output would be (note that the byte values are base 10):

[1]
[19, 4, 49, 1]

Actual output is:

["(non-representable type)"]
[19, 4, 0, 1]

The output is as expected (albeit with a larger byte array) when isBuildUnindexedArrays() = false. The output is also as expected when not using small integer values.

The VPackBuilder seems to write the 1 correctly as 49 into its buffer, but fails to copy it to the correct position in VPackBuilder::closeCompactArrayOrObject.

I created this PR #25 that should solve the problem.
Feel free to review or add comments to it.