Ken Hu created TINKERPOP-3277:
---------------------------------
Summary: gremlin-go can't serialize zero in bigdecimal/biginteger
Key: TINKERPOP-3277
URL: https://issues.apache.org/jira/browse/TINKERPOP-3277
Project: TinkerPop
Issue Type: Bug
Components: go
Affects Versions: 3.8.1, 3.7.6
Reporter: Ken Hu
Caveat: I haven't fully verified this, just something AI told me when I was
writing the "model" tests for gremlin-go. Just putting here so it can be
checked later.
Gremlin-Go serializes zero BigInteger as a GraphBinary length of 0 with no
bytes. Java expects a valid two’s-complement BigInteger byte array, where zero
is encoded as length 1 with byte 0x00. When Java reads Go’s zero-length form,
new BigInteger(new byte[0]) throws NumberFormatException, so Java servers
cannot read zero BigInteger values sent by Go.
The same affects BigDecimal when its unscaled value is zero, because that
unscaled value is serialized as a BigInteger.
{code:java}
func TestZeroBigIntegerGraphBinaryV1Bytes(t *testing.T) {
var buffer bytes.Buffer
got, err := bigIntWriter(*big.NewInt(0), &buffer, nil)
if err != nil {
t.Fatal(err)
}
want := []byte{0x00, 0x00, 0x00, 0x01, 0x00}
if !bytes.Equal(got, want) {
t.Fatalf("zero BigInteger bytes = % x, want % x", got, want)
}
}
Current output:
00 00 00 00
Expected output:
00 00 00 01 00
{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)