Invalid error: can't parse argument number: 1:X8

Hi,

Using Aspose Cells for Java, version 22.7.

Sample code:

InputStream inputStream = new AutoCloseInputStream(new BufferedInputStream(new FileInputStream("empty.xlsx")));
new Workbook(inputStream);

AutoCloseInputStream is from commons-io:commons-io:2.4 library (also attached).

Resulting stacktrace:

Exception in thread "main" java.lang.IllegalArgumentException: can't parse argument number: 1:X8
	at java.text.MessageFormat.makeFormat(MessageFormat.java:1429)
	at java.text.MessageFormat.applyPattern(MessageFormat.java:479)
	at java.text.MessageFormat.<init>(MessageFormat.java:362)
	at java.text.MessageFormat.format(MessageFormat.java:840)
	at com.aspose.cells.b.a.f.u78.a(Unknown Source)
	at com.aspose.cells.b.a.f0.a(Unknown Source)
	at com.aspose.cells.c.s9q.B(Unknown Source)
	at com.aspose.cells.c.s9q.v(Unknown Source)
	at com.aspose.cells.c.s9q.z(Unknown Source)
	at com.aspose.cells.c.s9q.y(Unknown Source)
	at com.aspose.cells.c.d.a(Unknown Source)
	at com.aspose.cells.g_h.a(Unknown Source)
	at com.aspose.cells.u78.E(Unknown Source)
	at com.aspose.cells.u78.a(Unknown Source)
	at com.aspose.cells.f7l.a(Unknown Source)
	at com.aspose.cells.o9.a(Unknown Source)
	at com.aspose.cells.o9.a(Unknown Source)
	at com.aspose.cells.Workbook.a(Unknown Source)
	at com.aspose.cells.Workbook.<init>(Unknown Source)
	at <sample code above>
Caused by: java.lang.NumberFormatException: For input string: "1:X8"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:580)
	at java.lang.Integer.parseInt(Integer.java:615)
	at java.text.MessageFormat.makeFormat(MessageFormat.java:1427)
	... 19 more

Note that Aspose Cells is causing an exception while attempting to generate an error message for another exception.

Kind regards,
Taras

files.zip (172.1 KB)

@TarasTielkes,

Thanks for the template file.

Please notice, after an initial test, I am able to reproduce the issue as you mentioned by using your template file. It works if I do not involve Apache Commons IO library, it works fine if I load the file directly from file path or from java.io streams (JDK) using Workbook constructor. But I got an
exception “java.lang.IllegalArgumentException: can’t parse argument number: 1:X8” when loading the Excel file from streams using “org.apache.commons.io.input.AutoCloseInputStream” API.
e.g.
Sample code:
1)

//**** Not working *****
InputStream inputStream = new org.apache.commons.io.input.AutoCloseInputStream(new java.io.BufferedInputStream(new FileInputStream("f:\\files\\empty.xlsx")));
new Workbook(inputStream);//not working - exception
//**** Working *****
//Workbook lWorkbook = new Workbook("f:\\files\\empty.xlsx");
//Or
InputStream input = new java.io.BufferedInputStream(new FileInputStream("f:\\files\\empty.xlsx"));
new Workbook(input);

To investigate your issue in details, I have logged a ticket with an id “CELLSJAVA-44763” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

Hi @Amjad_Sahi,

Yes, there are potentially two different issues here.

The way that org.apache.commons.io.input.AutoCloseInputStream implements java.io.FilterInputStream#markSupported, java.io.InputStream#mark and java.io.InputStream#reset might be questionable.

However, at least there is a clear bug in the Aspose Cells 22.7 code: in the handling of some caught exceptions, the (obfuscated) code in com.aspose.cells.b.a.f.u78.a makes a call to java.text.MessageFormat.format with invalid arguments, leading to a secondary exception in the process of handling the primary one. That bug, at the very least, should be fixed.

Kind regards,
Taras

@TarasTielkes,

Thanks for sharing your findings and further details.

Please spare us little time to evaluate your issue in details first then we can comment or provide details and our findings. If it is a bug in the APIs, it will be figured out.

@TarasTielkes,

This is to inform you that your issue (logged earlier as “CELLSJAVA-44763”) has been resolved now. The fix will be included in the next official release (Aspose.Cells v22.8) which is scheduled to be released in the second week of August 2022. You will also be notified when the next version is published.

Hi @Amjad_Sahi,

Does that fix relate to the invalid error message, or does the fix also provide a workaround for the arguably wrong implementation of AutoCloseInputStream?

Kind regards,
Taras

@TarasTielkes,

We fixed your issue in Aspose.Cells for Java API. We fixed a possible issue of String.Format() invocation in Aspose.Cells for Java API. We fixed the issue regarding Apache’s AutoCloseInputStream in our API.

May I ask what the “fix” is for the AutoCloseInputStream?
From my look at the implementation of that class, I think it is actually broken, in the sense that it does not return a consistent value from its java.io.InputStream#markSupported implementation, in some situations.

@TarasTielkes,

We will gather details and get back to you soon to provide for your queries/doubts.

@TarasTielkes
If the end of file is read with this class, the stream will be closed automatically.
Xlsx is a zip file which ends with the central directory record area. We read the file according to the size of each file in the compressed package to avoid reading the end of the file.

The issues you have found earlier (filed as CELLSJAVA-44763) have been fixed in this update. This message was posted using Bugs notification tool by Peyton.Xu