Aspose cells breaks iterator interface

Hi,
we found an issue in the current aspose.Cells version 18.4, where the iterator breaks the java.util iterator interface

if you call iterator.hasnext() twice, then aspose.Cells move already to the next row instead of staying at the row :frowning:

it is similar to the issue in Aspose.Pdf which was already fixed TextFragmentCollection breaks Iterable interface - #6 by willspecht

Is it possible to fix it also for aspose.Cells?

I wrote a simple example for test (you just need also an example excel file):

	Path path = Paths.get("./Testdata.xlsx");

	Workbook workbook = null;

	try
	{
		ByteArrayInputStream stream = new ByteArrayInputStream(Files.readAllBytes(path));

		workbook = new Workbook(stream);
	}
	catch (Exception e)
	{
		// do nothing jon snow
	}


	Worksheet worksheet = workbook.getWorksheets().get(0);
	Cells cells = worksheet.getCells();
	Row row = null;

	@SuppressWarnings("unchecked")
	Iterator<Row> rowIt = cells.getRows().iterator();


	System.out.println(rowIt.hasNext());
	System.out.println(rowIt.hasNext());

	row = rowIt.next();

	System.out.println(row.get(0));

	// XXX

	@SuppressWarnings("unchecked")
	Iterator<Row> rowIt2 = cells.getRows().iterator();


	System.out.println(rowIt2.hasNext());

	row = rowIt2.next();

	System.out.println(row.get(0));


	// XXX
	ArrayList<String> al = new ArrayList<>();

	al.add("1");
	al.add("2");
	al.add("3");
	al.add("4");

	@SuppressWarnings("rawtypes")
	Iterator itr = al.iterator();


	System.out.println(itr.hasNext());
	System.out.println(itr.hasNext());

	Object element = itr.next();

	System.out.println(element);


	// XXX

	@SuppressWarnings("rawtypes")
	Iterator itr2 = al.iterator();


	System.out.println(itr2.hasNext());

	Object element2 = itr2.next();

	System.out.println(element2);

@rbi-sw-dev,

Thanks for the sample code with details.

After an initial test, I am able to observe the issue as you mentioned by using your sample code with a sample file (attached, it contains simple data). I found Aspose.Cells breaks iterator interface when calling Iterator.hasnext() twice. it moves already to the next row instead of staying at the row.
e.g
Sample code:

Path path = Paths.get("f:\\files\\Testdata12.xlsx"); 

Workbook workbook = null; 

try 
{ 
ByteArrayInputStream stream = new ByteArrayInputStream(Files.readAllBytes(path)); 

workbook = new Workbook(stream); 
} 
catch (Exception e) 
{ 
// do nothing jon snow 
} 


Worksheet worksheet = workbook.getWorksheets().get(0); 
Cells cells = worksheet.getCells(); 
Row row = null; 

@SuppressWarnings("unchecked") 
Iterator<Row> rowIt = cells.getRows().iterator(); 


System.out.println(rowIt.hasNext()); 
System.out.println(rowIt.hasNext()); 

row = rowIt.next(); 

System.out.println(row.get(0)); 

// XXX 

@SuppressWarnings("unchecked") 
Iterator<Row> rowIt2 = cells.getRows().iterator(); 


System.out.println(rowIt2.hasNext()); 

row = rowIt2.next(); 

System.out.println(row.get(0)); 


// XXX 
ArrayList<String> al = new ArrayList<>(); 

al.add("1"); 
al.add("2"); 
al.add("3"); 
al.add("4"); 

@SuppressWarnings("rawtypes") 
Iterator itr = al.iterator(); 


System.out.println(itr.hasNext()); 
System.out.println(itr.hasNext()); 

Object element = itr.next(); 

System.out.println(element); 


// XXX 

@SuppressWarnings("rawtypes") 
Iterator itr2 = al.iterator(); 


System.out.println(itr2.hasNext()); 

Object element2 = itr2.next(); 

System.out.println(element2); 

Output:

true
true
Aspose.Cells.Cell [ A2; ValueType : IsString; Value : dadsf ] --> Issue here.
true
Aspose.Cells.Cell [ A1; ValueType : IsNumeric; Value : 0 ]
true
true
1
true
1

I have logged a ticket with an id “CELLSJAVA-42616” for your issue. We will look into it soon.

Once we have an update on it, we will let you know here.
files1.zip (6.3 KB)

1 Like

@Amjad_Sahi

Thanks for using Aspose APIs.

This is to inform you that we have fixed your issue CELLSJAVA-42616 now. We will soon provide the fix after performing QA and including other enhancements and fixes.

1 Like

The issues you have found earlier (filed as CELLSJAVA-42616) have been fixed in Aspose.Cells for Java 18.5. Please also see the document for your reference: Installation|Documentation

1 Like