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

            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;

    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);
                    if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
                        boolean isDate =
                        if (idxCell > 0 && isDate) {
                            System.out.println("cell " + idxCell + " is not a
        catch (Exception e) {

Make another copy of the attached file - "file_2.xls" and run the code to
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

View raw message