Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider com.bea.xml.stream.EventFactory not found #8

Closed
kurthuwig opened this issue Feb 11, 2017 · 21 comments
Closed

Provider com.bea.xml.stream.EventFactory not found #8

kurthuwig opened this issue Feb 11, 2017 · 21 comments

Comments

@kurthuwig
Copy link

I try to read an xlsx file from an InputStream

            workbook = new XSSFWorkbook(is);

which yields

org.apache.poi.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.EventFactory not found
     at org.apache.poi.javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
     at org.apache.poi.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:178)
     at org.apache.poi.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
     at org.apache.poi.javax.xml.stream.XMLEventFactory.newInstance(XMLEventFactory.java:30)
     at org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(PackagePropertiesMarshaller.java:41)
     at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:161)
     at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141)
     at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:96)
     at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:342)
     at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
     at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:285)
@centic9
Copy link
Owner

centic9 commented Feb 17, 2017

Not sure where the com.bea... part comes from, looks like some other XML parser is found via some service-files in other packaged jars, presumably from some other library that you package into your Android app.

What other dependencies do you have?

@BaN4NaJ0e
Copy link

BaN4NaJ0e commented Feb 22, 2017

I am running into exactly the same problem. Here are my dependencies:

dependencies {
apt 'com.google.dagger:dagger-compiler:2.9'
apt "com.github.Raizlabs.DBFlow:dbflow-processor:4.0.0-beta5"
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.github.Raizlabs.DBFlow:dbflow-core:4.0.0-beta5"
compile "com.github.Raizlabs.DBFlow:dbflow:4.0.0-beta5"
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.google.dagger:dagger:2.9'
compile 'javax.annotation:javax.annotation-api:1.2'
compile 'com.github.tony19:logback-android-core:1.1.1-6'
compile 'com.github.tony19:logback-android-classic:1.1.1-6'
compile 'org.slf4j:slf4j-api:1.7.23'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.github.radzio:android-data-binding-recyclerview:0.1.0'
compile 'com.android.support:recyclerview-v7:25.1.1'
compile 'com.android.support:design:25.1.1'
compile 'com.android.support:percent:25.1.1'
debugCompile 'com.facebook.stetho:stetho:1.4.2'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
debugCompile 'com.github.brianPlummer:tinydancer:0.1.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support:support-annotations:25.1.1'
}

My libs folder only contains the poishadow-all.jar from the release page.

@centic9
Copy link
Owner

centic9 commented Feb 24, 2017

I am having a hard time reproducing this with your dependencies as some of them are not publicly available and some clash with the version of Android libs that are used in this sample-project. Can you extract a self-sufficient small sample-app that shows the problem?

@SUPERCILEX
Copy link

#5 (comment) might fix your issue.

@centic9
Copy link
Owner

centic9 commented Mar 8, 2017

I have release version 0.3 which incorporates most of the changes from #7, hopefully this also fixes this issue, please comment and reopen if not.

@centic9 centic9 closed this as completed Mar 8, 2017
@centic9
Copy link
Owner

centic9 commented Jun 18, 2017

Please see #10 (comment) in issue #10 where a workaround is described that I also document in the README now until someone comes up with a better way of doing this.

@Xosmond
Copy link

Xosmond commented Apr 18, 2018

I went into this problem too, the workaround there not fixed the problem.

package javax.xml.stream;

    public static XMLEventFactory newInstance() throws FactoryConfigurationError {
        return (XMLEventFactory)FactoryFinder.find("javax.xml.stream.XMLEventFactory", "com.bea.xml.stream.EventFactory");
    }

The problem comes from there.

SOLVED WITH:

System.setProperty("javax.xml.stream.XMLInputFactory", "com.fasterxml.aalto.stax.InputFactoryImpl")
System.setProperty("javax.xml.stream.XMLOutputFactory", "com.fasterxml.aalto.stax.OutputFactoryImpl")
System.setProperty("javax.xml.stream.XMLEventFactory", "com.fasterxml.aalto.stax.EventFactoryImpl")

and adding stax to gradle:

implementation 'com.fasterxml:aalto-xml:1.0.0'

@Akansh0581
Copy link

Add the following to your gradle file:
implementation 'com.fasterxml:aalto-xml:1.0.0'
And relax...

@albert0m
Copy link

if I add it I get the errors:

Duplicate class com.fasterxml.aalto.AsyncByteArrayFeeder found in modules aalto-xml-1.0.0.jar (com.fasterxml:aalto-xml:1.0.0) and poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17)
Duplicate class com.fasterxml.aalto.AsyncByteBufferFeeder found in modules aalto-xml-1.0.0.jar (com.fasterxml:aalto-xml:1.0.0) and poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17)
Duplicate class com.fasterxml.aalto.AsyncInputFeeder found in modules aalto-xml-1.0.0.jar (com.fasterxml:aalto-xml:1.0.0) and poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17)
Duplicate class com.fasterxml.aalto.AsyncXMLInputFactory found in modules aalto-xml-1.0.0.jar 

ecc

@h4jahmad
Copy link

I went into this problem too, the workaround there not fixed the problem.

package javax.xml.stream;

    public static XMLEventFactory newInstance() throws FactoryConfigurationError {
        return (XMLEventFactory)FactoryFinder.find("javax.xml.stream.XMLEventFactory", "com.bea.xml.stream.EventFactory");
    }

The problem comes from there.

SOLVED WITH:

System.setProperty("javax.xml.stream.XMLInputFactory", "com.fasterxml.aalto.stax.InputFactoryImpl")
System.setProperty("javax.xml.stream.XMLOutputFactory", "com.fasterxml.aalto.stax.OutputFactoryImpl")
System.setProperty("javax.xml.stream.XMLEventFactory", "com.fasterxml.aalto.stax.EventFactoryImpl")

and adding stax to gradle:

implementation 'com.fasterxml:aalto-xml:1.0.0'

In Which file we should add those "Three Line"??????

@nckshr
Copy link

nckshr commented Feb 19, 2020

Still experiencing this issue even using the advice in the README.
I am using the pre-packaged poishadow jar file from this repository.

I have these lines in my app's onCreate:

System.setProperty("javax.xml.stream.XMLInputFactory","com.fasterxml.aalto.stax.InputFactoryImpl")
System.setProperty("javax.xml.stream.XMLOutputFactory","com.fasterxml.aalto.stax.OutputFactoryImpl")
System.setProperty("javax.xml.stream.XMLEventFactory","com.fasterxml.aalto.stax.EventFactoryImpl")

and have added this to my app's build.gradle:

implementation files('libs/poishadow-all.jar')
implementation ('com.fasterxml:aalto-xml:1.0.0')

adding fasterxml to build.gradle creates a large list of duplicate class errors at build time, requiring me to delete entire sections from the poishadow jar (org/codehaus and com/fasterxml). After doing this, the project will build, but I am left with the exact same error!

I can only assume I am missing something important, I know this was closed a while ago but can anyone give me advice on how to get this runtime error to go away?

@centic9
Copy link
Owner

centic9 commented Feb 22, 2020

The addition of com.fasterxml should not be necessary and is the cause for the duplicates.

I would check if the setProperty calls are really executed before you reach any Apache POI code and if the error is really exactly the one that was discussed in this issue.

@nckshr
Copy link

nckshr commented Feb 22, 2020

The addition of com.fasterxml should not be necessary and is the cause for the duplicates.

I would check if the setProperty calls are really executed before you reach any Apache POI code and if the error is really exactly the one that was discussed in this issue.

Thanks for the tips! Actually I did end up figuring out what the problem was. You are right everything I needed was already in the jar (I just tried including fasterxml because I saw others doing it). The fix for me actually involved adding the following System.setProperty lines in addition to those mentioned in the README:

System.setProperty("javax.xml.stream.XMLInputFactory","com.fasterxml.aalto.stax.InputFactoryImpl");        
System.setProperty("javax.xml.stream.XMLOutputFactory","com.fasterxml.aalto.stax.OutputFactoryImpl");  
System.setProperty("javax.xml.stream.XMLEventFactory","com.fasterxml.aalto.stax.EventFactoryImpl");

Not sure if I messed up the jar import some how that it necessitated this or if the README should be updated to include these? Either way, these statements (put in onCreate of the application / service) and the jar were the only things I needed to get it working. Hopefully this helps some others having similar obstacles!

@centic9
Copy link
Owner

centic9 commented Feb 23, 2020

Hm, these are exactly the lines mentioned in the README already, so I don't see what can be updated there?

@nckshr
Copy link

nckshr commented Feb 23, 2020

Hm, these are exactly the lines mentioned in the README already, so I don't see what can be updated there?

Woops, my apologies, I copied the wrong lines from my code. I have updated my post to be the correct lines. All together, this is the full set I needed to get it working:

System.setProperty("javax.xml.stream.XMLInputFactory", "com.fasterxml.aalto.stax.InputFactoryImpl");
System.setProperty("javax.xml.stream.XMLOutputFactory", "com.fasterxml.aalto.stax.OutputFactoryImpl");
System.setProperty("javax.xml.stream.XMLEventFactory", "com.fasterxml.aalto.stax.EventFactoryImpl");
System.setProperty("org.apache.poi.javax.xml.stream.XMLInputFactory", "com.fasterxml.aalto.stax.InputFactoryImpl");
System.setProperty("org.apache.poi.javax.xml.stream.XMLOutputFactory", "com.fasterxml.aalto.stax.OutputFactoryImpl");
System.setProperty("org.apache.poi.javax.xml.stream.XMLEventFactory", "com.fasterxml.aalto.stax.EventFactoryImpl");

@centic9
Copy link
Owner

centic9 commented Feb 28, 2020

Strange that you needed them for the "javax.xml.stream" package as well as we shade all code underneath org.apache.poi here and javax.xml.stream should not exist at all.

Do you have a stacktrace where exactly in the code this was causing an Exception?

@nckshr
Copy link

nckshr commented Feb 28, 2020

Strange that you needed them for the "javax.xml.stream" package as well as we shade all code underneath org.apache.poi here and javax.xml.stream should not exist at all.

Do you have a stacktrace where exactly in the code this was causing an Exception?

Sure thing:

    Process: com.myapp.app, PID: 12019
    org.apache.poi.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.EventFactory not found
        at org.apache.poi.javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
        at org.apache.poi.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:178)
        at org.apache.poi.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
        at org.apache.poi.javax.xml.stream.XMLEventFactory.newInstance(XMLEventFactory.java:30)
        at org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(PackagePropertiesMarshaller.java:41)
        at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:161)
        at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141)
        at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:130)
        at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:295)
        at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:268)
        at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:230)
        at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:209)

The reference to javax seems to be in XMLEventFactory (here's the decompiled line) :

    public static XMLEventFactory newInstance() throws FactoryConfigurationError {
        return (XMLEventFactory)FactoryFinder.find("org.apache.poi.javax.xml.stream.XMLEventFactory", "com.bea.xml.stream.EventFactory");
    }

Perhaps I have not incorporated the jar correctly? I am just using this line in my build.gradle:

    implementation files('libs/poishadow-all.jar')

@centic9
Copy link
Owner

centic9 commented Mar 3, 2020

Strange that you need the javax... properties here, I would not expect this to be required, the exception shows that it is actually looking at org.apache.poi... code here, so it should also only require this property here.

To be honest I am a bit reluctant to add this to the README for now without knowing why it is needed. If you want to investigate more, please open a new issue with enough details to reproduce this behavior, i.e. a sample application that triggers this.

@HelloYu
Copy link

HelloYu commented Jul 18, 2021

I went into this problem too, the workaround there not fixed the problem.
package javax.xml.stream;

    public static XMLEventFactory newInstance() throws FactoryConfigurationError {
        return (XMLEventFactory)FactoryFinder.find("javax.xml.stream.XMLEventFactory", "com.bea.xml.stream.EventFactory");
    }

The problem comes from there.
SOLVED WITH:

System.setProperty("javax.xml.stream.XMLInputFactory", "com.fasterxml.aalto.stax.InputFactoryImpl")
System.setProperty("javax.xml.stream.XMLOutputFactory", "com.fasterxml.aalto.stax.OutputFactoryImpl")
System.setProperty("javax.xml.stream.XMLEventFactory", "com.fasterxml.aalto.stax.EventFactoryImpl")

and adding stax to gradle:
implementation 'com.fasterxml:aalto-xml:1.0.0'

In Which file we should add those "Three Line"??????

Add them in onCreate function of Main Activity

@kurthuwig
Copy link
Author

Although this works I recommend to put it into the onCreate method of the Application subclass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

11 participants