Bug 63303 - java.io.IOException: java.lang.NoSuchMethodException: org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(java.io.File)
Summary: java.io.IOException: java.lang.NoSuchMethodException: org.apache.poi.xssf.use...
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 4.0.x-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-30 17:46 UTC by zengxh
Modified: 2019-04-04 19:26 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description zengxh 2019-03-30 17:46:43 UTC
(WorkbookFactory/create java.io.File) will cause this

java.io.IOException: java.lang.NoSuchMethodException: org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(java.io.File)
                     WorkbookFactory.java:354 org.apache.poi.ss.usermodel.WorkbookFactory.createWorkbook
                     WorkbookFactory.java:314 org.apache.poi.ss.usermodel.WorkbookFactory.createXSSFWorkbook
                     WorkbookFactory.java:173 org.apache.poi.ss.usermodel.WorkbookFactory.create
Comment 1 Dominik Stadler 2019-03-31 19:54:44 UTC
Sounds like you are running with different versions of Apache POI somehow, either there is a difference between compile-time and run-time or you have mixed versions of the various poi-jars. 

Please check your setup.

If you think this is really caused by Apache POI, please provide some test-project which allows to reproduce this as there is no way to reproduce this for now.
Comment 2 zengxh 2019-04-03 04:39:29 UTC
https://poi.apache.org/apidocs/dev/org/apache/poi/xssf/usermodel/XSSFWorkbookFactory.html

Is this method createWorkbook(java.io.File) missing?
Only see this createWorkbook(java.io.File, boolean)
Comment 3 Greg Woolsey 2019-04-03 12:01:29 UTC
That method only exists in the parent class,

org.apache.poi.ss.usermodel.WorkbookFactory

From the source you can see that it defaults to readOnly=false when calling 

org.apache.poi.xssf.usermodel.XSSFWorkbookFactory

Further,

org.apache.poi.xssf.usermodel.XSSFWorkbookFactory

has never implemented the method

createWorkbook(File), only ever inheriting that method from WorkbookFactory.

It's all there in the source and SVN history if you care to investigate. 

As Dominik said above, it sounds like your classpath has multiple different POI JAR files in it.  This kind of runtime only error is almost always due to stale JARs in the classpath and/or differences between compile and run class loading - e.g. IDE configuration vs deployment server/container configuration.
Comment 4 zengxh 2019-04-03 14:25:49 UTC
Yeah how silly I was. I should have looked into the parent class.

poi 4.0.1 was the only library pulled from maven. This is the only thing I'm sure of: there was no library version issue. I check my .m2 folder and it's the same verdict.

I'm not able to reproduce the issue I guess we'll leave it there. Sorry about this bug report.
Comment 5 zengxh 2019-04-04 16:10:53 UTC
This is still an issue.
Comment 6 zengxh 2019-04-04 16:14:55 UTC
According to the source https://svn.apache.org/repos/asf/poi/trunk/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java

In method createWorkbook(String, Object[]) it will try to look for org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(java.io.File, Boolean). When the method is not found it's not found exception is thrown https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getMethod-java.lang.String-java.lang.Class...-


    private static Workbook createXSSFWorkbook(Object... args) throws IOException, EncryptedDocumentException {
        return createWorkbook("org.apache.poi.xssf.usermodel.XSSFWorkbookFactory", args);
    }

    /**
     * Does the actual call to HSSF or XSSF to do the creation.
     * Uses reflection, so that this class can be in the Core non-OOXML
     *  POI jar without errors / broken references to the OOXML / XSSF code.
     */
    private static Workbook createWorkbook(String factoryClass, Object[] args) throws IOException, EncryptedDocumentException {
        try {
            Class<?> clazz = WorkbookFactory.class.getClassLoader().loadClass(factoryClass);
            Class<?>[] argsClz = new Class<?>[args.length];
            int i=0;
            for (Object o : args) {
                Class<?> c = o.getClass();
                if (Boolean.class.isAssignableFrom(c)) {
                    c = boolean.class;
                } else if (InputStream.class.isAssignableFrom(c)) {
                    c = InputStream.class;
                } else if (File.class.isAssignableFrom(c)) {
                    c = File.class;
                }
                argsClz[i++] = c;
            }
            Method m = clazz.getMethod("createWorkbook", argsClz);
            return (Workbook)m.invoke(null, args);
Comment 7 Dominik Stadler 2019-04-04 18:27:27 UTC
It seems you are trying to call the WorkbookFactory.create() with a "File" object, which is not supported. There is currently a method create(Object), which you can call with any object, but only "OPCPackage" is supported according to it's javadoc description. 

Also this method is scheduled to be removed in one of the next releases.

Please show the code that you use to invoke the WorkbookFactory.
Comment 8 Dominik Stadler 2019-04-04 18:31:41 UTC
Change 1832358 in Bug #62355 seems related, we changed interface from OPCPackage to Object for one method in order to support Java 11 properly, however this seems to break cases where you now try to provide a "File" as "Object" somehow in the parameters and thus the wrong method is selected for execution.

We have tests that create(File) still works as expected, so something in your code seems to trigger this and so it most likely will need some modification there to be fixed.
Comment 9 zengxh 2019-04-04 19:15:42 UTC
I am using Clojure interop I call it essentially this way:

(WorkbookFactory/create java.io.File) which gives this

java.io.IOException: java.lang.NoSuchMethodException: org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(java.io.File)
                     WorkbookFactory.java:354 org.apache.poi.ss.usermodel.WorkbookFactory.createWorkbook
                     WorkbookFactory.java:314 org.apache.poi.ss.usermodel.WorkbookFactory.createXSSFWorkbook
                     WorkbookFactory.java:173 org.apache.poi.ss.usermodel.WorkbookFactory.create


here's the signature:
https://poi.apache.org/apidocs/dev/org/apache/poi/ss/usermodel/WorkbookFactory.html#create-java.io.File-

examples here "Files vs InputStreams" section:
https://poi.apache.org/components/spreadsheet/quick-guide.html

perhaps a .xlsx file will trigger this according to source code and stacktrace.
Comment 10 zengxh 2019-04-04 19:21:05 UTC
Perhaps i was calling create(java.lang.Object pkg) method as you point out? Let me try to give it a type hint.
Comment 11 zengxh 2019-04-04 19:26:22 UTC
that's exactly the case.... i'm sorry.... i was doing a file upload in clojure ring.

this fails
(let [file  (:tempfile req)
;;          wb    (XSSFWorkbookFactory/createWorkbook file false)
          wb    (WorkbookFactory/create file)

this works
(let [file  (:tempfile req)
;;          wb    (XSSFWorkbookFactory/createWorkbook file false)
          wb    (WorkbookFactory/create ^java.io.File file)