You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2016/02/09 09:14:03 UTC

[Bug 57034] NullPointerException in autoSizeColumn

https://bz.apache.org/bugzilla/show_bug.cgi?id=57034

--- Comment #2 from Worsik <wo...@email.cz> ---
Still valid on 3.11-Final

I think that NPE should be prevented when autosizing column and value should be
treated as empty string.

Code of SheetUtil.java

        if (cellType == Cell.CELL_TYPE_STRING) {
            RichTextString rt = cell.getRichStringCellValue();
!!!         String[] lines = rt.getString().split("\\n");      !!! this is
wrong !!!
            for (int i = 0; i < lines.length; i++) {
                String txt = lines[i] + defaultChar;

                AttributedString str = new AttributedString(txt);
                copyAttributes(font, str, 0, txt.length());

                if (rt.numFormattingRuns() > 0) {
                    // TODO: support rich text fragments
                }

                width = getCellWidth(defaultCharWidth, colspan, style, width,
str);
            }
        }

It could be a benefit if we can set how to treat NULL values when setting Cell
values. For me, it would be better to accept NULL value as empty string (maybe
based on some parameter). When exporting list of objects to Excel via POI, it
is quite annoying to handle all getters like 

        object.getValue() == null ? "" : object.getValue();

-- 
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