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 2013/03/01 04:18:12 UTC

[Bug 54625] New: User defined functions added to static variable

https://issues.apache.org/bugzilla/show_bug.cgi?id=54625

            Bug ID: 54625
           Summary: User defined functions added to static variable
           Product: POI
           Version: 3.9
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HSSF
          Assignee: dev@poi.apache.org
          Reporter: stuart.donald@ibboost.com
    Classification: Unclassified

When registering a new User defined function as described here:

http://poi.apache.org/spreadsheet/user-defined-functions.html

In the case of the HSSF workbook

doing this:

workbook.addToolPack(udfToolpack);

adds the udfToolpack to a static variable. 

At the very least this could cause a bit of a memory leak, and in my case when
dealing with multiple workbooks in a single process, that have different
implementations for a particular UDF name, this statefulness means that the
first one registered is the one that always gets used.

I suggest changing this

private UDFFinder _udfFinder = UDFFinder.DEFAULT;

to this

private IndexedUDFFinder _udfFinder = new IndexedUDFFinder(UDFFinder.DEFAULT);

in org.apache.poi.hssf.usermodel.HSSFWorkbook

In the meantime, a suitable workaround for this issue is to create your own
implementation of a workbook factory, and when you create a HSSFWorkbook, use
reflection to set the appropriate value to the _udfFinder private variable.

-- 
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 54625] User defined functions added to static variable

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

stuart <st...@ibboost.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

--- Comment #1 from stuart <st...@ibboost.com> ---
If anybody needs it, here is the workaround that I use

public class POIWorkbookFactory {

    public static Workbook create(InputStream inp) throws Exception {
        Workbook workbook = WorkbookFactory.create(inp);
        if (workbook instanceof HSSFWorkbook) {
            Field field = HSSFWorkbook.class.getDeclaredField("_udfFinder");
            field.setAccessible(true);
            field.set(workbook, new IndexedUDFFinder(UDFFinder.DEFAULT));
        }
        return workbook;
    }

}

-- 
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 54625] User defined functions added to static variable

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

Yegor Kozlov <ye...@dinom.ru> changed:

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

--- Comment #2 from Yegor Kozlov <ye...@dinom.ru> ---
Fix applied in r1452060

I had to move IndexedUDFFinder to the common package
org.apache.poi.ss.formula.udf, otherwise HSSF did not compile. 

Regards,
Yegor

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