Hi guys,
I used the flag -DAspose.Cells.ZipTool=TEMPFILE
in both of my projects that call Workbook asposeWorkbook = new Workbook(excelStream)
to avoid the POI 5 ZIP issue. However, one of the projects still encounters problems while the other works fine. I can’t figure out the cause or the difference between them. Could you help me identify what the issue might be?
The environment is Aspose.Cells 21.6 and Java 17
This is an issue test:
@Test
public void test() throws Exception {
CqrGeneratorEnvironment.initAsposeLicense();
System.setProperty("Aspose.Cells.ZipTool", "TEMPFILE");
File excel = new File("src/test/resources/POI 5 test.xlsx");
byte[] excelBytes = FileUtils.readFileToByteArray(excel);
try (InputStream excelStream = new ByteArrayInputStream(excelBytes);) {
Workbook asposeWorkbook = new Workbook(excelStream);
System.out.println(asposeWorkbook.getFileName());
}
}
this is trace:
java.lang.IllegalStateException: toArray is not supported
at com.aspose.cells.b.a.d.zm.b(Unknown Source)
at com.aspose.cells.a.d.zj.(Unknown Source)
at com.aspose.cells.a.d.zg.a(Unknown Source)
at com.aspose.cells.a.d.zl.(Unknown Source)
at com.aspose.cells.a.d.zl.a(Unknown Source)
at com.aspose.cells.zsp.a(Unknown Source)
at com.aspose.cells.zka.a(Unknown Source)
at com.aspose.cells.zka.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
at com.camline.cqr.report.ppt.PptReportCreatorTest.test(PptReportCreatorTest.java:150)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
I also attached the EXCEL compressed file of my test
POI 5 test.zip (14.5 KB)
@yi.xuan
It sounds like you’re encountering an issue with the java.lang.IllegalStateException
when using the -DAspose.Cells.ZipTool=TEMPFILE
flag in one of your projects. Since this works in another project, let’s troubleshoot the potential causes and implement a solution.
Cause:
The issue may stem from differences in project dependencies, input files, environment configurations, or error handling.
Solution:
-
Check Project Dependencies: Ensure that both projects are using the same version of Aspose.Cells and any other related libraries. Differences in versions can lead to inconsistencies in behavior.
-
Review Input File: Verify that the Excel file (POI 5 test.xlsx
) is the same in both projects. Even minor differences in the file can cause unexpected issues.
-
Environment Configuration: Confirm that the environment settings (like JVM options) are identical in both projects. This includes checking for any additional flags or configurations that might be set in one project but not the other.
-
Error Handling: Implement additional error handling in your code to capture more details about the exception. This can help identify if the issue is related to the file format or the way the input stream is being handled.
-
Testing with Different Files: Try using a different Excel file in the project that is failing. This can help determine if the issue is specific to the file you are currently using.
Here’s a minimal code snippet to ensure you are correctly setting the property and handling the input stream:
System.setProperty("Aspose.Cells.ZipTool", "TEMPFILE");
File excel = new File("src/test/resources/POI 5 test.xlsx");
try (InputStream excelStream = new FileInputStream(excel)) {
Workbook asposeWorkbook = new Workbook(excelStream);
System.out.println(asposeWorkbook.getFileName());
} catch (Exception e) {
e.printStackTrace(); // This will help in debugging
}
Next Steps:
Please follow the steps outlined above and let me know if these actions help resolve the issue. If the problem persists, provide any additional error messages or context, and I will assist you further. Thank you!
@yi.xuan,
Which version of the Aspose.Cells for Java you are using? I tested your scenario/case with Aspose.Cells for Java v25.7 using your sample file and code snippet, it works fine and I do not get any exception.
@yi.xuan
For the old version of Cells component and some special issues occur with some environments only, it is hard for us to test and trace. Would you please check whether the JDK of this project is different from others? And you may try another option:
-DAspose.Cells.ZipTool=APACHE
this option will use the apache zip tool instead of Java’s zip implementation. And if you enable this option, please make sure you have added the lib of apache zip tool to your classpath(such as the jar of it provided by eclipse).
Hi guys, @johnson.shi
I’m using Aspose.Cells 21.6 and Java 17.
Another project is Java 8. That version is ok.
And I tried -DAspose.Cells.ZipTool=APACHE is not work.
How can I resolve it in Java 17.
@yi.xuan
There is bug for processing input from ByteArrayInputStream with JDK17. However, we cannot provide fix based on the old versions. We are afraid there is no available solution on the side of component itself. Workarounds may be tried:
- From your sample code, you are using stream built from file directly. If so, please use the template file instead of converting it to stream to create the Workbook:
Workbook asposeWorkbook = new Workbook("src/test/resources/POI 5 test.xlsx");
...
-
If in your application it is not possible to use the file directly, you may output the data in the input stream to one temporary file, then use the temporary file to create Workbook, after that delete the file.
-
Using Java 8 instead of 17 for your project
I tried Workbook asposeWorkbook = new Workbook(“src/test/resources/POI 5 test.xlsx”) is OK.
I will try to use second way.
Thank you for your reply
@yi.xuan
Thank you for your feedback. You are welcome. I’m glad you solved the issue by using the suggested solution. If you have any questions, please feel free to contact us at any time.