673 if (firstChar < '0') { // Possible leading "+" or "-" |
673 if (firstChar < '0') { // Possible leading "+" or "-" |
674 if (firstChar == '-') { |
674 if (firstChar == '-') { |
675 negative = true; |
675 negative = true; |
676 limit = Long.MIN_VALUE; |
676 limit = Long.MIN_VALUE; |
677 } else if (firstChar != '+') { |
677 } else if (firstChar != '+') { |
678 throw NumberFormatException.forInputString(s); |
678 throw NumberFormatException.forInputString(s, radix); |
679 } |
679 } |
680 |
680 |
681 if (len == 1) { // Cannot have lone "+" or "-" |
681 if (len == 1) { // Cannot have lone "+" or "-" |
682 throw NumberFormatException.forInputString(s); |
682 throw NumberFormatException.forInputString(s, radix); |
683 } |
683 } |
684 i++; |
684 i++; |
685 } |
685 } |
686 long multmin = limit / radix; |
686 long multmin = limit / radix; |
687 long result = 0; |
687 long result = 0; |
688 while (i < len) { |
688 while (i < len) { |
689 // Accumulating negatively avoids surprises near MAX_VALUE |
689 // Accumulating negatively avoids surprises near MAX_VALUE |
690 int digit = Character.digit(s.charAt(i++),radix); |
690 int digit = Character.digit(s.charAt(i++),radix); |
691 if (digit < 0 || result < multmin) { |
691 if (digit < 0 || result < multmin) { |
692 throw NumberFormatException.forInputString(s); |
692 throw NumberFormatException.forInputString(s, radix); |
693 } |
693 } |
694 result *= radix; |
694 result *= radix; |
695 if (result < limit + digit) { |
695 if (result < limit + digit) { |
696 throw NumberFormatException.forInputString(s); |
696 throw NumberFormatException.forInputString(s, radix); |
697 } |
697 } |
698 result -= digit; |
698 result -= digit; |
699 } |
699 } |
700 return negative ? result : -result; |
700 return negative ? result : -result; |
701 } else { |
701 } else { |
702 throw NumberFormatException.forInputString(s); |
702 throw NumberFormatException.forInputString(s, radix); |
703 } |
703 } |
704 } |
704 } |
705 |
705 |
706 /** |
706 /** |
707 * Parses the {@link CharSequence} argument as a signed {@code long} in |
707 * Parses the {@link CharSequence} argument as a signed {@code long} in |