Program: 61479
Project: 61479
Buggy source:
public List<File> exportFrames(AbortRetryIgnoreHandler handler,String outdir,final SWF swf,int containerId,List<Integer> frames,final FrameExportSettings settings,final EventListener evl) throws IOException, InterruptedException {
  final List<File> ret=new ArrayList<>();
  if (swf.tags.isEmpty()) {
    return ret;
  }
  Timeline tim0;
  String path="String_Node_Str";
  if (containerId == 0) {
    tim0=swf.getTimeline();
  }
 else {
    tim0=((Timelined)swf.getCharacter(containerId)).getTimeline();
    path=File.separator + Helper.makeFileName(swf.getCharacter(containerId).getExportFileName());
  }
  final Timeline tim=tim0;
  if (frames == null) {
    int frameCnt=tim.getFrameCount();
    frames=new ArrayList<>();
    for (int i=0; i < frameCnt; i++) {
      frames.add(i);
    }
  }
  final File foutdir=new File(outdir + path);
  Path.createDirectorySafe(foutdir);
  final List<Integer> fframes=frames;
  Color backgroundColor=null;
  if (settings.mode == FrameExportMode.AVI) {
    for (    Tag t : swf.tags) {
      if (t instanceof SetBackgroundColorTag) {
        SetBackgroundColorTag sb=(SetBackgroundColorTag)t;
        backgroundColor=sb.backgroundColor.toColor();
      }
    }
  }
  if (settings.mode == FrameExportMode.SVG) {
    for (int i=0; i < frames.size(); i++) {
      if (evl != null) {
        evl.handleExportingEvent("String_Node_Str",i + 1,frames.size(),tim.parentTag == null ? "String_Node_Str" : tim.parentTag.getName());
      }
      final int fi=i;
      final Color fbackgroundColor=backgroundColor;
      new RetryTask(() -> {
        int frame=fframes.get(fi);
        File f=new File(foutdir + File.separator + frame+ "String_Node_Str");
        try (OutputStream fos=new BufferedOutputStream(new FileOutputStream(f))){
          ExportRectangle rect=new ExportRectangle(tim.displayRect);
          rect.xMax*=settings.zoom;
          rect.yMax*=settings.zoom;
          rect.xMin*=settings.zoom;
          rect.yMin*=settings.zoom;
          SVGExporter exporter=new SVGExporter(rect);
          if (fbackgroundColor != null) {
            exporter.setBackGroundColor(fbackgroundColor);
          }
          SWF.frameToSvg(tim,frame,0,null,0,exporter,new ColorTransform(),0,settings.zoom);
          fos.write(Utf8Helper.getBytes(exporter.getSVG()));
        }
         ret.add(f);
      }
,handler).run();
      if (evl != null) {
        evl.handleExportedEvent("String_Node_Str",i + 1,frames.size(),tim.parentTag == null ? "String_Node_Str" : tim.parentTag.getName());
      }
    }
    return ret;
  }
  if (settings.mode == FrameExportMode.CANVAS) {
    if (evl != null) {
      evl.handleExportingEvent("String_Node_Str",1,1,tim.parentTag == null ? "String_Node_Str" : tim.parentTag.getName());
    }
    final Timeline ftim=tim;
    final Color fbackgroundColor=backgroundColor;
    final SWF fswf=swf;
    new RetryTask(() -> {
      File fcanvas=new File(foutdir + File.separator + "String_Node_Str");
      Helper.saveStream(SWF.class.getClassLoader().getResourceAsStream("String_Node_Str"),fcanvas);
      ret.add(fcanvas);
      File f=new File(foutdir + File.separator + "String_Node_Str");
      File fmin=new File(foutdir + File.separator + "String_Node_Str");
      int width=(int)(ftim.displayRect.getWidth() * settings.zoom / SWF.unitDivisor);
      int height=(int)(ftim.displayRect.getHeight() * settings.zoom / SWF.unitDivisor);
      try (final OutputStream fos=new BufferedOutputStream(new FileOutputStream(f))){
        fos.write(Utf8Helper.getBytes("String_Node_Str"));
        Set<Integer> library=new HashSet<>();
        ftim.getNeededCharacters(fframes,library);
        SWF.writeLibrary(fswf,library,fos);
        String currentName=ftim.id == 0 ? "String_Node_Str" : SWF.getTypePrefix(fswf.getCharacter(ftim.id)) + ftim.id;
        StringBuilder sb=new StringBuilder();
        sb.append("String_Node_Str").append(currentName).append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str").append(-ftim.displayRect.Xmin * settings.zoom / SWF.unitDivisor).append("String_Node_Str").append(-ftim.displayRect.Ymin * settings.zoom / SWF.unitDivisor).append("String_Node_Str");
        framesToHtmlCanvas(sb,SWF.unitDivisor / settings.zoom,ftim,fframes,0,null,0,ftim.displayRect,new ColorTransform(),fbackgroundColor);
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        for (        int i : fframes) {
          sb.append("String_Node_Str").append(i).append("String_Node_Str");
        }
        sb.append("String_Node_Str");
        RGB backgroundColor1=new RGB(255,255,255);
        for (        Tag t : fswf.tags) {
          if (t instanceof SetBackgroundColorTag) {
            SetBackgroundColorTag sbgct=(SetBackgroundColorTag)t;
            backgroundColor1=sbgct.backgroundColor;
          }
        }
        sb.append("String_Node_Str").append(backgroundColor1.toHexRGB()).append("String_Node_Str");
        sb.append("String_Node_Str").append(width).append("String_Node_Str");
        sb.append("String_Node_Str").append(height).append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str").append(currentName).append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        if (ftim.swf.frameRate > 0) {
          sb.append("String_Node_Str").append((int)(1000.0 / ftim.swf.frameRate)).append("String_Node_Str");
        }
        sb.append("String_Node_Str");
        fos.write(Utf8Helper.getBytes(sb.toString()));
      }
       boolean packed=false;
      if (Configuration.packJavaScripts.get()) {
        try {
          JPacker.main(new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",fmin.getAbsolutePath(),f.getAbsolutePath()});
          f.delete();
          packed=true;
        }
 catch (        Exception|Error e) {
          logger.log(Level.WARNING,"String_Node_Str");
          f.renameTo(fmin);
        }
      }
 else {
        f.renameTo(fmin);
      }
      File fh=new File(foutdir + File.separator + "String_Node_Str");
      try (OutputStream fos=new BufferedOutputStream(new FileOutputStream(fh));FileInputStream fis=new FileInputStream(fmin)){
        fos.write(Utf8Helper.getBytes(CanvasShapeExporter.getHtmlPrefix(width,height)));
        fos.write(Utf8Helper.getBytes(CanvasShapeExporter.getJsPrefix()));
        byte[] buf=new byte[1000];
        int cnt;
        while ((cnt=fis.read(buf)) > 0) {
          fos.write(buf,0,cnt);
        }
        if (packed) {
          fos.write(Utf8Helper.getBytes("String_Node_Str"));
        }
        fos.write(Utf8Helper.getBytes(CanvasShapeExporter.getJsSuffix()));
        fos.write(Utf8Helper.getBytes(CanvasShapeExporter.getHtmlSuffix()));
      }
       fmin.delete();
      ret.add(f);
    }
,handler).run();
    if (evl != null) {
      evl.handleExportedEvent("String_Node_Str",1,1,tim.parentTag == null ? "String_Node_Str" : tim.parentTag.getName());
    }
    return ret;
  }
  final Timeline ftim=tim;
  final Color fbackgroundColor=backgroundColor;
  final Iterator<BufferedImage> frameImages=new Iterator<BufferedImage>(){
    private int pos=0;
    @Override public boolean hasNext(){
      return fframes.size() > pos;
    }
    @Override public void remove(){
      throw new UnsupportedOperationException();
    }
    @Override public BufferedImage next(){
      if (!hasNext()) {
        return null;
      }
      if (evl != null) {
        evl.handleExportingEvent("String_Node_Str",pos + 1,fframes.size(),tim.parentTag == null ? "String_Node_Str" : tim.parentTag.getName());
      }
      BufferedImage result=SWF.frameToImageGet(ftim,fframes.get(pos++),0,null,0,ftim.displayRect,new Matrix(),new ColorTransform(),fbackgroundColor,false,settings.zoom).getBufferedImage();
      if (evl != null) {
        evl.handleExportedEvent("String_Node_Str",pos,fframes.size(),tim.parentTag == null ? "String_Node_Str" : tim.parentTag.getName());
      }
      return result;
    }
  }
;
switch (settings.mode) {
case GIF:
    new RetryTask(() -> {
      File f=new File(foutdir + File.separator + "String_Node_Str");
      makeGIF(frameImages,swf.frameRate,f,evl);
      ret.add(f);
    }
,handler).run();
  break;
case BMP:
for (int i=0; frameImages.hasNext(); i++) {
  final int fi=i;
  new RetryTask(() -> {
    File f=new File(foutdir + File.separator + (fframes.get(fi) + 1)+ "String_Node_Str");
    BMPFile.saveBitmap(frameImages.next(),f);
    ret.add(f);
  }
,handler).run();
}
break;
case PNG:
for (int i=0; frameImages.hasNext(); i++) {
final int fi=i;
new RetryTask(() -> {
File file=new File(foutdir + File.separator + (fframes.get(fi) + 1)+ "String_Node_Str");
ImageHelper.write(frameImages.next(),ImageFormat.PNG,file);
ret.add(file);
}
,handler).run();
}
break;
case PDF:
if (frameImages.hasNext()) {
new RetryTask(() -> {
File f=new File(foutdir + File.separator + "String_Node_Str");
PDFJob job=new PDFJob(new BufferedOutputStream(new FileOutputStream(f)));
PageFormat pf=new PageFormat();
pf.setOrientation(PageFormat.PORTRAIT);
Paper p=new Paper();
BufferedImage img0=frameImages.next();
p.setSize(img0.getWidth() + 10,img0.getHeight() + 10);
pf.setPaper(p);
for (int i=0; frameImages.hasNext(); i++) {
BufferedImage img=frameImages.next();
Graphics g=job.getGraphics(pf);
g.drawImage(img,5,5,img.getWidth(),img.getHeight(),null);
g.dispose();
}
job.end();
ret.add(f);
}
,handler).run();
}
break;
case AVI:
new RetryTask(() -> {
File f=new File(foutdir + File.separator + "String_Node_Str");
makeAVI(frameImages,swf.frameRate,f,evl);
ret.add(f);
}
,handler).run();
break;
}
return ret;
}

Fixed version (ground truth):
public List<File> exportFrames(AbortRetryIgnoreHandler handler,String outdir,final SWF swf,int containerId,List<Integer> frames,final FrameExportSettings settings,final EventListener evl) throws IOException, InterruptedException {
  final List<File> ret=new ArrayList<>();
  if (swf.tags.isEmpty()) {
    return ret;
  }
  Timeline tim0;
  String path="String_Node_Str";
  if (containerId == 0) {
    tim0=swf.getTimeline();
  }
 else {
    tim0=((Timelined)swf.getCharacter(containerId)).getTimeline();
    path=File.separator + Helper.makeFileName(swf.getCharacter(containerId).getExportFileName());
  }
  final Timeline tim=tim0;
  if (frames == null) {
    int frameCnt=tim.getFrameCount();
    frames=new ArrayList<>();
    for (int i=0; i < frameCnt; i++) {
      frames.add(i);
    }
  }
  final File foutdir=new File(outdir + path);
  Path.createDirectorySafe(foutdir);
  final List<Integer> fframes=frames;
  Color backgroundColor=null;
  SetBackgroundColorTag setBgColorTag=swf.getBackgroundColor();
  if (setBgColorTag != null) {
    backgroundColor=setBgColorTag.backgroundColor.toColor();
  }
  if (settings.mode == FrameExportMode.SVG) {
    for (int i=0; i < frames.size(); i++) {
      if (evl != null) {
        evl.handleExportingEvent("String_Node_Str",i + 1,frames.size(),tim.parentTag == null ? "String_Node_Str" : tim.parentTag.getName());
      }
      final int fi=i;
      final Color fbackgroundColor=null;
      new RetryTask(() -> {
        int frame=fframes.get(fi);
        File f=new File(foutdir + File.separator + frame+ "String_Node_Str");
        try (OutputStream fos=new BufferedOutputStream(new FileOutputStream(f))){
          ExportRectangle rect=new ExportRectangle(tim.displayRect);
          rect.xMax*=settings.zoom;
          rect.yMax*=settings.zoom;
          rect.xMin*=settings.zoom;
          rect.yMin*=settings.zoom;
          SVGExporter exporter=new SVGExporter(rect);
          if (fbackgroundColor != null) {
            exporter.setBackGroundColor(fbackgroundColor);
          }
          SWF.frameToSvg(tim,frame,0,null,0,exporter,new ColorTransform(),0,settings.zoom);
          fos.write(Utf8Helper.getBytes(exporter.getSVG()));
        }
         ret.add(f);
      }
,handler).run();
      if (evl != null) {
        evl.handleExportedEvent("String_Node_Str",i + 1,frames.size(),tim.parentTag == null ? "String_Node_Str" : tim.parentTag.getName());
      }
    }
    return ret;
  }
  if (settings.mode == FrameExportMode.CANVAS) {
    if (evl != null) {
      evl.handleExportingEvent("String_Node_Str",1,1,tim.parentTag == null ? "String_Node_Str" : tim.parentTag.getName());
    }
    final Timeline ftim=tim;
    final Color fbackgroundColor=null;
    final SWF fswf=swf;
    new RetryTask(() -> {
      File fcanvas=new File(foutdir + File.separator + "String_Node_Str");
      Helper.saveStream(SWF.class.getClassLoader().getResourceAsStream("String_Node_Str"),fcanvas);
      ret.add(fcanvas);
      File f=new File(foutdir + File.separator + "String_Node_Str");
      File fmin=new File(foutdir + File.separator + "String_Node_Str");
      int width=(int)(ftim.displayRect.getWidth() * settings.zoom / SWF.unitDivisor);
      int height=(int)(ftim.displayRect.getHeight() * settings.zoom / SWF.unitDivisor);
      try (final OutputStream fos=new BufferedOutputStream(new FileOutputStream(f))){
        fos.write(Utf8Helper.getBytes("String_Node_Str"));
        Set<Integer> library=new HashSet<>();
        ftim.getNeededCharacters(fframes,library);
        SWF.writeLibrary(fswf,library,fos);
        String currentName=ftim.id == 0 ? "String_Node_Str" : SWF.getTypePrefix(fswf.getCharacter(ftim.id)) + ftim.id;
        StringBuilder sb=new StringBuilder();
        sb.append("String_Node_Str").append(currentName).append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str").append(-ftim.displayRect.Xmin * settings.zoom / SWF.unitDivisor).append("String_Node_Str").append(-ftim.displayRect.Ymin * settings.zoom / SWF.unitDivisor).append("String_Node_Str");
        framesToHtmlCanvas(sb,SWF.unitDivisor / settings.zoom,ftim,fframes,0,null,0,ftim.displayRect,new ColorTransform(),fbackgroundColor);
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        for (        int i : fframes) {
          sb.append("String_Node_Str").append(i).append("String_Node_Str");
        }
        sb.append("String_Node_Str");
        RGB backgroundColor1=new RGB(255,255,255);
        if (setBgColorTag != null) {
          backgroundColor1=setBgColorTag.backgroundColor;
        }
        sb.append("String_Node_Str").append(backgroundColor1.toHexRGB()).append("String_Node_Str");
        sb.append("String_Node_Str").append(width).append("String_Node_Str");
        sb.append("String_Node_Str").append(height).append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str").append(currentName).append("String_Node_Str");
        sb.append("String_Node_Str");
        sb.append("String_Node_Str");
        if (ftim.swf.frameRate > 0) {
          sb.append("String_Node_Str").append((int)(1000.0 / ftim.swf.frameRate)).append("String_Node_Str");
        }
        sb.append("String_Node_Str");
        fos.write(Utf8Helper.getBytes(sb.toString()));
      }
       boolean packed=false;
      if (Configuration.packJavaScripts.get()) {
        try {
          JPacker.main(new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",fmin.getAbsolutePath(),f.getAbsolutePath()});
          f.delete();
          packed=true;
        }
 catch (        Exception|Error e) {
          logger.log(Level.WARNING,"String_Node_Str");
          f.renameTo(fmin);
        }
      }
 else {
        f.renameTo(fmin);
      }
      File fh=new File(foutdir + File.separator + "String_Node_Str");
      try (OutputStream fos=new BufferedOutputStream(new FileOutputStream(fh));FileInputStream fis=new FileInputStream(fmin)){
        fos.write(Utf8Helper.getBytes(CanvasShapeExporter.getHtmlPrefix(width,height)));
        fos.write(Utf8Helper.getBytes(CanvasShapeExporter.getJsPrefix()));
        byte[] buf=new byte[1000];
        int cnt;
        while ((cnt=fis.read(buf)) > 0) {
          fos.write(buf,0,cnt);
        }
        if (packed) {
          fos.write(Utf8Helper.getBytes("String_Node_Str"));
        }
        fos.write(Utf8Helper.getBytes(CanvasShapeExporter.getJsSuffix()));
        fos.write(Utf8Helper.getBytes(CanvasShapeExporter.getHtmlSuffix()));
      }
       fmin.delete();
      ret.add(f);
    }
,handler).run();
    if (evl != null) {
      evl.handleExportedEvent("String_Node_Str",1,1,tim.parentTag == null ? "String_Node_Str" : tim.parentTag.getName());
    }
    return ret;
  }
  final Timeline ftim=tim;
  final Color fbackgroundColor=backgroundColor;
  final Iterator<BufferedImage> frameImages=new Iterator<BufferedImage>(){
    private int pos=0;
    @Override public boolean hasNext(){
      return fframes.size() > pos;
    }
    @Override public void remove(){
      throw new UnsupportedOperationException();
    }
    @Override public BufferedImage next(){
      if (!hasNext()) {
        return null;
      }
      if (evl != null) {
        evl.handleExportingEvent("String_Node_Str",pos + 1,fframes.size(),tim.parentTag == null ? "String_Node_Str" : tim.parentTag.getName());
      }
      BufferedImage result=SWF.frameToImageGet(ftim,fframes.get(pos++),0,null,0,ftim.displayRect,new Matrix(),new ColorTransform(),fbackgroundColor,false,settings.zoom).getBufferedImage();
      if (evl != null) {
        evl.handleExportedEvent("String_Node_Str",pos,fframes.size(),tim.parentTag == null ? "String_Node_Str" : tim.parentTag.getName());
      }
      return result;
    }
  }
;
switch (settings.mode) {
case GIF:
    new RetryTask(() -> {
      File f=new File(foutdir + File.separator + "String_Node_Str");
      makeGIF(frameImages,swf.frameRate,f,evl);
      ret.add(f);
    }
,handler).run();
  break;
case BMP:
for (int i=0; frameImages.hasNext(); i++) {
  final int fi=i;
  new RetryTask(() -> {
    File f=new File(foutdir + File.separator + (fframes.get(fi) + 1)+ "String_Node_Str");
    BMPFile.saveBitmap(frameImages.next(),f);
    ret.add(f);
  }
,handler).run();
}
break;
case PNG:
for (int i=0; frameImages.hasNext(); i++) {
final int fi=i;
new RetryTask(() -> {
File file=new File(foutdir + File.separator + (fframes.get(fi) + 1)+ "String_Node_Str");
ImageHelper.write(frameImages.next(),ImageFormat.PNG,file);
ret.add(file);
}
,handler).run();
}
break;
case PDF:
if (frameImages.hasNext()) {
new RetryTask(() -> {
File f=new File(foutdir + File.separator + "String_Node_Str");
PDFJob job=new PDFJob(new BufferedOutputStream(new FileOutputStream(f)));
PageFormat pf=new PageFormat();
pf.setOrientation(PageFormat.PORTRAIT);
Paper p=new Paper();
BufferedImage img0=frameImages.next();
p.setSize(img0.getWidth() + 10,img0.getHeight() + 10);
pf.setPaper(p);
for (int i=0; frameImages.hasNext(); i++) {
BufferedImage img=frameImages.next();
Graphics g=job.getGraphics(pf);
g.drawImage(img,5,5,img.getWidth(),img.getHeight(),null);
g.dispose();
}
job.end();
ret.add(f);
}
,handler).run();
}
break;
case AVI:
new RetryTask(() -> {
File f=new File(foutdir + File.separator + "String_Node_Str");
makeAVI(frameImages,swf.frameRate,f,evl);
ret.add(f);
}
,handler).run();
break;
}
return ret;
}