poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 63242] New: NullPointerException when trying to write a boxed Integer null value to a cell using setCellValue due to automatic unboxing
Date Thu, 07 Mar 2019 14:59:52 GMT
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: dev@poi.apache.org
          Reporter: remco.siemonsma@gmail.com
  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: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message