swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

bug: IntegerSchema returns `null` for negative values for some locales

Open jhannes opened this issue 3 years ago • 0 comments

NumberFormat.getInstance().parse(Integer.toString(-1)) always throws exception in the following locales: ar· ·ckb· ·he· ·ks· ·pa_Arab· ·ur· ·fa· ·ps· ·uz_Arab· ·eo· ·et· ·fi· ·fo· ·gsw· ·ksh· ·lt· ·nb· ·nn· ·rm· ·se· ·sv· (see https://bugs.openjdk.java.net/browse/JDK-8189097)

To see this in action, try running the following code:

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;

public class NumberFormatIsBroken {
    public static void main(String[] args) throws ParseException {
        Locale.setDefault(new Locale("no"));
        NumberFormat.getInstance().parse(Long.toString(-1));
    }
}

In addition to using Long.parseLong which doesn't have this locale-problem, I propose getting rid of the try/catch block as the statement Long.parseLong(value.toString()) should never throw

jhannes avatar May 12 '22 09:05 jhannes