hjson-java
hjson-java copied to clipboard
JsonValue.valueOf( float / double ) should check NaN and ±Infinite values
Otherwise
JsonValue.valueOf( Math.log(-1)).toString();
will throw up a NumberFormatException
like a drunken sailor, because inside JsonNumber.toString()
the called function BigDecimal.valueOf()
doesn't really like non-finite values.
Adding this,
if (Double.isNaN(value) || Double.isInfinite(value)) {
return Double.toString(value);
}
under line 41, would help prevent throwing a NumberFormatException
, as it skips BigDecimal.valueOf()
, and just returns its own value.
Sorry for the very late response.
I'll have a look at improving documentation instead of changing this behavior. Reasons:
- Existing apps might depend on hjson-java throwing an error instead of outputting
Inf
orNaN
. - The Hjson specification does not consider
Inf
orNaN
to be valid representations for numbers (https://hjson.github.io/syntax.html) - The JSON specification does not consider
Inf
orNaN
to be valid representations for numbers, soJsonWriter
should still throw an error for them.