docs: @Override
      public IIOMetadata getImageMetadata(int imageIndex) throws IOException {
          // checkBounds needed, as we catch the IndexOutOfBoundsException below.
          checkBounds(imageIndex);
          initHeader(imageIndex);
  
          IIOMetadata imageMetadata;
  
          if (isLossless()) {
              return new JPEGImage10Metadata(segments);
          }
          else {
              try {
                  imageMetadata = delegate.getImageMetadata(0);
              }
              catch (IndexOutOfBoundsException knownIssue) {
                  // TMI-101: com.sun.imageio.plugins.jpeg.JPEGBuffer doesn't do proper sanity check of input data.
                  throw new IIOException("Corrupt JPEG data: Bad segment length", knownIssue);
              }
              catch (NegativeArraySizeException knownIssue) {
                  // Most likely from com.sun.imageio.plugins.jpeg.SOSMarkerSegment
                  throw new IIOException("Corrupt JPEG data: Bad component count", knownIssue);
              }
  
              if (imageMetadata != null && Arrays.asList(imageMetadata.getMetadataFormatNames()).contains(JPEGImage10MetadataCleaner.JAVAX_IMAGEIO_JPEG_IMAGE_1_0)) {
                  if (metadataCleaner == null) {
                      metadataCleaner = new JPEGImage10MetadataCleaner(this);
                  }
  
                  return metadataCleaner.cleanMetadata(imageMetadata);
              }
          }
  
          return imageMetadata;
      }