Closed TBlueF closed 3 years ago
The same seems to happen using the GsonConfigurationLoader
(using org.spongepowered:configurate-gson:4.1.1
)
I tracked this issue down to be probably caused by this method returning false
if the tested double is exactly 0.0
.
Replacing:
if (!Double.isFinite(test)) { // NaN, ±inf
with something like:
if (test == 0.0 || !Double.isFinite(test)) { // zero, NaN, ±inf
should fix this :)
If you want, i can create a pull-request with this fix, but you'll be probably faster if you do it yourself :)
Might want to stick a check in there for -0.0
too, although isFinite
is doing Math.abs(d) <= Double.MAX_VALUE
so I'm not sure why this would fail on zero to begin with. Did you try this suggested fix at all?
@amaranth
Yes, i tested it successfully.
Double.isFinite(test)
is negated (!Double.isFinite(test)
) in that if-statement, so the extra check for 0
is needed :)
I'm sorry it's taken a while to get to this issue, but it will be fixed in the release of 4.1.2
, available in 4.1.2-SNAPSHOT
dev builds within the next few minutes.
Version
Description
Given: A (hocon) configuration-file node has its value explicitly set to
0
. It got loaded using aHoconConfigurationLoader
. The value is retrieved as a float using a getter with a default-fallback argument (e.g.node.getFloat(1f)
)Then: That getter returns the default/fallback-value. (e.g.
1f
)Expected result: That getter returns the explicitly set value:
0f
Extra info: This only happens with
float
values. This only happens if the node got loaded from a config-file. I only tested the HOCON-loader.Code Example
The console output of the above code:
The contents of the
testFile.conf
(after execution):