opensagres / xdocreport

XDocReport means XML Document reporting. It's Java API to merge XML document created with MS Office (docx) or OpenOffice (odt), LibreOffice (odt) with a Java model to generate report and convert it if you need to another format (PDF, XHTML...).
https://github.com/opensagres/xdocreport
1.19k stars 368 forks source link

NullPointerException for getText method of ListItemContext class #637

Closed Xiaoshu-Zhao closed 4 months ago

Xiaoshu-Zhao commented 4 months ago

getText's code is following:

public String getText() {
        String text = this.lvl.getLvlText().getVal();
        CTNumFmt numFmt = this.lvl.getNumFmt();
        if (!STNumberFormat.BULLET.equals(numFmt)) {
            List<String> numbers = new ArrayList();

            for (ListItemContext item = this; !item.isRoot(); item = item.getParent()) {
                numbers.add(0, item.getNumberText());
            }

            String num = null;

            for (int i = 0; i < numbers.size(); ++i) {
                if (numbers.get(i) instanceof String) {
                    num = (String) numbers.get(i);
                }
                text = StringUtils.replaceAll(text, "%" + (i + 1), num);
            }
        }

        return text;
    }

String text = this.lvl.getLvlText().getVal(); may occur NullPointerException because this.lvl.getLvlText() can be null. I suggest add following code at beginning to avoid NullPointerException.

if (this.lvl == null || this.lvl.getLvlText() == null) {
    return "";
}
angelozerr commented 4 months ago

Please create a PR to apply your fix.

Xiaoshu-Zhao commented 4 months ago

Hi, I just create a pr, let me know if there is anything I need to do to get it approve. It is my first time to create a pr for open source repo lol.

Adriansun commented 3 months ago

Will this fix be released soon? A version 2.0.5 with a fix for the PDF problem, which seem to be the same problem that this one fix, would be great.