Free Support Forum -

Java Iterator contract seems to be broken in Aspose Slides collections


like in

I think I have found that the Aspose Slides for Java API breaks the contract for java.util.Iterator in the implemantation of com.aspose.slides.ISlideCollection and com.aspose.slides.IShapeCollection.

The call to .hasNext() has the side effect to progress the iterator one step further.
That should be the job of .next(), which .next() does not perform. .nect() seems to have has no sideeffects.

A call to .next() with no prior .hasNext() always returns null, even for filled collections. Which is also not as expected.

I found that behavior in Version 19.1 and 20.4.

I have some example code to demonstrate this:

  // //////////////////////////////////////////////////////////////////////////////////////////////////

    package de.demo;

    import java.util.Iterator;
    import com.aspose.slides.*;

    public class App
        public static void main( String[] args )
           IPresentation presentation = new Presentation("folienpool.pptx");
        System.out.println("First slides:");

        ISlideCollection slides = presentation.getSlides();
        Iterator<ISlide>  slides_iter;

        slides_iter= slides.iterator();

        System.out.println("1. Slides: .next()-> " +;

        slides_iter = slides.iterator();
        System.out.println("2. Slides: .hasNext() .next()-> " +;

        slides_iter = slides.iterator();
        System.out.println("3. Slides: .hasNext() .next()-> " +;

        slides_iter = slides.iterator();
        System.out.println("4. Slides: .hasNext() : .hasNext() .next()-> " +;

        slides_iter = slides.iterator();
        System.out.println("5. Slides: .hasNext() .next() .next() -> " +;

        System.out.println("Now Shapes:");

        ISlide slide = slides.get_Item(31);
        IShapeCollection shapes = slide.getShapes();
        Iterator<IShape>  shape_iter;

        shape_iter= shapes.iterator();

        System.out.println("6. Shapes: .next() -> " +;

        shape_iter = shapes.iterator();
        System.out.println("7. Shapes: .hasNext() .next() -> " +;

        shape_iter = shapes.iterator();
        System.out.println("8. Shapes: .hasNext() .next() -> " +;

        shape_iter = shapes.iterator();
        System.out.println("9. Shapes: .hasNext() .hasNext() .next() -> " +;

        shape_iter = shapes.iterator();
        System.out.println("10. Shapes: .hasNext() .next() .next() -> " +;


// //////////////////////////////////////////////////////////////////////////////////////////////////

Example output:

First slides:

  1. Slides: .next()-> null
  2. Slides: .hasNext() .next()-> com.aspose.slides.Slide@27210a3b
  3. Slides: .hasNext() .next()-> com.aspose.slides.Slide@27210a3b
  4. Slides: .hasNext() : .hasNext() .next()-> com.aspose.slides.Slide@3a12f3e7
  5. Slides: .hasNext() .next() .next() -> com.aspose.slides.Slide@27210a3b
    Now Shapes:
  6. Shapes: .next() -> null
  7. Shapes: .hasNext() .next() -> com.aspose.slides.Table@84a9f65
  8. Shapes: .hasNext() .next() -> com.aspose.slides.Table@84a9f65
  9. Shapes: .hasNext() .hasNext() .next() -> com.aspose.slides.AutoShape@70700b8a
  10. Shapes: .hasNext() .next() .next() -> com.aspose.slides.Table@84a9f65


What I would expect for slides is:
1 = 2 = 3 = 4 = com.aspose.slides.Slide@27210a3b


5 = com.aspose.slides.Slide@3a12f3e7

And for shapes:
6 = 7= 8 = 9 = com.aspose.slides.Table@84a9f65
10 = com.aspose.slides.AutoShape@70700b8a

Kind regards,

Uwe Hubert


I have observed the issue shared by you and request you to please share the source file that you have used on your end too so that I may log issue.

The operating system is Linux Ubuntu 20.04 LTS.

java -version
openjdk version “1.8.0_252”
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1ubuntu1-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode) (587 Bytes)


I have observed the sample code but it is still missing the source file used to reproduce the issue.Please share the requested information

When you mean with “source file” the .pptx slides file, here it (33.7 KB)

The Java source file is in the attachment of my last response.


I have observed the issue shared and have created a ticket with ID SLIDESJAVA-38108 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.