poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 56563] New: Multithreading bug when reading 2 similar files
Date Mon, 26 May 2014 07:54:00 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=56563

            Bug ID: 56563
           Summary: Multithreading bug when reading 2 similar files
           Product: POI
           Version: 3.10
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: HSSF
          Assignee: dev@poi.apache.org
          Reporter: urishe@gmail.com

Created attachment 31660
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=31660&action=edit
A file for which the problem reproduces

When reading two copies of the same file (doesn't necessarily need to be the
exact same file, but do need to contain the same styles or something along
those lines),
from two threads simultaneously (each thread processes its own file), the
format string of cell styles get mixed up.

The following code demonstrates this, printing to System.out every time a non
date cell is mistakenly recognized as date. Note that starting only one of the
threads yields no System.out messages.

public class CellFormatBugExample implements Runnable {

    public static void main(String[] args) {
        new Thread(new CellFormatBugExample("C:/temp/file_1.xls")).start();
        new Thread(new CellFormatBugExample("C:/temp/file_2.xls")).start();
    }

    String filePath;

    public CellFormatBugExample(String filePath) {
        this.filePath = filePath;
    }

    @Override
    public void run() {

        File inputFile = new File(filePath);
        try (FileInputStream stream = new FileInputStream(inputFile)) {

            Workbook wb = WorkbookFactory.create(stream);
            Sheet sheet = wb.getSheetAt(0);

            for (Row row : sheet) {
                for (Integer idxCell = 0; idxCell < row.getLastCellNum();
idxCell++) {

                    Cell cell = row.getCell(idxCell);
                    cell.getCellStyle().getDataFormatString();
                    if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
                        boolean isDate =
HSSFDateUtil.isCellDateFormatted(cell);
                        if (idxCell > 0 && isDate) {
                            System.out.println("cell " + idxCell + " is not a
date!");
                        }
                    }
                }
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Make another copy of the attached file - "file_2.xls" and run the code to
reproduce.
Digging around a bit, seems the cause for this is a caching bug in the
HSSFCellStyle.getDataFormatString() method.
As far as I could understand a simple resolution would be to synchronize access
to that method.

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