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

Runtime fail on native-image application using Apache POI #2187

Closed
cosminpolifronie opened this issue Feb 25, 2020 · 12 comments
Closed

Runtime fail on native-image application using Apache POI #2187

cosminpolifronie opened this issue Feb 25, 2020 · 12 comments
Assignees

Comments

@cosminpolifronie
Copy link

cosminpolifronie commented Feb 25, 2020

Describe GraalVM and your environment :

  • GraalVM version or commit id if built from source: 20.1.0-dev-20200225_0946
  • CE or EE: CE
  • Build Time or run time failure: run time
  • JDK version: JDK11
  • Native compiler information:
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27035 for x64
  • Native linker information:
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27035 for x64
  • OS and OS Version: Windows 10 1909 18363.657
  • Architecture: AMD64
  • The output of java -Xinternalversion:
OpenJDK 64-Bit Server VM (11.0.6+9-jvmci-20.0-b02) for windows-amd64 JRE (11.0.6+9-jvmci-20.0-b02), built on Jan 20 2020 20:19:26 by "" with MS VC++ 15.5 (VS2017)

Have you verified this issue still happens when using the latest snapshot?
It has been verified using GraalVM CE 20.1.0-dev-20200225_0946, the latest snapshot at the time of reporting.

Describe the issue
The example application instantiates an Apache POI class. Its dependencies use reflection, so a reflection config has to be generated for the native-image build. When running the built executable, the following exception occurs:

> graalvm_ni_apachepoi_failure.app.exe
Exception in thread "main" java.lang.ExceptionInInitializerError
        at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:290)
        at java.lang.Class.ensureInitialized(DynamicHub.java:496)
        at org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook$Factory.getTypeLoader(Unknown Source)
        at org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook$Factory.newInstance(Unknown Source)
        at org.apache.poi.xssf.usermodel.XSSFWorkbook.onWorkbookCreate(XSSFWorkbook.java:462)
        at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:265)
        at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:259)
        at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:247)
        at graalvm_ni_apachepoi_failure.App.main(App.java:8)
Caused by: java.lang.IllegalStateException: Cannot load getContextTypeLoader: verify that xbean.jar is on the classpath
        at org.apache.xmlbeans.XmlBeans.buildMethod(XmlBeans.java:185)
        at org.apache.xmlbeans.XmlBeans.buildNoArgMethod(XmlBeans.java:194)
        at org.apache.xmlbeans.XmlBeans.buildGetContextTypeLoaderMethod(XmlBeans.java:204)
        at org.apache.xmlbeans.XmlBeans.<clinit>(XmlBeans.java:130)
        at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
        at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
        ... 8 more
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl
        at com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:60)
        at java.lang.Class.forName(DynamicHub.java:1224)
        at org.apache.xmlbeans.XmlBeans.buildMethod(XmlBeans.java:178)
        ... 13 more

Describe the full native-image command

native-image -cp "C:\graalvm_ni_apachepoi_failure\build\distributions\graalvm_ni_apachepoi_failure\lib\*" --no-fallback graalvm_ni_apachepoi_failure.App --verbose
Executing [
'C:\graalvm\graalvm-ce-java11-20.1.0-dev\bin\java.exe' \
-XX:+UseParallelGC \
-XX:+UnlockExperimentalVMOptions \
-XX:+EnableJVMCI \
-Dtruffle.TrustAllTruffleRuntimeProviders=true \
-Dtruffle.TruffleRuntime=com.oracle.truffle.api.impl.DefaultTruffleRuntime \
-Dgraalvm.ForcePolyglotInvalid=true \
-Dgraalvm.locatorDisabled=true \
-Dsubstratevm.IgnoreGraalVersionCheck=true \
-Djava.lang.invoke.stringConcat=BC_SB \
--add-exports \
jdk.internal.vm.ci/jdk.vm.ci.runtime=ALL-UNNAMED \
--add-exports \
jdk.internal.vm.ci/jdk.vm.ci.code=ALL-UNNAMED \
--add-exports \
jdk.internal.vm.ci/jdk.vm.ci.aarch64=ALL-UNNAMED \
--add-exports \
jdk.internal.vm.ci/jdk.vm.ci.amd64=ALL-UNNAMED \
--add-exports \
jdk.internal.vm.ci/jdk.vm.ci.meta=ALL-UNNAMED \
--add-exports \
jdk.internal.vm.ci/jdk.vm.ci.hotspot=ALL-UNNAMED \
--add-exports \
jdk.internal.vm.ci/jdk.vm.ci.services=ALL-UNNAMED \
--add-exports \
jdk.internal.vm.ci/jdk.vm.ci.common=ALL-UNNAMED \
--add-exports \
jdk.internal.vm.ci/jdk.vm.ci.code.site=ALL-UNNAMED \
--add-exports \
jdk.internal.vm.ci/jdk.vm.ci.code.stack=ALL-UNNAMED \
--add-opens \
jdk.internal.vm.compiler/org.graalvm.compiler.debug=ALL-UNNAMED \
--add-opens \
jdk.internal.vm.compiler/org.graalvm.compiler.nodes=ALL-UNNAMED \
--add-opens \
jdk.unsupported/sun.reflect=ALL-UNNAMED \
--add-opens \
java.base/jdk.internal.module=ALL-UNNAMED \
--add-opens \
java.base/jdk.internal.ref=ALL-UNNAMED \
--add-opens \
java.base/jdk.internal.reflect=ALL-UNNAMED \
--add-opens \
java.base/java.io=ALL-UNNAMED \
--add-opens \
java.base/java.lang=ALL-UNNAMED \
--add-opens \
java.base/java.lang.reflect=ALL-UNNAMED \
--add-opens \
java.base/java.lang.invoke=ALL-UNNAMED \
--add-opens \
java.base/java.lang.ref=ALL-UNNAMED \
--add-opens \
java.base/java.net=ALL-UNNAMED \
--add-opens \
java.base/java.nio=ALL-UNNAMED \
--add-opens \
java.base/java.nio.file=ALL-UNNAMED \
--add-opens \
java.base/java.security=ALL-UNNAMED \
--add-opens \
java.base/javax.crypto=ALL-UNNAMED \
--add-opens \
java.base/java.util=ALL-UNNAMED \
--add-opens \
java.base/java.util.concurrent.atomic=ALL-UNNAMED \
--add-opens \
java.base/sun.security.x509=ALL-UNNAMED \
--add-opens \
java.base/jdk.internal.logger=ALL-UNNAMED \
--add-opens \
org.graalvm.sdk/org.graalvm.nativeimage.impl=ALL-UNNAMED \
--add-opens \
org.graalvm.sdk/org.graalvm.polyglot=ALL-UNNAMED \
--add-opens \
org.graalvm.truffle/com.oracle.truffle.polyglot=ALL-UNNAMED \
--add-opens \
org.graalvm.truffle/com.oracle.truffle.api.impl=ALL-UNNAMED \
-XX:+UseJVMCINativeLibrary \
-Xss10m \
-Xms1g \
-Xmx13642557024 \
-Duser.country=US \
-Duser.language=en \
-Djava.awt.headless=true \
-Dorg.graalvm.version=20.1.0-dev \
-Dorg.graalvm.config=CE \
-Dcom.oracle.graalvm.isaot=true \
-Djava.system.class.loader=com.oracle.svm.hosted.NativeImageSystemClassLoader \
-Xshare:off \
--module-path \
'C:\graalvm\graalvm-ce-java11-20.1.0-dev\lib\truffle\truffle-api.jar' \
'-javaagent:C:\graalvm\graalvm-ce-java11-20.1.0-dev\lib\svm\builder\svm.jar' \
-Djdk.internal.lambda.disableEagerInitialization=true \
-Djdk.internal.lambda.eagerlyInitialize=false \
-Djava.lang.invoke.InnerClassLambdaMetafactory.initializeLambdas=false \
-cp \
'C:\graalvm\graalvm-ce-java11-20.1.0-dev\lib\svm\builder\objectfile.jar;C:\graalvm\graalvm-ce-java11-20.1.0-dev\lib\svm\builder\pointsto.jar;C:\graalvm\graalvm-ce-java11-20.1.0-dev\lib\svm\builder\svm.jar' \
'com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus' \
-imagecp \
'C:\graalvm\graalvm-ce-java11-20.1.0-dev\lib\svm\builder\objectfile.jar;C:\graalvm\graalvm-ce-java11-20.1.0-dev\lib\svm\builder\pointsto.jar;C:\graalvm\graalvm-ce-java11-20.1.0-dev\lib\svm\builder\svm.jar;C:\graalvm\graalvm-ce-java11-20.1.0-dev\lib\svm\library-support.jar;C:\graalvm_ni_apachepoi_failure\build\distributions\graalvm_ni_apachepoi_failure\lib\*' \
'-H:Path=C:\graalvm_ni_apachepoi_failure\build\libs' \
-H:FallbackThreshold=0 \
'-H:CLibraryPath=C:\graalvm\graalvm-ce-java11-20.1.0-dev\lib\svm\clibraries\windows-amd64' \
-H:Class=graalvm_ni_apachepoi_failure.App \
-H:Name=graalvm_ni_apachepoi_failure.app \

]
[graalvm_ni_apachepoi_failure.app:15500]    classlist:   5,354.03 ms,  0.94 GB
[graalvm_ni_apachepoi_failure.app:15500]        (cap):   2,719.90 ms,  0.94 GB
[graalvm_ni_apachepoi_failure.app:15500]        setup:   5,238.48 ms,  0.94 GB
[graalvm_ni_apachepoi_failure.app:15500]   (typeflow):  19,277.36 ms,  2.69 GB
[graalvm_ni_apachepoi_failure.app:15500]    (objects):  14,421.34 ms,  2.69 GB
[graalvm_ni_apachepoi_failure.app:15500]   (features):     829.48 ms,  2.69 GB
[graalvm_ni_apachepoi_failure.app:15500]     analysis:  35,316.22 ms,  2.69 GB
[graalvm_ni_apachepoi_failure.app:15500]     (clinit):     474.53 ms,  2.69 GB
[graalvm_ni_apachepoi_failure.app:15500]     universe:   1,469.09 ms,  2.69 GB
[graalvm_ni_apachepoi_failure.app:15500]      (parse):   4,601.44 ms,  2.69 GB
[graalvm_ni_apachepoi_failure.app:15500]     (inline):   4,936.58 ms,  4.14 GB
[graalvm_ni_apachepoi_failure.app:15500]    (compile):  25,365.61 ms,  4.68 GB
[graalvm_ni_apachepoi_failure.app:15500]      compile:  36,794.99 ms,  4.68 GB
[graalvm_ni_apachepoi_failure.app:15500]        image:   2,648.88 ms,  4.68 GB
[graalvm_ni_apachepoi_failure.app:15500]        write:     684.50 ms,  4.68 GB
[graalvm_ni_apachepoi_failure.app:15500]      [total]:  87,858.55 ms,  4.68 GB

Code snippet or code repository that reproduces the issue

  • src\main\java\graalvm_ni_apachepoi_failure\App.java
package graalvm_ni_apachepoi_failure;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class App {
    public static void main(String[] args) {
        XSSFWorkbook workbook = new XSSFWorkbook();
        System.out.println(workbook.toString());
        try {
            workbook.close();
        } catch (Exception e) {
            System.out.println("Couldn't close workbook");
        }
    }
}
  • build.gradle
plugins {
    id 'java'
    id 'application'
}

repositories {
    jcenter()
}

dependencies {
    implementation 'org.apache.poi:poi:4.1.2'
    implementation 'org.apache.poi:poi-ooxml:4.1.2'
}

application {
    mainClassName = 'graalvm_ni_apachepoi_failure.App'
}

jar {
    manifest {
        attributes 'Main-Class': mainClassName
    }
}
  • native-image\META-INF\native-image\jni-config.json
[
]
  • native-image\META-INF\native-image\proxy-config.json
[
]
  • native-image\META-INF\native-image\reflect-config.json
[
{
  "name":"java.lang.Class"
},
{
  "name":"org.apache.commons.compress.archivers.zip.AsiExtraField",
  "methods":[{"name":"<init>","parameterTypes":[] }]
},
{
  "name":"org.apache.commons.compress.archivers.zip.JarMarker",
  "methods":[{"name":"<init>","parameterTypes":[] }]
},
{
  "name":"org.apache.commons.compress.archivers.zip.ResourceAlignmentExtraField",
  "methods":[{"name":"<init>","parameterTypes":[] }]
},
{
  "name":"org.apache.commons.compress.archivers.zip.UnicodeCommentExtraField",
  "methods":[{"name":"<init>","parameterTypes":[] }]
},
{
  "name":"org.apache.commons.compress.archivers.zip.UnicodePathExtraField",
  "methods":[{"name":"<init>","parameterTypes":[] }]
},
{
  "name":"org.apache.commons.compress.archivers.zip.X000A_NTFS",
  "methods":[{"name":"<init>","parameterTypes":[] }]
},
{
  "name":"org.apache.commons.compress.archivers.zip.X0014_X509Certificates",
  "methods":[{"name":"<init>","parameterTypes":[] }]
},
{
  "name":"org.apache.commons.compress.archivers.zip.X0015_CertificateIdForFile",
  "methods":[{"name":"<init>","parameterTypes":[] }]
},
{
  "name":"org.apache.commons.compress.archivers.zip.X0016_CertificateIdForCentralDirectory",
  "methods":[{"name":"<init>","parameterTypes":[] }]
},
{
  "name":"org.apache.commons.compress.archivers.zip.X0017_StrongEncryptionHeader",
  "methods":[{"name":"<init>","parameterTypes":[] }]
},
{
  "name":"org.apache.commons.compress.archivers.zip.X0019_EncryptionRecipientCertificateList",
  "methods":[{"name":"<init>","parameterTypes":[] }]
},
{
  "name":"org.apache.commons.compress.archivers.zip.X5455_ExtendedTimestamp",
  "methods":[{"name":"<init>","parameterTypes":[] }]
},
{
  "name":"org.apache.commons.compress.archivers.zip.X7875_NewUnix",
  "methods":[{"name":"<init>","parameterTypes":[] }]
},
{
  "name":"org.apache.commons.compress.archivers.zip.Zip64ExtendedInformationExtraField",
  "methods":[{"name":"<init>","parameterTypes":[] }]
},
{
  "name":"org.apache.xmlbeans.impl.schema.BuiltinSchemaTypeSystem",
  "methods":[
    {"name":"get","parameterTypes":[] }, 
    {"name":"getNoType","parameterTypes":[] }
  ]
},
{
  "name":"org.apache.xmlbeans.impl.schema.PathResourceLoader",
  "methods":[{"name":"<init>","parameterTypes":["java.io.File[]"] }]
},
{
  "name":"org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl",
  "methods":[
    {"name":"build","parameterTypes":["org.apache.xmlbeans.SchemaTypeLoader[]","org.apache.xmlbeans.ResourceLoader","java.lang.ClassLoader"] }, 
    {"name":"getContextTypeLoader","parameterTypes":[] }
  ]
},
{
  "name":"org.apache.xmlbeans.impl.schema.SchemaTypeSystemCompiler",
  "methods":[{"name":"compile","parameterTypes":["java.lang.String","org.apache.xmlbeans.SchemaTypeSystem","org.apache.xmlbeans.XmlObject[]","org.apache.xmlbeans.BindingConfig","org.apache.xmlbeans.SchemaTypeLoader","org.apache.xmlbeans.Filer","org.apache.xmlbeans.XmlOptions"] }]
},
{
  "name":"org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl",
  "methods":[{"name":"<init>","parameterTypes":["java.lang.Class"] }]
},
{
  "name":"org.apache.xmlbeans.impl.store.Locale",
  "methods":[
    {"name":"nodeToCursor","parameterTypes":["org.w3c.dom.Node"] }, 
    {"name":"nodeToXmlObject","parameterTypes":["org.w3c.dom.Node"] }, 
    {"name":"nodeToXmlStream","parameterTypes":["org.w3c.dom.Node"] }, 
    {"name":"streamToNode","parameterTypes":["javax.xml.stream.XMLStreamReader"] }
  ]
},
{
  "name":"org.apache.xmlbeans.impl.store.Path",
  "methods":[{"name":"compilePath","parameterTypes":["java.lang.String","org.apache.xmlbeans.XmlOptions"] }]
},
{
  "name":"org.apache.xmlbeans.impl.store.Query",
  "methods":[{"name":"compileQuery","parameterTypes":["java.lang.String","org.apache.xmlbeans.XmlOptions"] }]
},
{
  "name":"org.openxmlformats.schemas.officeDocument.x2006.customProperties.impl.CTPropertiesImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.officeDocument.x2006.customProperties.impl.PropertiesDocumentImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.impl.CTPropertiesImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.impl.PropertiesDocumentImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.STFontScheme$Enum"
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType$Enum"
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTBookViewImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTBookViewsImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTBorderImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTBorderPrImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTColorImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFillImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontNameImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontSchemeImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontSizeImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTIntPropertyImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTPatternFillImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTSheetsImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTSstImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTStylesheetImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTWorkbookImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTWorkbookPrImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTXfImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STBorderIdImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STCellStyleXfIdImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STFillIdImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STFontIdImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STFontSchemeImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STNumFmtIdImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STPatternTypeImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.STXstringImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.SstDocumentImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.StyleSheetDocumentImpl",
  "methods":[{"name":"<init>","parameterTypes":["org.apache.xmlbeans.SchemaType"] }]
},
{
  "name":"schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.TypeSystemHolder",
  "fields":[{"name":"typeSystem"}]
}
]
  • native-image\META-INF\native-image\resource-config.json
{
  "resources":[
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctbookviewf677type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctbookviewsb864type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctborderf935type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctborderpre497type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctcolord2c2type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctfill550ctype.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctfont14d8type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctfontname2dc3type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctfontschemebf5dtype.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctfontsizeb3b9type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctintproperty32c3type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctpatternfill7452type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctproperties2c18type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctproperties3f10type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctsheets49fdtype.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctsst44f3type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctstylesheet4257type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctworkbook83c3type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctworkbookpr03a5type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/ctxf97f7type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/index.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/properties288cdoctype.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/propertiesee84doctype.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/sstf81fdoctype.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/stborderid1a80type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/stcellstylexfid70c7type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/stfillida097type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/stfontid9d63type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/stfontschemef36dtype.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/stnumfmtid76fbtype.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/stpatterntype7939type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/stxstring1198type.xsb\\E"}, 
    {"pattern":"\\Qschemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/stylesheet5d8bdoctype.xsb\\E"}
  ],
  "bundles":[{"name":"org.apache.xmlbeans.impl.regex.message"}]
}

Steps to reproduce the issue

  1. Install Gradle 6.2
  2. Create a directory called graalvm_ni_apachepoi_failure and paste src\main\java\graalvm_ni_apachepoi_failure\App.java, build.gradle, native-image\META-INF\native-image\jni-config.json, native-image\META-INF\native-image\proxy-config.json, native-image\META-INF\native-image\reflect-config.json, native-image\META-INF\native-image\resource-config.json provided above into it
  3. Build the application using Gradle 6.2: open a command prompt and execute gradle clean build into the graalvm_ni_apachepoi_failure directory
  4. Run gu install native-image
  5. Change the current working directory to graalvm_ni_apachepoi_failure\native-image
  6. (Optional) Regenerate the reflection configs: java -agentlib:native-image-agent=config-output-dir=META-INF\native-image -cp "..\build\distributions\graalvm_ni_apachepoi_failure\lib\*" graalvm_ni_apachepoi_failure.App
  7. Build the native-image executable using native-image -cp "..\build\distributions\graalvm_ni_apachepoi_failure\lib\*" --no-fallback --verbose graalvm_ni_apachepoi_failure.App

Expected behavior
The application should have printed the string representation of a XSSFWorkbook object.

@cosminpolifronie
Copy link
Author

Simillar to #1993 but this uses Java 11.

@cstancu
Copy link
Member

cstancu commented Sep 24, 2020

I see that you attached the native-image\META-INF\native-image\reflect-config.json file and that it contains org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl but I don't see how you specify this file to native-image. I think that in this case, since you don't package your app as a jar, you need to specify the reflection config explicitly, I don't think it is automatically detected in META-INF. @jramirez-isc can you please try to reproduce? Thanks!

@cstancu cstancu assigned jramirez-isc and unassigned cstancu Sep 24, 2020
@jramirez-isc jramirez-isc assigned cstancu and unassigned jramirez-isc Jan 7, 2021
@kkriske
Copy link
Contributor

kkriske commented Feb 26, 2021

@sgyeme in my experience, the ClassCastException is always caused by missing reflection configuration. For yours specifically, org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTWorkbookImpl and its constructor.

@kkriske
Copy link
Contributor

kkriske commented Feb 26, 2021

I'll also add that you can initialize org.apache.commons.compress at build-time, which is the only config I have for apache commons-compress. The reflection config is afaik only required for the static initialization of org.apache.commons.compress.archivers.zip.ExtraFieldUtils so putting it (and the whole package) at build-time is much easier.

For this issue itself: Other than that, you have a few org.apache.xmlbeans classes in your config that I didn't need, but that's probably required for the .toString call.

The config itself looks ok, and for me, the agent was able to get all the config I needed. (I also use XSSFWorkbook, so I don't see any reason why that would not be the case for you). If the suggestion from @cstancu doesn't work, you may want to try POI 5.0.0, I have since moved on to it and I find it a tiny bit more native-image friendly, although most of the config will stay the same.

@kmandalas
Copy link

@kkriske could you please share the configuration you have for org.apache.commons.compress?

@kkriske
Copy link
Contributor

kkriske commented Apr 7, 2022

As stated in my previous message, just initializing everything at build-time:

# native-image.properties
Args = --initialize-at-build-time=\
  org.apache.commons.compress

I'm currently using commons-compress:1.20.

That's all, but fair warning, initializing entire packages at built-time instead of letting GraalVM detect what is safe to initialize is discouraged as it may introduce hard to debug bugs.

As far as I know, only org.apache.commons.compress.archivers.zip.ExtraFieldUtils would require reflection config if initialized at run-time, so if you want to keep the previous warning in mind, you may want to only initialize this class at build-time and let GraalVM figure out the rest.

Are you running into any specific issues with commons-compress?

@kmandalas
Copy link

kmandalas commented Apr 7, 2022

@kkriske thank you for the prompt response. I am in the process of migrating some microservices to native (using poi-ooxml 5.2.0), and I get the following error during Runtime:

2022-04-06T11:15:56.642066+00:00 app[web.1]: Caused by: java.lang.ExceptionInInitializerError
2022-04-06T11:15:56.642076+00:00 app[web.1]: 	at org.apache.commons.compress.archivers.zip.ZipArchiveEntry.setExtra(ZipArchiveEntry.java:713)
2022-04-06T11:15:56.642087+00:00 app[web.1]: 	at org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.getNextZipEntry(ZipArchiveInputStream.java:350)
2022-04-06T11:15:56.642101+00:00 app[web.1]: 	at org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.getNextEntry(ZipArchiveThresholdInputStream.java:152)
2022-04-06T11:15:56.642110+00:00 app[web.1]: 	at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource.<init>(ZipInputStreamZipEntrySource.java:94)
2022-04-06T11:15:56.642120+00:00 app[web.1]: 	at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:132)
2022-04-06T11:15:56.642131+00:00 app[web.1]: 	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:312)
2022-04-06T11:15:56.642140+00:00 app[web.1]: 	at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:59)
2022-04-06T11:15:56.642150+00:00 app[web.1]: 	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:304)
2022-04-06T11:15:56.642158+00:00 app[web.1]: 	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:300)
2022-04-06T11:15:56.642170+00:00 app[web.1]: 	at gr.kmandalas.expenser.service.ExcelService.generateExcel(ExcelService.java:55)
2022-04-06T11:15:56.642179+00:00 app[web.1]: 	at gr.kmandalas.expenser.controller.ExpensesController.generate(ExpensesController.java:72)
2022-04-06T11:15:56.642189+00:00 app[web.1]: 	at java.lang.reflect.Method.invoke(Method.java:566)
2022-04-06T11:15:56.642198+00:00 app[web.1]: 	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
2022-04-06T11:15:56.642210+00:00 app[web.1]: 	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
2022-04-06T11:15:56.642220+00:00 app[web.1]: 	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
2022-04-06T11:15:56.642229+00:00 app[web.1]: 	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
2022-04-06T11:15:56.642240+00:00 app[web.1]: 	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
2022-04-06T11:15:56.642250+00:00 app[web.1]: 	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
2022-04-06T11:15:56.642258+00:00 app[web.1]: 	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)
2022-04-06T11:15:56.642268+00:00 app[web.1]: 	... 86 more
2022-04-06T11:15:56.642282+00:00 app[web.1]: Caused by: java.lang.RuntimeException: class org.apache.commons.compress.archivers.zip.AsiExtraField is not a concrete class
2022-04-06T11:15:56.642292+00:00 app[web.1]: 	at org.apache.commons.compress.archivers.zip.ExtraFieldUtils.register(ExtraFieldUtils.java:73)
2022-04-06T11:15:56.642301+00:00 app[web.1]: 	at org.apache.commons.compress.archivers.zip.ExtraFieldUtils.<clinit>(ExtraFieldUtils.java:43)
2022-04-06T11:15:56.642310+00:00 app[web.1]: 	... 105 more

UPDATE: After adding the --initialize-at-build-time=org.apache.commons.compress hint, I get now a different error:

2022-04-07T08:36:46.256635+00:00 app[web.1]: Caused by: java.lang.ExceptionInInitializerError
2022-04-07T08:36:46.256645+00:00 app[web.1]: 	at org.openxmlformats.schemas.spreadsheetml.x2006.main.ExternalLinkDocument.<clinit>(ExternalLinkDocument.java:23)
2022-04-07T08:36:46.256655+00:00 app[web.1]: 	at org.apache.poi.xssf.model.ExternalLinksTable.readFrom(ExternalLinksTable.java:66)
2022-04-07T08:36:46.256665+00:00 app[web.1]: 	at org.apache.poi.xssf.model.ExternalLinksTable.<init>(ExternalLinksTable.java:60)
2022-04-07T08:36:46.256680+00:00 app[web.1]: 	at org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:61)
2022-04-07T08:36:46.256689+00:00 app[web.1]: 	at org.apache.poi.ooxml.POIXMLDocumentPart.read(POIXMLDocumentPart.java:661)
2022-04-07T08:36:46.256699+00:00 app[web.1]: 	at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:165)
2022-04-07T08:36:46.256709+00:00 app[web.1]: 	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:274)
2022-04-07T08:36:46.256719+00:00 app[web.1]: 	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:304)
2022-04-07T08:36:46.256728+00:00 app[web.1]: 	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:300)
2022-04-07T08:36:46.256738+00:00 app[web.1]: 	at gr.kmandalas.expenser.service.ExcelService.generateExcel(ExcelService.java:55)
2022-04-07T08:36:46.256748+00:00 app[web.1]: 	at gr.kmandalas.expenser.controller.ExpensesController.generate(ExpensesController.java:72)
2022-04-07T08:36:46.256758+00:00 app[web.1]: 	at java.lang.reflect.Method.invoke(Method.java:566)
2022-04-07T08:36:46.256769+00:00 app[web.1]: 	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
2022-04-07T08:36:46.256779+00:00 app[web.1]: 	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
2022-04-07T08:36:46.256794+00:00 app[web.1]: 	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
2022-04-07T08:36:46.256805+00:00 app[web.1]: 	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
2022-04-07T08:36:46.256815+00:00 app[web.1]: 	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
2022-04-07T08:36:46.256829+00:00 app[web.1]: 	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
2022-04-07T08:36:46.256838+00:00 app[web.1]: 	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)
2022-04-07T08:36:46.256848+00:00 app[web.1]: 	... 86 more
2022-04-07T08:36:46.256870+00:00 app[web.1]: Caused by: org.apache.xmlbeans.SchemaTypeLoaderException: XML-BEANS compiled schema: Could not locate compiled schema resource org/apache/poi/schemas/ooxml/system/ooxml/index.xsb (org.apache.poi.schemas.ooxml.system.ooxml.index) - code 0
2022-04-07T08:36:46.256872+00:00 app[web.1]: 	at org.apache.xmlbeans.impl.schema.XsbReader.<init>(XsbReader.java:63)
2022-04-07T08:36:46.256887+00:00 app[web.1]: 	at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.initFromHeader(SchemaTypeSystemImpl.java:235)
2022-04-07T08:36:46.256888+00:00 app[web.1]: 	at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.<init>(SchemaTypeSystemImpl.java:201)
2022-04-07T08:36:46.256932+00:00 app[web.1]: 	at org.apache.poi.schemas.ooxml.system.ooxml.TypeSystemHolder.<init>(TypeSystemHolder.java:9)
2022-04-07T08:36:46.256934+00:00 app[web.1]: 	at org.apache.poi.schemas.ooxml.system.ooxml.TypeSystemHolder.<clinit>(TypeSystemHolder.java:6)
2022-04-07T08:36:46.256935+00:00 app[web.1]: 	... 105 more

In my pom.xml, I only have the following dependency:

 <dependency>
  <groupId>org.apache.poi</groupId>
   <artifactId>poi-ooxml</artifactId>
    <version>5.2.0</version>
</dependency>

@kkriske
Copy link
Contributor

kkriske commented Apr 7, 2022

POI requires resources & reflection at runtime so you need to provide the config for that. I've previously explained a bit about POI and native-image here: #3191
But in short, the resource & reflection config you need can be generated with the native-image-agent.

@kmandalas
Copy link

kmandalas commented Apr 7, 2022

@kkriske I finally managed to resolve the issues by using the native-image-agent. Thanks for the feedback.

@jigneshkhatri
Copy link

jigneshkhatri commented Nov 17, 2022

@kkriske I am using an Apache POI lib in Micronaut project which I am building a Graalvm native-image. But the issue is there are tons of classes and method in POI lib which are using the reflection, and POI dynamically uses any of those classes to read the excel file. I am developing an application where end users will upload and read the excel files, and thus I will need the reflection configs of all the classes and method of POI lib. How can I get those configs without actually executing that code?

@anthonydenecheau
Copy link

native-image-agent ?

Could you explain ? Which command do you run ? please

@cstancu
Copy link
Member

cstancu commented Dec 6, 2023

Using the native-image-agent seems to have fixed the issue.

@cstancu cstancu closed this as completed Dec 6, 2023
Native Image automation moved this from To do to Done Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Native Image
  
Done
Development

No branches or pull requests

7 participants