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/10/17 14:04:10 UTC

[Bug 62831] New: WorkbookFactory.create() doesn't work for File subclasses

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

            Bug ID: 62831
           Summary: WorkbookFactory.create() doesn't work for File
                    subclasses
           Product: POI
           Version: 4.0.0-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: SS Common
          Assignee: dev@poi.apache.org
          Reporter: maarten_coene@yahoo.com
  Target Milestone: ---

Hi,

If you pass a File subclass to the
org.apache.poi.ss.usermodel.WorkbookFactory.create() method, a
NoSuchMethodException is thrown.

For instance:
OK: WorkbookFactory.create(new File("C:\\temp\\test.xlsx"));
ERROR: WorkbookFactory.create(new File("C:\\temp\\test.xlsx") {});

Stacktrace:
Exception in thread "main" java.io.IOException:
java.lang.NoSuchMethodException:
org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(uz.POITest$1,
boolean)
        at
org.apache.poi.ss.usermodel.WorkbookFactory.createWorkbook(WorkbookFactory.java:329)
        at
org.apache.poi.ss.usermodel.WorkbookFactory.createXSSFWorkbook(WorkbookFactory.java:296)
        at
org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:284)
        at
org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:253)
        at
org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:234)
        at uz.POITest.main(POITest.java:67)
Caused by: java.lang.NoSuchMethodException:
org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(uz.POITest$1,
boolean)
        at java.lang.Class.getMethod(Class.java:1786)
        at
org.apache.poi.ss.usermodel.WorkbookFactory.createWorkbook(WorkbookFactory.java:313)
        ... 5 more


The reason is that reflection is used within the WorkbookFactory class to find
the correct createWorkbook method. This fails for subclasses of java.io.File.

A concrete use-case is the JFileChooser which (on Windows) returns subclasses
of java.io.File when you select a file by double-clicking on it.

Maarten

-- 
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 62831] WorkbookFactory.create() doesn't work for File subclasses

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

Nick Burch <ap...@gagravarr.org> changed:

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

--- Comment #1 from Nick Burch <ap...@gagravarr.org> ---
Fixed in r1844116, thanks for tracking this one down!

-- 
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 62831] WorkbookFactory.create() doesn't work for File subclasses

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

--- Comment #2 from Maarten Coene <ma...@yahoo.com> ---
Thanks for the very fast reply and fix! :-D

Maarten

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