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: [email protected]
          Reporter: [email protected]
  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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to