Skip to content

bug: IntegerSchema returns null for negative values for some locales - #4178

Closed
jhannes wants to merge 3 commits into
swagger-api:masterfrom
jhannes:patch-1
Closed

jhannes wants to merge 3 commits into
swagger-api:masterfrom
jhannes:patch-1

Conversation

@jhannes

@jhannes jhannes commented May 12, 2022

Copy link
Copy Markdown
Contributor

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

* 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)
jhannes added a commit to jhannes/openapi-generator-java-annotationfree that referenced this pull request May 12, 2022
* Changed infectionTracker.json to allow for reproduction of swagger-api/swagger-core#4178
@jhannes jhannes changed the title Avoid locale-dependent NumberFormat in IntegerSchema bug: IntegerSchema returns null for negative values for some locales Jul 21, 2022
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant