https://bz.apache.org/bugzilla/show_bug.cgi?id=63242
Bug ID: 63242
Summary: NullPointerException when trying to write a boxed
Integer null value to a cell using setCellValue due to
automatic unboxing
Product: POI
Version: 4.0.0-FINAL
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: XSSF
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
Test code below leads to a NPE during runtime due to the way the Java compiler
handles unboxing during compilation/linking.
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Main {
public static void main(String[] args) throws Exception {
Integer nullint = null;
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Sheet");
XSSFRow row = sheet.createRow(0);
XSSFCell nullCell = row.createCell(0);
nullCell.setCellValue(nullint);
}
}
Since the XSSFCell does not provide a method which accepts boxed values, or an
Object, the Java compiler decides the "setCellValue(double value)" method is
the best method to link to. At runtime the JVM tries to unbox the null Integer,
or any other numeric value, and throws an NPE.
Currently, a workaround can be done by first manually checking whether the
value being written is null before the call to setCellValue, but this should
not be needed.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]