Например, в следующей программе:
Код: Выделить всё
public static Number createNumber(final String str) throws NumberFormatException {
if (str == null) {
return null;
}
if (StringUtils.isBlank(str)) {
throw new NumberFormatException("A blank string is not a valid number");
}
final String[] hex_prefixes = {"0x", "0X", "-0x", "-0X", "#", "-#"};
int pfxLen = 0;
for(final String pfx : hex_prefixes) {
if (str.startsWith(pfx)) {
pfxLen += pfx.length();
break;
}
}
if (pfxLen > 0) { // we have a hex number
final int hexDigits = str.length() - pfxLen;
if (hexDigits > 16) {
return createBigInteger(str);
}
if (hexDigits > 8) {
return createLong(str);
}
return createInteger(str); // this line would throw out an exception
}
...
}
Код: Выделить всё
createIntegerТо, что я хочу, выглядит следующим образом:
expected_jacoco_report_of_a_failed_program
Я пытался окружить код с try/catch, как показано ниже, но результат не изменился.
Код: Выделить всё
try {
NumberUtils.createNumber("0x80000000"));
} catch (Exception e) {
System.out.println("Error: " + e);
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... would-fail
Мобильная версия