LoadOptions opt = new LoadOptions();
opt.setMemorySetting(MemorySetting.MEMORY_PREFERENCE);
I am thinking of making one static instance of LoadOptions, and sharing it across all the Workbooks. Is the LoadOptions thread-safe?
Do we have any java-doc for the aspose-cells classes? More information apart from what is mentioned on Aspose API References
Hi Hitesh,
Thank you for contacting Aspose support.
First of all, please note that Aspose.Cells for Java APIs are thread safe unless you are sharing the resources between the concurrent threads. In case you have a shared data/resource then you have to do the synchronization your self. As far as this inquiry is concerned, I believe you wish to create a single LoadOptions instance and use it across different threads. I have tested the scenario with following piece of code against the latest version of Aspose.Cells for Java 9.0.0, and I was not able to observe any problem.
Java
LoadOptions opt = new LoadOptions();
opt.setMemorySetting(MemorySetting.MEMORY_PREFERENCE);
for (int z = 0; z < 200; z++)
{
new Thread(){
@Override
public void run() {
Workbook wb;
try
{
wb = new Workbook(“D:/book1.xlsx”, opt);
} catch (Exception e1)
{
e1.printStackTrace();
}
}
}.start();
}
Regarding the last part of your inquiry, please note that we try to keep the live documentation up-to-date as per latest API set. In case you wish to look for the documentation as per your current revision of the API, we suggest you to check the HTML based documentation supplied in the product archive at \aspose-cells-x.x.x-java\doc\.
Babar, thanks for the quick response.
My testng test loads an excel file (filename provided by data provider), and gets the sheet names from the file. While opening the excel file, it uses the static loadoptions variable. The dataprovider has two files. The test runs two times with each of the two files.
But, it is failing with the following exception:
Caused by: java.lang.NullPointerException
at com.aspose.cells.zsz.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
When I remove the static load option variable, and generate new load option for every file, the tests succeed.
Does it mean that the load option should not be shared? Or can it be some other issue?
Hi Hitesh,
Please be kind enough to share your executable code for our testing. Moreover, please confirm if you are getting the NullPointerException against the latest build of Aspose.Cells for Java 9.0.9?
Yep, I am using latest jar 9.0.0.
I have the code ready.
How can I upload the zip file over here?
Edit:
Attached the file loadOptions.zip.
If the testng test case is executed with loadoption variable LOAD_NO_DATA, it gives the error mentioend below:
java.lang.IllegalStateException: This is not a structured storage file.
at com.aspose.cells.zagr.(Unknown Source)
at com.aspose.cells.zwg.b(Unknown Source)
at com.aspose.cells.zwg.(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
If the testng test case is executed with loadoption variable LOAD_NO_DATA_LOCAL, it works fine.
Attached the sample excel files, error log and the testng test case.
Hi Hitesh,
Please check the attachment for a snapshot. Please note, on Add Post window, you will find the Add/Update button. You can use it to trigger open a Browse File dialog. Select Choose File button to select the ZIP file and click Save.
Thanks.
As per your guidelines, I have edited my previous comment to upload the file.
Hi Hitesh,
Thank you for sharing the code. Please check the attachment for the updated LoadOptionTest class in which I have removed the unnecessary dependencies over the third party APIs in order to reduce the chance of their contribution to the said error. Please add the class to you project and execute the following statement in the main method. You will notice that the result is same regardless how you initialize the LoadOptions class.
Please note, I have performed all tests on Windows 10 x64 against JDK 1.8. In case you face any difficulty with the provided class, we will require your complete environment details to investigate the matter.
Java
LoadOptionTest test = new LoadOptionTest();
test.getSourceObjectsFromXLSTest(path to 97-2003.xls/xlsx);
Hello Babar,
Attached the code without unit test related dependencies.
It still fails: First time, the LoadOptions object is used for an xls file. When we use it for the second time with xlsx file, it fails with the following exception:
java.lang.IllegalStateException: This is not a structured storage file.
at com.aspose.cells.zagr.(Unknown Source)
at com.aspose.cells.zwg.b(Unknown Source)
at com.aspose.cells.zwg.(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
Hi Hitesh,
Thank you for the updated code segment.
I am able to replicate the said exception therefore I have raised it as CELLSJAVA-42040 in our bug tracking system. Please spare us little time to evaluate the scenario and get back with updates in this regard.
Hi,
We have evaluated your issue “CELLSJAVA-42040” further.
Well, when the LoadOptions object was initialized, the file format specified by it is Auto. While loading the template file, the correct file format will be set to this object. So if you use this object to load another template file, the specified load format will be the one of the previous template file. In this way, the exception was caused because the given LoadOptions specified incorrect load format.
So, please do not reuse the LoadOptions object. To get the unified entry, we think it will be better for you to instantiate and set the LoadOptions object in one method.
Thank you.