Program: 76903
Project: 76903
Buggy source:
/** 
 * Draws image at the contentByte
 * @param image		the ImageArea specified from the layout
 */
protected void drawImage(IImageArea image){
  Image img=null;
  TranscoderInput ti=null;
  cb.saveState();
  ContainerPosition curPos;
  if (!containerStack.isEmpty())   curPos=(ContainerPosition)containerStack.peek();
 else   curPos=new ContainerPosition(0,0);
  int imageX=curPos.x + image.getX();
  int imageY=curPos.y + image.getY();
  IImageContent imageContent=((IImageContent)image.getContent());
  try {
    boolean isSvg=false;
switch (imageContent.getImageSource()) {
case IImageContent.IMAGE_FILE:
      if (null == imageContent.getURI())       return;
    if (imageContent.getURI().endsWith("String_Node_Str")) {
      isSvg=true;
      ti=new TranscoderInput(new FileInputStream(imageContent.getURI()));
    }
 else {
      img=Image.getInstance(imageContent.getURI());
    }
  break;
case IImageContent.IMAGE_URL:
if (null == imageContent.getURI()) return;
if (imageContent.getURI().endsWith("String_Node_Str")) {
isSvg=true;
ti=new TranscoderInput(imageContent.getURI());
}
 else {
img=Image.getInstance(imageContent.getURI());
}
break;
case IImageContent.IMAGE_NAME:
case IImageContent.IMAGE_EXPRESSION:
if (null == imageContent.getData()) return;
isSvg=((imageContent.getMIMEType() != null) && imageContent.getMIMEType().equalsIgnoreCase("String_Node_Str")) || ((imageContent.getURI() != null) && imageContent.getURI().toLowerCase().endsWith("String_Node_Str")) || ((imageContent.getExtension() != null) && imageContent.getExtension().toLowerCase().endsWith("String_Node_Str"));
if (isSvg) {
ti=new TranscoderInput(new ByteArrayInputStream(imageContent.getData()));
}
 else {
img=Image.getInstance(imageContent.getData());
}
}
if (!isSvg) {
cb.addImage(img,pdfMeasure(image.getWidth()),0f,0f,pdfMeasure(image.getHeight()),layoutAreaX2PDF(imageX),layoutAreaY2PDF(imageY,image.getHeight()));
}
 else {
try {
if (ti != null) {
double width=pdfMeasure(image.getWidth());
double height=pdfMeasure(image.getHeight());
double x=layoutAreaX2PDF(imageX);
double y=layoutAreaY2PDF(imageY,image.getHeight());
PdfTemplate template=cb.createTemplate(new Float(width).floatValue(),new Float(height).floatValue());
Graphics2D g2=template.createGraphics(new Float(width).floatValue(),new Float(height).floatValue());
PrintTranscoder prm=new PrintTranscoder();
prm.addTranscodingHint(PrintTranscoder.KEY_SCALE_TO_PAGE,new Boolean(true));
prm.transcode(ti,null);
PageFormat pg=new PageFormat();
Paper pp=new Paper();
pp.setSize(width,height);
pp.setImageableArea(0,0,width,height);
pg.setPaper(pp);
prm.print(g2,pg,0);
g2.dispose();
cb.addTemplate(template,new Float(x).floatValue(),new Float(y).floatValue());
}
}
 catch (Exception e) {
e.printStackTrace();
}
}
}
 catch (BadElementException bee) {
logger.log(Level.WARNING,bee.getMessage(),bee);
}
catch (IOException ioe) {
logger.log(Level.WARNING,ioe.getMessage(),ioe);
}
catch (DocumentException de) {
logger.log(Level.WARNING,de.getMessage(),de);
}
catch (Throwable t) {
logger.log(Level.WARNING,t.getMessage(),t);
}
cb.restoreState();
makeBookmark(image,curPos);
handleHyperlinkAction(image,curPos);
}

Fixed version (ground truth):
/** 
 * Draws image at the contentByte
 * @param image		the ImageArea specified from the layout
 */
protected void drawImage(IImageArea image){
  Image img=null;
  TranscoderInput ti=null;
  cb.saveState();
  ContainerPosition curPos;
  if (!containerStack.isEmpty())   curPos=(ContainerPosition)containerStack.peek();
 else   curPos=new ContainerPosition(0,0);
  int imageX=curPos.x + image.getX();
  int imageY=curPos.y + image.getY();
  IImageContent imageContent=((IImageContent)image.getContent());
  try {
    boolean isSvg=false;
switch (imageContent.getImageSource()) {
case IImageContent.IMAGE_FILE:
      if (null == imageContent.getURI())       return;
    if (imageContent.getURI().endsWith("String_Node_Str")) {
      isSvg=true;
      ti=new TranscoderInput(new FileInputStream(imageContent.getURI()));
    }
 else {
      URL url=new URL(imageContent.getURI());
      InputStream in=url.openStream();
      try {
        byte[] buffer=new byte[in.available()];
        in.read(buffer);
        img=Image.getInstance(buffer);
      }
 catch (      Exception ex) {
        logger.log(Level.WARNING,ex.getMessage(),ex);
      }
 finally {
        in.close();
      }
    }
  break;
case IImageContent.IMAGE_URL:
if (null == imageContent.getURI()) return;
if (imageContent.getURI().endsWith("String_Node_Str")) {
isSvg=true;
ti=new TranscoderInput(imageContent.getURI());
}
 else {
img=Image.getInstance(imageContent.getURI());
}
break;
case IImageContent.IMAGE_NAME:
case IImageContent.IMAGE_EXPRESSION:
if (null == imageContent.getData()) return;
isSvg=((imageContent.getMIMEType() != null) && imageContent.getMIMEType().equalsIgnoreCase("String_Node_Str")) || ((imageContent.getURI() != null) && imageContent.getURI().toLowerCase().endsWith("String_Node_Str")) || ((imageContent.getExtension() != null) && imageContent.getExtension().toLowerCase().endsWith("String_Node_Str"));
if (isSvg) {
ti=new TranscoderInput(new ByteArrayInputStream(imageContent.getData()));
}
 else {
img=Image.getInstance(imageContent.getData());
}
}
if (!isSvg) {
cb.addImage(img,pdfMeasure(image.getWidth()),0f,0f,pdfMeasure(image.getHeight()),layoutAreaX2PDF(imageX),layoutAreaY2PDF(imageY,image.getHeight()));
}
 else {
try {
if (ti != null) {
double width=pdfMeasure(image.getWidth());
double height=pdfMeasure(image.getHeight());
double x=layoutAreaX2PDF(imageX);
double y=layoutAreaY2PDF(imageY,image.getHeight());
PdfTemplate template=cb.createTemplate(new Float(width).floatValue(),new Float(height).floatValue());
Graphics2D g2=template.createGraphics(new Float(width).floatValue(),new Float(height).floatValue());
PrintTranscoder prm=new PrintTranscoder();
prm.addTranscodingHint(PrintTranscoder.KEY_SCALE_TO_PAGE,new Boolean(true));
prm.transcode(ti,null);
PageFormat pg=new PageFormat();
Paper pp=new Paper();
pp.setSize(width,height);
pp.setImageableArea(0,0,width,height);
pg.setPaper(pp);
prm.print(g2,pg,0);
g2.dispose();
cb.addTemplate(template,new Float(x).floatValue(),new Float(y).floatValue());
}
}
 catch (Exception e) {
e.printStackTrace();
}
}
}
 catch (BadElementException bee) {
logger.log(Level.WARNING,bee.getMessage(),bee);
}
catch (IOException ioe) {
logger.log(Level.WARNING,ioe.getMessage(),ioe);
}
catch (DocumentException de) {
logger.log(Level.WARNING,de.getMessage(),de);
}
catch (Throwable t) {
logger.log(Level.WARNING,t.getMessage(),t);
}
cb.restoreState();
makeBookmark(image,curPos);
handleHyperlinkAction(image,curPos);
}