Search before asking
Fesod version
main
JDK version
any
Operating system
Linux
Steps To Reproduce
@Getter
@Setter
public static class Row {
@ExcelProperty(index = 0)
private Integer phone;
}
File file = new File("overflow.xlsx");
FesodSheet.write(file).sheet()
.doWrite(Collections.singletonList(Collections.singletonList(13800138000L)));
List<Row> rows = FesodSheet.read(file).head(Row.class).headRowNumber(0).sheet().doReadSync();
System.out.println(rows.get(0).getPhone());
Current Behavior
The read succeeds and prints 915236112 (that is 13800138000 mod 2^32). No exception, no warning.
Other integer types wrap the same way. The wrong value is returned in XLSX, XLS and CSV, for number cells and text cells alike:
| Field type |
Cell value |
Read back |
Integer |
13800138000 |
915236112 |
Short |
40000 |
-25536 |
Byte |
"300" |
44 |
Long |
Long.MAX_VALUE (XLSX/XLS, stored as a double) |
-9223372036854771616 |
Expected Behavior
An out-of-range value should throw ArithmeticException.
Anything else?
intValueExact() alone isn't enough because it also rejects any fraction.
The fix is to check the value against the type's range with BigDecimal.compareTo before narrowing and throw in the worst case.
Are you willing to submit a PR?
Search before asking
Fesod version
main
JDK version
any
Operating system
Linux
Steps To Reproduce
Current Behavior
The read succeeds and prints
915236112(that is13800138000 mod 2^32). No exception, no warning.Other integer types wrap the same way. The wrong value is returned in XLSX, XLS and CSV, for number cells and text cells alike:
Integer13800138000915236112Short40000-25536Byte"300"44LongLong.MAX_VALUE(XLSX/XLS, stored as a double)-9223372036854771616Expected Behavior
An out-of-range value should throw
ArithmeticException.Anything else?
intValueExact()alone isn't enough because it also rejects any fraction.The fix is to check the value against the type's range with
BigDecimal.compareTobefore narrowing and throw in the worst case.Are you willing to submit a PR?