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

Getting ClassCastException in native mode when using Apache POI #10891

Closed
yrostov opened this issue Jul 22, 2020 · 16 comments
Closed

Getting ClassCastException in native mode when using Apache POI #10891

yrostov opened this issue Jul 22, 2020 · 16 comments
Labels
kind/bug Something isn't working

Comments

@yrostov
Copy link

yrostov commented Jul 22, 2020

Describe the bug
Code is using org.apache.poi / poi-ooxml libraries and running as AWS Lambda native executable. When code executes Workbook workbook = new XSSFWorkbook() line it gets ClassCastException exception

Expected behavior
Expect to be able to create object of Workbook class

Actual behavior
Getting java.lang.ClassCastException: org.apache.xmlbeans.impl.values.XmlComplexContentImpl cannot be cast to org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook. See attached file with full stack trace.

To Reproduce
Code is based on generated project from Amazon Lambda with RESTEasy, etc guide with addition of Apache POI dependency and code that creates Excel Workbook

Environment (please complete the following information):

  • Output of uname -a or ver: Linux Inspiron-15 4.4.0-18362-Microsoft Agroal extension url configurable independent of configuration subsystem #836-Microsoft Mon May 05 16:04:00 PST 2020 x86_64 x86_64 x86_64 GNU/Linux
  • Output of java -version: OpenJDK 64-Bit Server VM GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02, mixed mode, sharing)
  • GraalVM version (if different from Java):
  • Quarkus version or git rev: 1.6.1.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.3

Additional context
See attached reflect-config.txt based on running agent.

stack.txt
reflect-config.txt

@yrostov yrostov added the kind/bug Something isn't working label Jul 22, 2020
@geoand
Copy link
Contributor

geoand commented Jul 22, 2020

This isn't really a Quarkus bug, as there is no Quarkus extension supporting Apache POI.

Furthermore, not having the sources (https://repo1.maven.org/maven2/org/apache/poi/poi-ooxml-schemas/4.0.1/) does not make it really easy for us to help

@geoand geoand changed the title Getting ClassCastException in native mode Getting ClassCastException in native mode when using Apache POi Jul 22, 2020
@geoand geoand changed the title Getting ClassCastException in native mode when using Apache POi Getting ClassCastException in native mode when using Apache POI Jul 22, 2020
@yrostov
Copy link
Author

yrostov commented Jul 22, 2020

I understand. The only reason I filed this as a bug is because the same code runs as native when I compile it directly with GraalVM via its Maven plugin and without any Quarkus dependencies (attached as txt file). It also runs with no issue in JVM.

If I understand correctly, this issue can be resolved via reflection-config.json. If it is, can you suggest what I need to put in this file to resolve confusion with classes (ClassCastException)? Because this looks like reflection issue. Please see stack trace and generated reflection-config file I attached to issue.

pom.txt

@geoand
Copy link
Contributor

geoand commented Jul 22, 2020

It's very hard to tell without having the actual sources.

@yrostov
Copy link
Author

yrostov commented Jul 22, 2020

@geoand
Copy link
Contributor

geoand commented Jul 22, 2020

I guess, although I personally don't have the time currently to go through the various hoops of trying to figure it out, sorry.

Maybe someone else has an idea of how to quickly fox it? @sberyozkin perhaps you have an answer off the top of your head?

@yrostov
Copy link
Author

yrostov commented Jul 22, 2020

I can help if you outline course of actions for issues of this kind.

@geoand
Copy link
Contributor

geoand commented Jul 22, 2020

I am not sure what is causing it, so I don't have any specific recommendations.
You'd typically need to look at source code and try and imagine how the CCE would occur given the fact that GraalVM can remove a lot of code.

@yrostov
Copy link
Author

yrostov commented Jul 22, 2020

Something to keep in mind, from what I mentioned above. I was able compile this code to native executable using GraalVM Maven plugin in the POM I provided. And run it successfully. I can zip and provide the whole project, if this will help. Thanks

com.oracle.substratevm
native-image-maven-plugin
1.0.0-rc14

@geoand
Copy link
Contributor

geoand commented Jul 22, 2020

I understand that, thanks.

The thing is that the more classes are on the classpath can alter the native image behavior.

Also, are you sure you used the same GraalVM version as Quarkus is using?

@yrostov
Copy link
Author

yrostov commented Jul 22, 2020

This is from command line for working build.

Executing: /home/yury/graalvm-ce-java11-20.1.0/bin/native-image -cp /home/yury/.m2/repository/org/apache/poi/poi-ooxml/4.1.2/poi-ooxml-4.1.2.jar:/home/yury/.m2/repository/org/apache/poi/poi/4.1.2/poi-4.1.2.jar:/home/yury/.m2/repository/commons-codec/commons-codec/1.13/commons-codec-1.13.jar:/home/yury/.m2/repository/org/apache/commons/commons-collections4/4.4/commons-collections4-4.4.jar:/home/yury/.m2/repository/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar:/home/yury/.m2/repository/com/zaxxer/SparseBitSet/1.2/SparseBitSet-1.2.jar:/home/yury/.m2/repository/org/apache/poi/poi-ooxml-schemas/4.1.2/poi-ooxml-schemas-4.1.2.jar:/home/yury/.m2/repository/org/apache/xmlbeans/xmlbeans/3.1.0/xmlbeans-3.1.0.jar:/home/yury/.m2/repository/org/apache/commons/commons-compress/1.19/commons-compress-1.19.jar:/home/yury/.m2/repository/com/github/virtuald/curvesapi/1.06/curvesapi-1.06.jar:/mnt/c/development/graal/target/excel-gen-0.1.jar -ea -H:Class=graal.test.ExcelGen

@ncomet
Copy link

ncomet commented Mar 9, 2021

Hello, I have an open source application project where you can reproduce the problem.

https://github.com/ncomet/excel2adoc

launching the

$ > java -jar target/excel2adoc-1.1-runner excelfile.xlsx

will work, but if you go to "Releases" in the github project, the platform dependent native binaries will produce this stack:

java.lang.ClassCastException: org.apache.xmlbeans.impl.values.XmlComplexContentImpl cannot be cast to org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument
	at org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown Source)
	at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:86)
	at org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:61)
	at org.apache.poi.ooxml.POIXMLDocumentPart.read(POIXMLDocumentPart.java:684)
	at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:180)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:288)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:309)
	at fr.ncomet.Excel2Asciidoc.call(Main.kt:80)
	at fr.ncomet.Excel2Asciidoc.call(Main.kt:28)

I tried adding more dependencies to the project

    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>ooxml-schemas</artifactId>
      <version>1.4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi-ooxml-schemas</artifactId>
      <version>4.1.2</version>
    </dependency>

But without any success.

@lacrosse1991
Copy link

Hello, I have an open source application project where you can reproduce the problem.

https://github.com/ncomet/excel2adoc

launching the

$ > java -jar target/excel2adoc-1.1-runner excelfile.xlsx

will work, but if you go to "Releases" in the github project, the platform dependent native binaries will produce this stack:

java.lang.ClassCastException: org.apache.xmlbeans.impl.values.XmlComplexContentImpl cannot be cast to org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument
	at org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown Source)
	at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:86)
	at org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:61)
	at org.apache.poi.ooxml.POIXMLDocumentPart.read(POIXMLDocumentPart.java:684)
	at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:180)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:288)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:309)
	at fr.ncomet.Excel2Asciidoc.call(Main.kt:80)
	at fr.ncomet.Excel2Asciidoc.call(Main.kt:28)

I tried adding more dependencies to the project

    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>ooxml-schemas</artifactId>
      <version>1.4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi-ooxml-schemas</artifactId>
      <version>4.1.2</version>
    </dependency>

But without any success.

Hi ncomet, were you able to find a fix for this in the end?

@ncomet
Copy link

ncomet commented Apr 27, 2021

Hi ncomet, were you able to find a fix for this in the end?

Unfortunately no. I did not have time to look any further into this.

@knuspertante
Copy link

knuspertante commented Oct 26, 2022

Hey @yrostov

I was able to create and read some various excel files with Poi and Quarkus and got the same error before. Unfortunately I do not know anymore how I solved this error concret, but add some classes to reflect-config.json was the solution.

Importand notice: We used Poi 4.1.2 from Quarkus Tika Extension 1.0.3

Attached you get some snips from my reflect-config.json which could probably help you. Unfortunately I can not provide the whole config.

But nevermind, the best way to create your reflect-config.json or at least figure out which classes are missing in your config is to run your application with native-image agent from graalvm.

snips-reflect-config.json.txt

@nhatdau
Copy link

nhatdau commented Nov 25, 2022

Thanks @knuspertante much! Your reflect-conflig file saved my day.
btw, I use POI 5.2.3 and it also worked.

@gsmet
Copy link
Member

gsmet commented Nov 25, 2022

This is not a Quarkus bug. If someone is interested in creating a POI extension to centralize the reflection config, that would be awesome.
It could be hosted in the Quarkiverse, similarly to the quarkus-tika extension.

Closing this. If someone is interested, please create an extension-proposal issue.

@gsmet gsmet closed this as not planned Won't fix, can't repro, duplicate, stale Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants