Bug 61991 - Simple instantiation of XWPFDocument causes reflection warning and method not found exception
Summary: Simple instantiation of XWPFDocument causes reflection warning and method not...
Status: RESOLVED DUPLICATE of bug 61572
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 3.17-FINAL
Hardware: PC All
: P2 blocker (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2018-01-11 23:43 UTC by Will Greenway
Modified: 2018-01-23 18:17 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
Description Will Greenway 2018-01-11 23:43:44 UTC
This simple code:

        FileInputStream fis = new FileInputStream(filename);
        document = new XWPFDocument(fis);

Using Tiki the mime of the file being attempted:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.poi.openxml4j.util.ZipSecureFile$1 (file:/C:/javadev/workspace/poi-3.17/poi-ooxml-3.17.jar) to field java.io.FilterInputStream.in
WARNING: Please consider reporting this to the maintainers of org.apache.poi.openxml4j.util.ZipSecureFile$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

--> the blocker
java.lang.NoSuchMethodException: org.openxmlformats.schemas.wordprocessingml.x2006.main.impl.CTPictureBaseImpl.<init>(org.apache.xmlbeans.SchemaType, boolean)

Jar files in use:
POI Core came from file:/C:/javadev/workspace/poi-3.17/poi-3.17.jar!/org/apache/poi/poifs/filesystem/POIFSFileSystem.class
POI OOXML came from file:/C:/javadev/workspace/poi-3.17/poi-ooxml-3.17.jar!/org/apache/poi/POIXMLDocument.class
POI Scratchpad came from file:/C:/javadev/workspace/poi-3.17/poi-scratchpad-3.17.jar!/org/apache/poi/hslf/usermodel/HSLFSlideShow.class

I have tried work arounds nothing so far successful.  I've tried switching between JVMs 1.7,1.8,1.9. Looking for jar dependencies and tried different files.

I am building / running in Eclipse version: Oxygen.2 Release (4.7.2) Build id: 20171218-0600

Libraries on build path:
Comment 1 Will Greenway 2018-01-12 00:02:21 UTC
Many of the examples for OOXML (XWPFDocument) refer to version 3.9.  I gathered all the 3.9 jars, recompiled.  Code works.
Comment 2 Andreas Beeker 2018-01-12 08:02:26 UTC
For the Java 9 warning check [1] and add the addOpens & Co. to your java command.
Don't use POI 3.9.
This basic example should work - for other cases try the full schema instead of poi-ooxml-schema.

[1] http://poi.apache.org/faq.html#faq-N102B0
Comment 3 Will Greenway 2018-01-12 20:37:19 UTC

I was able to get 3.17 to work by adding this to the VM Arguments page of the project:
-Xmx1524m --add-modules=java.xml.bind --add-opens=java.xml/com.sun.org.apache.xerces.internal.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED -Duser.language=en -Duser.country=US -Djava9addmods=--add-modules=java.xml.bind -Djavadoc9addmods=--add-modules=java.xml.bind -Djava9addmodsvalue=-Dsun.reflect.debugModuleAccessChecks=true -Djava9addopens1=--add-opens=java.xml/com.sun.org.apache.xerces.internal.util=ALL-UNNAMED -Djava9addopens2=--add-opens=java.base/java.io=ALL-UNNAMED -Djava9addopens3=--add-opens=java.base/java.nio=ALL-UNNAMED -Djava9addopens4=--add-opens=java.base/java.lang=ALL-UNNAMED -Djava9addopens5=--add-opens=java.base/jdk.internal.ref=ALL-UNNAMED -Djava.locale.providers=JRE,CLDR -Dcoverage.enabled=true

I also added the ooxml-schemas-1.3.jar to the classpath.

If the full version is necessary just to instantiate XWPFDocument, shouldn't it be a little easier to find (or included with the download)?
Comment 4 Nick Burch 2018-01-13 05:30:20 UTC
(In reply to Will Greenway from comment #3)
> If the full version is necessary just to instantiate XWPFDocument, shouldn't
> it be a little easier to find (or included with the download)?

Almost all files should be processable by the standard "minimum" smaller poi-ooxml-schemas jar. However, there's always the odd one that uses something else...

Please see this FAQ for more details on the why, the how, and how to get the smaller schemas jar updated to handle your odd file: http://poi.apache.org/faq.html#faq-N10025
Comment 5 PJ Fanning 2018-01-23 12:17:27 UTC

*** This bug has been marked as a duplicate of bug 61572 ***
Comment 6 Tim Allison 2018-01-23 18:07:45 UTC
Added triggering file from TIKA-2549 to include CTPictureBaseImpl in our smaller ooxml jar.

Comment 7 Will Greenway 2018-01-23 18:13:28 UTC
Wanted to add that the file I was reading that caused the issue was docx output from GoogleDocs, which I'd take to be fairly common.
Comment 8 Tim Allison 2018-01-23 18:17:31 UTC
Interesting.  Note that the content was still extracted without exception, but the exception was logged.  Now we're good -- Java 9 aside. :)  Thank you!