Program: 76567
Project: 76567
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;
    URL url=reportDesign.findResource(imageContent.getURI(),IResourceLocator.IMAGE);
  InputStream in=url.openStream();
if (imageContent.getURI().endsWith("String_Node_Str")) {
  isSvg=true;
  ti=new TranscoderInput(in);
}
 else {
  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);
}

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;
    URL url=reportDesign.findResource(imageContent.getURI(),IResourceLocator.IMAGE);
  InputStream in=url.openStream();
if (imageContent.getURI().endsWith("String_Node_Str")) {
  isSvg=true;
  ti=new TranscoderInput(in);
}
 else {
  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());
}
}
float width=pdfMeasure(image.getWidth());
float height=pdfMeasure(image.getHeight());
float x=layoutAreaX2PDF(imageX);
float y=layoutAreaY2PDF(imageY,image.getHeight());
if (!isSvg) {
cb.addImage(img,width,0f,0f,height,x,y);
String helpText=imageContent.getHelpText();
if (helpText != null) {
showHelpText(x,y,width,height,helpText);
}
}
 else {
try {
if (ti != null) {
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);
}