Program: 47047
Project: 47047
Buggy source:
/** 
 * Parses an image file and stores the results in the given  {@link DLNAMediaInfo}. Parsing is performed using both <a href=https://github.com/drewnoakes/metadata-extractor>Metadata Extractor</a> and   {@link ImageIO}. While Metadata Extractor offers more detailed information,   {@link ImageIO} offers information that is convenient forimage transformation with  {@link ImageIO}. Parsing will be performed if just one of the two methods produces results, but some details will be missing if either one failed. <p><b> This method consumes and closes   {@code inputStream}. </b>
 * @param file the {@link File} to parse.
 * @param media the {@link DLNAMediaInfo} instance to store the parsingresults to.
 * @throws IOException if an IO error occurs or no information can be parsed.
 */
public static void parseImage(File file,DLNAMediaInfo media) throws IOException {
  final int MAX_BUFFER=1048576;
  if (file == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (media == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  boolean trace=LOGGER.isTraceEnabled();
  if (trace) {
    LOGGER.trace("String_Node_Str",file.getAbsolutePath());
  }
  long size=file.length();
  ResettableInputStream inputStream=new ResettableInputStream(Files.newInputStream(file.toPath()),MAX_BUFFER);
  try {
    Metadata metadata=null;
    FileType fileType=null;
    try {
      fileType=FileTypeDetector.detectFileType(inputStream);
      metadata=getMetadata(inputStream,fileType);
    }
 catch (    IOException e) {
      metadata=new Metadata();
      LOGGER.debug("String_Node_Str",file.getAbsolutePath(),e.getMessage());
      LOGGER.trace("String_Node_Str",e);
    }
catch (    ImageProcessingException e) {
      metadata=new Metadata();
      LOGGER.debug("String_Node_Str",fileType.toString().toUpperCase(Locale.ROOT),file.getAbsolutePath(),e.getMessage());
      LOGGER.trace("String_Node_Str",e);
    }
    ImageFormat format=ImageFormat.toImageFormat(fileType);
    if (format == null || format == ImageFormat.TIFF) {
      ImageFormat tmpformat=ImageFormat.toImageFormat(metadata);
      if (tmpformat != null) {
        format=tmpformat;
      }
    }
    if (inputStream.isFullResetAvailable()) {
      inputStream.fullReset();
    }
 else {
      inputStream.close();
      inputStream=new ResettableInputStream(Files.newInputStream(file.toPath()),MAX_BUFFER);
    }
    ImageInfo imageInfo=null;
    try {
      imageInfo=ImageIOTools.readImageInfo(inputStream,size,metadata,false);
    }
 catch (    UnknownFormatException|IIOException|ParseException e) {
      if (format == null) {
        throw new UnknownFormatException("String_Node_Str" + file.getAbsolutePath() + "String_Node_Str",e);
      }
      LOGGER.debug("String_Node_Str",file.getAbsolutePath());
      LOGGER.trace("String_Node_Str",e.getMessage());
      if (metadata != null) {
        try {
          imageInfo=ImageInfo.create(metadata,format,size,true,true);
        }
 catch (        ParseException pe) {
          imageInfo=null;
          LOGGER.debug("String_Node_Str",file.getAbsolutePath(),pe.getMessage());
          LOGGER.trace("String_Node_Str",pe);
        }
      }
    }
    if (imageInfo == null && format == null) {
      throw new ParseException("String_Node_Str" + file.getAbsolutePath() + "String_Node_Str");
    }
    if (format == null) {
      format=imageInfo.getFormat();
    }
 else     if (imageInfo != null && imageInfo.getFormat() != null && format != imageInfo.getFormat()) {
      if (imageInfo.getFormat() == ImageFormat.TIFF && format.isRaw()) {
        if (format == ImageFormat.ARW && !isARW(metadata)) {
          format=ImageFormat.toImageFormat(metadata);
          if (format == null) {
            format=ImageFormat.TIFF;
          }
          LOGGER.trace("String_Node_Str",format,file.getAbsolutePath());
        }
 else {
          imageInfo=ImageInfo.create(imageInfo.getWidth(),imageInfo.getHeight(),format,size,imageInfo.getBitDepth(),imageInfo.getNumComponents(),imageInfo.getColorSpace(),imageInfo.getColorSpaceType(),metadata,false,imageInfo.isImageIOSupported());
          LOGGER.trace("String_Node_Str",format.toString(),file.getAbsolutePath());
        }
      }
 else {
        LOGGER.debug("String_Node_Str" + "String_Node_Str",file.getAbsolutePath(),format,imageInfo.getFormat(),imageInfo.getFormat());
        format=imageInfo.getFormat();
      }
    }
    media.setImageInfo(imageInfo);
    if (format != null) {
      media.setCodecV(format.toFormatConfiguration());
      media.setContainer(format.toFormatConfiguration());
    }
    if (trace) {
      LOGGER.trace("String_Node_Str",file.getName());
    }
  }
  finally {
    inputStream.close();
  }
}

Fixed version (ground truth):
/** 
 * Parses an image file and stores the results in the given  {@link DLNAMediaInfo}. Parsing is performed using both <a href=https://github.com/drewnoakes/metadata-extractor>Metadata Extractor</a> and   {@link ImageIO}. While Metadata Extractor offers more detailed information,   {@link ImageIO} offers information that is convenient forimage transformation with  {@link ImageIO}. Parsing will be performed if just one of the two methods produces results, but some details will be missing if either one failed. <p><b> This method consumes and closes   {@code inputStream}. </b>
 * @param file the {@link File} to parse.
 * @param media the {@link DLNAMediaInfo} instance to store the parsingresults to.
 * @throws IOException if an IO error occurs or no information can be parsed.
 */
public static void parseImage(File file,DLNAMediaInfo media) throws IOException {
  final int MAX_BUFFER=1048576;
  if (file == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (media == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  boolean trace=LOGGER.isTraceEnabled();
  if (trace) {
    LOGGER.trace("String_Node_Str",file.getAbsolutePath());
  }
  long size=file.length();
  ResettableInputStream inputStream=new ResettableInputStream(Files.newInputStream(file.toPath()),MAX_BUFFER);
  try {
    Metadata metadata=null;
    FileType fileType=null;
    try {
      fileType=FileTypeDetector.detectFileType(inputStream);
      metadata=getMetadata(inputStream,fileType);
    }
 catch (    IOException e) {
      metadata=new Metadata();
      LOGGER.debug("String_Node_Str",file.getAbsolutePath(),e.getMessage());
      LOGGER.trace("String_Node_Str",e);
    }
catch (    ImageProcessingException e) {
      metadata=new Metadata();
      LOGGER.debug("String_Node_Str",fileType.toString().toUpperCase(Locale.ROOT),file.getAbsolutePath(),e.getMessage());
      LOGGER.trace("String_Node_Str",e);
    }
    ImageFormat format=ImageFormat.toImageFormat(fileType);
    if (format == null || format == ImageFormat.TIFF) {
      ImageFormat tmpformat=ImageFormat.toImageFormat(metadata);
      if (tmpformat != null) {
        format=tmpformat;
      }
    }
    if (inputStream.isFullResetAvailable()) {
      inputStream.fullReset();
    }
 else {
      inputStream.close();
      inputStream=new ResettableInputStream(Files.newInputStream(file.toPath()),MAX_BUFFER);
    }
    ImageInfo imageInfo=null;
    try {
      imageInfo=ImageIOTools.readImageInfo(inputStream,size,metadata,false);
    }
 catch (    UnknownFormatException|IIOException|ParseException e) {
      if (format == null) {
        throw new UnknownFormatException("String_Node_Str" + file.getAbsolutePath() + "String_Node_Str",e);
      }
      LOGGER.debug("String_Node_Str",file.getAbsolutePath());
      LOGGER.trace("String_Node_Str",e.getMessage());
      if (metadata != null) {
        try {
          imageInfo=ImageInfo.create(metadata,format,size,true,true);
        }
 catch (        ParseException pe) {
          LOGGER.debug("String_Node_Str",file.getAbsolutePath(),pe.getMessage());
          LOGGER.trace("String_Node_Str",pe);
        }
      }
    }
    if (imageInfo == null && format == null) {
      throw new ParseException("String_Node_Str" + file.getAbsolutePath() + "String_Node_Str");
    }
    if (format == null) {
      format=imageInfo.getFormat();
    }
 else     if (imageInfo != null && imageInfo.getFormat() != null && format != imageInfo.getFormat()) {
      if (imageInfo.getFormat() == ImageFormat.TIFF && format.isRaw()) {
        if (format == ImageFormat.ARW && !isARW(metadata)) {
          format=ImageFormat.toImageFormat(metadata);
          if (format == null) {
            format=ImageFormat.TIFF;
          }
          LOGGER.trace("String_Node_Str",format,file.getAbsolutePath());
        }
 else {
          imageInfo=ImageInfo.create(imageInfo.getWidth(),imageInfo.getHeight(),format,size,imageInfo.getBitDepth(),imageInfo.getNumComponents(),imageInfo.getColorSpace(),imageInfo.getColorSpaceType(),metadata,false,imageInfo.isImageIOSupported());
          LOGGER.trace("String_Node_Str",format.toString(),file.getAbsolutePath());
        }
      }
 else {
        LOGGER.debug("String_Node_Str" + "String_Node_Str",file.getAbsolutePath(),format,imageInfo.getFormat(),imageInfo.getFormat());
        format=imageInfo.getFormat();
      }
    }
    media.setImageInfo(imageInfo);
    if (format != null) {
      media.setCodecV(format.toFormatConfiguration());
      media.setContainer(format.toFormatConfiguration());
    }
    if (trace) {
      LOGGER.trace("String_Node_Str",file.getName());
    }
  }
  finally {
    inputStream.close();
  }
}