Bug 57867

Summary: TransformerFactoryConfigurationError: Provider org.apache.xalan.processor.TransformerFactoryImpl not found
Product: POI Reporter: Hector Fontanez <hector.j.fontanez>
Component: POI OverallAssignee: POI Developers List <dev>
Status: RESOLVED WORKSFORME    
Severity: trivial    
Priority: P2    
Version: 3.17-FINAL   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Hector Fontanez 2015-04-28 16:32:47 UTC
Documentation should reflect a change made in Java SE 5.0 that affects creation of documents that depend on the "org.apache" project. The following incompatibility i was extracted from Java SE 5.0 release notes:

"Apache - The org.apache classes, which have never been supported J2SE APIs but are used by the javax.xml package, have moved in 5.0 to com.sun.org.apache. package.internal so that they won't clash with more recent, developer-downloaded versions of the classes. Any applications that depend on the org.apache classes being part of the J2SE release must do one of the following to work in 5.0:

Code the application so it uses only the supported interfaces that are part of JAXP.
Download the org.apache.xalan classes from Apache."

This should be documented as an external dependency of the POI jars since Xalan is not provided with the POI distribution.
Comment 1 Nick Burch 2015-04-28 18:11:16 UTC
Current versions of Apache POI requires Java 6, so I'm not sure this applies/matters to us?

(There are no org.apache.xalan references to be found in the current codebase either)
Comment 2 Hector Fontanez 2015-04-28 23:21:17 UTC
(In reply to Nick Burch from comment #1)
> Current versions of Apache POI requires Java 6, so I'm not sure this
> applies/matters to us?
> 
> (There are no org.apache.xalan references to be found in the current
> codebase either)

Precisely for that reason the documentation must be updated. Since Java SE 5.0, the "org.apache" packages have been relocated. Therefore, you must download Xalan from Apache.  Because that change in Java, this is an external dependency of POI products that depend on code in that package.
Comment 3 Nick Burch 2015-04-29 00:06:06 UTC
I can't find any references to org.apache.xalan in our codebase or documentation, sorry. Any chance you could point me to the place where they are, so we can get them updated?

Ideally, if you could also provide a unit test (that fails on trunk without the fix) to highlight the problem, that'd be handy too!
Comment 4 Hector Fontanez 2015-04-29 14:49:01 UTC
(In reply to Nick Burch from comment #3)
> I can't find any references to org.apache.xalan in our codebase or
> documentation, sorry. Any chance you could point me to the place where they
> are, so we can get them updated?
> 
> Ideally, if you could also provide a unit test (that fails on trunk without
> the fix) to highlight the problem, that'd be handy too!

The following code works with xalan.jar in the classpath, but throws an exception without it:

      Workbook wb = new XSSFWorkbook();
      FileOutputStream fileOut = new FileOutputStream("workbook.xlsx");
      wb.write(fileOut); // Fails here (uncaught exception)
      fileOut.close();

Using HSSFWorkbook works with our without Xalan because they don't use OOXML. My development environment uses Java SE 6 and was failing on the call to the write method until I downloaded (as recommended by Java) Xalan with all the additional JARs (serializer.jar, xercesImpl.jar, xml-apis.jar). Removing the xalan.jar (and leaving the other updated ones) results in following error: java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal.
Comment 5 Nick Burch 2015-04-29 14:54:26 UTC
You haven't said what version of Apache POI you are using. As long as it's something recent (eg 3.11 or 3.12 beta 1), no additional jars are required beyond those shipped in the binary packages. 

The code you have given in your snippet works just fine for me on trunk, with no additional jars needed, so my hunch is that you're using an old version of POI, either knowingly or by accident
Comment 6 Hector Fontanez 2015-04-29 20:30:23 UTC
(In reply to Nick Burch from comment #5)
> You haven't said what version of Apache POI you are using. As long as it's
> something recent (eg 3.11 or 3.12 beta 1), no additional jars are required
> beyond those shipped in the binary packages. 
> 
> The code you have given in your snippet works just fine for me on trunk,
> with no additional jars needed, so my hunch is that you're using an old
> version of POI, either knowingly or by accident

I am using Apache POI 3.11. I updated the bug information. When I upgraded to 3.11, I added the following JARs and removed the old ones from classpath:

	poi-3.11-20141221.jar
	poi-ooxml-3.11-20141221.jar
	poi-ooxml-schemas-3.11-20141221.jar
	xmlbeans-2.6.0.jar

In my particular case, when I wrote using HSSF, it worked fine. However, after changing to XSSF, I could not create even a blank file without an error. Once I added the JARs I mentioned before, the problem went away.  Reading operations were unaffected by this.
Comment 7 Dominik Stadler 2015-04-30 19:29:43 UTC
1. Can you run the following to see where the XSSFWorkbook is loaded, just to make sure that there is not a version of POI loaded from somewhere:

System.out.println(Thread.currentThread().getContextClassLoader().getResource(XSSFWorkbook.class.getName().replace(".", "/") + ".class"));

2. Another thing that could happen is that you have some other jar-file in the classpath which tries to pull in Xalan/Xerces and via the service-files in META-INF "install" Xerces as default XML Parser. 

3. Also which exact JDK is this? If it is the IBM JDK, I would strongly suggest to upgrade to 1.7 as 1.6 has various problems, see also the FAQ at http://poi.apache.org/faq.html#faq-N1017E

=> Can you try this in a newly created project which only has POI? This way we eliminate the first two possible causes?
Comment 8 Dominik Stadler 2017-04-03 14:06:37 UTC
No response for a long time, thus closing this bug for now, please reopen with more information if this is still a problem for you.
Comment 9 Drake 2019-04-04 03:33:51 UTC
I am using following versions to make XSSF Workbook
poi-3.17.jar
poi-ooxml-3.17.jar
poi-ooxml-schemas-3.17.jar
xmlbeans-2.6.0.jar
commons-codec-1.10.jar
commons-collections4-4.1.jar
curvesapi-1.04.jar
stax-api-1.0.1.jar

When i run the code , in the workbook.write() method it is giving error 
[Fail to save: an error occurs while saving the package 
 : The part /docProps/core.xml failed to be saved in the stream with marshaller 
 org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller@1d386dd] ,
even the excel generated is of unsupported format(Corrupted)

But, when i add xalan-2.6.0.jar , this works perfectly fine , workbook write method is working properly and excel generated is as per expectation.
But I don't need xalan-2.6.0 or any of it version. I want to run my code only with above mentioned jars.
Comment 10 Dominik Stadler 2019-04-04 04:40:33 UTC
Please do not reopen any bug where you did not contribute before and which is not related to your problem. 

Please try with the latest version of POI (4.0.1 currently) and create a new bug entry with a sample file and some code that reproduces the problem so we can properly analyze.