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 2018/03/13 14:15:44 UTC

[Bug 62176] New: DefaultTempFileCreationStrategy is not thread-safe

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

            Bug ID: 62176
           Summary: DefaultTempFileCreationStrategy is not thread-safe
           Product: POI
           Version: 3.17-FINAL
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: POI Overall
          Assignee: dev@poi.apache.org
          Reporter: fabien@chebel.fr
  Target Milestone: ---

Whe using Apache POI, a single instance of DefaultTempFileCreationStrategy is
created and used by the org.apache.poi.util.TempFile static class.

This means that this component is shared by the whole Java application in which
POI is used.

Assuming an application is processing two Excel files in parallel via Apache
POI, it will end up calling
DefaultTempFileCreationStrategy#createTempDirectory(java.io.File) in order to
create the '/tmp/poifiles' directory (default name on Linux system).

This code will then be run:

private void createTempDirectory(File directory) throws IOException {
    // create directory if it doesn't exist
    final boolean dirExists = (directory.exists() || directory.mkdirs());

    // snip
}

Let's say this method is being called at the same time in the same JVM by
thread A and thread B

1) Thread A and Thread B execute directory.exists(). Both calls return 'false'
as the directory does not exist yet

2) Thread A and Thread B start executing directory.mkdirs() up until the part
where the directory existence is checked

3) Thread A creates the directory first: mkdirs() returns true. Thread B fails
to create the directory and mkdirs() returns false.

4) An IOException will be thrown in Thread B


To make this method Thread-safe, a synchronized block could be added to the
method, with a lock on the whole class.

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


[Bug 62176] DefaultTempFileCreationStrategy is not thread-safe

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=62176

PJ Fanning <fa...@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #1 from PJ Fanning <fa...@yahoo.com> ---
Change merged using
https://svn.apache.org/viewvc?view=revision&revision=1826655

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


[Bug 62176] DefaultTempFileCreationStrategy is not thread-safe

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=62176

Fabien Chebel <fa...@chebel.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fabien@chebel.fr

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