agrison / jtoml

TOML for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing a String into Toml.serialize("test",string) will cause a loop

dredhorse opened this issue · comments

If you pass a String directly into Toml.serialize with a root key it will cause a loop.

Here a test log.

20:23:05] [INFO] [TCBase] [DEBUG] buffer [[test]
]
[20:23:05] [INFO] [TCBase] [DEBUG] fields [7]
[20:23:05] [INFO] [TCBase] [DEBUG] field [value]
[20:23:05] [INFO] [TCBase] [DEBUG] type [[C]
[20:23:05] [INFO] [TCBase] [DEBUG] value [[C@7cbc11d]
[20:23:05] [INFO] [TCBase] [DEBUG] buffer [[test.value]
]
[20:23:05] [INFO] [TCBase] [DEBUG] fields [0]
[20:23:05] [INFO] [TCBase] [DEBUG] field [hash]
[20:23:05] [INFO] [TCBase] [DEBUG] type [int]
[20:23:05] [INFO] [TCBase] [DEBUG] value [0]
[20:23:05] [INFO] [TCBase] [DEBUG] buffer [[test.value.hash]
]
[20:23:05] [INFO] [TCBase] [DEBUG] fields [11]
[20:23:05] [INFO] [TCBase] [DEBUG] field [MIN_VALUE]
[20:23:05] [INFO] [TCBase] [DEBUG] type [int]
[20:23:05] [INFO] [TCBase] [DEBUG] value [-2147483648]
[20:23:05] [INFO] [TCBase] [DEBUG] buffer [[test.value.hash.MIN_VALUE]

Hi,

could you consider posting the Java code also.

Thank you ;-)

any String test = "test" will do.

just put that into Toml.serialize("looptest",test);

and you will get the test...

the log above is from some testing I have done inside a plugin for spout... that is alpha code and highly dynamic.. the logging isn't in the code even anymore. I would need to look into the code to find the location for the log again.

This is due to a recursion on members of the String class. It gets field by field (sorted by some comparator defined in Toml's Util.Reflection) and as it walks onto primitive fields like int it does enumerate all its fields on and on again.
I have fixed it by including int.class and so on in the TOML_SUPPORTED, now the result of Toml.serialize("looptest", "hello"); will be something like the following:

[looptest]
value = "hello"
hash = 0
serialVersionUID = -6849794470754667710
HASHING_SEED = 1151878548
hash32 = 0

[looptest.serialPersistentFields]

[looptest.CASE_INSENSITIVE_ORDER]
serialVersionUID = 8575799808933029326

thanks