NumberFormatException in real number

I see this all the time in my journals, however, as far as I know, the script should be impossible.

java.lang.NumberFormatException: For input string: "1487832810"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.7.0_80]
        at java.lang.Long.parseLong(Long.java:430) ~[na:1.7.0_80]
        at java.lang.Long.parseLong(Long.java:483) ~[na:1.7.0_80]

here (I think) the corresponding source code (line numbers correspond to ST)

424:    char firstChar = s.charAt(0);
425:    if (firstChar < '0') { // Possible leading "+" or "-"
426:        if (firstChar == '-') {
427:            negative = true;
428:            limit = Long.MIN_VALUE;
429:        } else if (firstChar != '+')
430:            throw NumberFormatException.forInputString(s);

So he thinks the first char ( 1) is < '0'??

I can only assume that this is some kind of character encoding problem or something like that.

Any ideas?

+4
source share
1 answer

I think this is because there are non-printable characters in your string. All non-printable characters < '0'. You can see which of them can be printed and which are not:

http://web.itu.edu.tr/sgunduz/courses/mikroisl/ascii.html

, .

, , , if . , SO , :

Java

Unicode Java?

+2

Source: https://habr.com/ru/post/1670901/


All Articles