Program: 47095
Project: 47095
Buggy source:
/** 
 * Parse media via MediaInfo.
 */
public synchronized static void parse(DLNAMediaInfo media,InputFile inputFile,int type,RendererConfiguration renderer){
  File file=inputFile.getFile();
  if (!media.isMediaparsed() && file != null && MI.isValid() && MI.Open(file.getAbsolutePath()) > 0) {
    try {
      StreamType general=StreamType.General;
      StreamType video=StreamType.Video;
      StreamType audio=StreamType.Audio;
      StreamType image=StreamType.Image;
      StreamType text=StreamType.Text;
      DLNAMediaAudio currentAudioTrack=new DLNAMediaAudio();
      DLNAMediaSubtitle currentSubTrack;
      media.setSize(file.length());
      String value;
      getFormat(general,media,currentAudioTrack,MI.Get(general,0,"String_Node_Str"),file);
      getFormat(general,media,currentAudioTrack,MI.Get(general,0,"String_Node_Str").trim(),file);
      media.setDuration(getDuration(MI.Get(general,0,"String_Node_Str")));
      media.setBitrate(getBitrate(MI.Get(general,0,"String_Node_Str")));
      value=MI.Get(general,0,"String_Node_Str");
      if (!value.isEmpty()) {
        media.setThumb(new Base64().decode(value.getBytes(StandardCharsets.US_ASCII)));
      }
      value=MI.Get(general,0,"String_Node_Str");
      if (!value.isEmpty()) {
        media.setFileTitleFromMetadata(value);
      }
      value=MI.Get(general,0,"String_Node_Str");
      if (!value.isEmpty()) {
        media.setEmbeddedFontExists(true);
      }
      media.setVideoTrackCount(MI.Count_Get(video));
      if (media.getVideoTrackCount() > 0) {
        for (int i=0; i < media.getVideoTrackCount(); i++) {
          if (MI.Get(video,i,"String_Node_Str").startsWith("String_Node_Str")) {
            currentSubTrack=new DLNAMediaSubtitle();
            currentSubTrack.setType(SubtitleType.valueOfLibMediaInfoCodec(MI.Get(video,i,"String_Node_Str")));
            currentSubTrack.setType(SubtitleType.valueOfLibMediaInfoCodec(MI.Get(video,i,"String_Node_Str")));
            currentSubTrack.setId(media.getSubtitleTracksList().size());
            addSub(currentSubTrack,media);
          }
 else {
            getFormat(video,media,currentAudioTrack,MI.Get(video,i,"String_Node_Str"),file);
            getFormat(video,media,currentAudioTrack,MI.Get(video,i,"String_Node_Str"),file);
            getFormat(video,media,currentAudioTrack,MI.Get(video,i,"String_Node_Str"),file);
            media.setWidth(getPixelValue(MI.Get(video,i,"String_Node_Str")));
            media.setHeight(getPixelValue(MI.Get(video,i,"String_Node_Str")));
            media.setMatrixCoefficients(MI.Get(video,i,"String_Node_Str"));
            media.setStereoscopy(MI.Get(video,i,"String_Node_Str"));
            media.setAspectRatioContainer(MI.Get(video,i,"String_Node_Str"));
            media.setAspectRatioVideoTrack(MI.Get(video,i,"String_Node_Str"));
            media.setFrameRate(getFPSValue(MI.Get(video,i,"String_Node_Str")));
            media.setFrameRateMode(getFrameRateModeValue(MI.Get(video,i,"String_Node_Str")));
            media.setReferenceFrameCount(getReferenceFrameCount(MI.Get(video,i,"String_Node_Str")));
            media.setVideoTrackTitleFromMetadata(MI.Get(video,i,"String_Node_Str"));
            value=MI.Get(video,i,"String_Node_Str");
            if (!value.isEmpty()) {
              media.putExtra(FormatConfiguration.MI_QPEL,value);
            }
            value=MI.Get(video,i,"String_Node_Str");
            if (!value.isEmpty()) {
              media.putExtra(FormatConfiguration.MI_GMC,value);
            }
            value=MI.Get(video,i,"String_Node_Str");
            if (!value.isEmpty()) {
              media.putExtra(FormatConfiguration.MI_GOP,value);
            }
            media.setMuxingMode(MI.Get(video,i,"String_Node_Str"));
            if (!media.isEncrypted()) {
              media.setEncrypted("String_Node_Str".equals(MI.Get(video,i,"String_Node_Str")));
            }
            value=MI.Get(video,i,"String_Node_Str");
            if (!value.isEmpty()) {
              try {
                media.setVideoBitDepth(Integer.parseInt(value));
              }
 catch (              NumberFormatException nfe) {
                LOGGER.debug("String_Node_Str" + value + "String_Node_Str");
              }
            }
          }
        }
      }
      int audioTracks=MI.Count_Get(audio);
      if (audioTracks > 0) {
        for (int i=0; i < audioTracks; i++) {
          currentAudioTrack=new DLNAMediaAudio();
          getFormat(audio,media,currentAudioTrack,MI.Get(audio,i,"String_Node_Str"),file);
          getFormat(audio,media,currentAudioTrack,MI.Get(audio,i,"String_Node_Str"),file);
          getFormat(audio,media,currentAudioTrack,MI.Get(audio,i,"String_Node_Str"),file);
          getFormat(audio,media,currentAudioTrack,MI.Get(audio,i,"String_Node_Str"),file);
          currentAudioTrack.setLang(getLang(MI.Get(audio,i,"String_Node_Str")));
          currentAudioTrack.setAudioTrackTitleFromMetadata((MI.Get(audio,i,"String_Node_Str")).trim());
          currentAudioTrack.getAudioProperties().setNumberOfChannels(MI.Get(audio,i,"String_Node_Str"));
          currentAudioTrack.setSampleFrequency(getSampleFrequency(MI.Get(audio,i,"String_Node_Str")));
          currentAudioTrack.setBitRate(getBitrate(MI.Get(audio,i,"String_Node_Str")));
          currentAudioTrack.setSongname(MI.Get(general,0,"String_Node_Str"));
          if (renderer.isPrependTrackNumbers() && currentAudioTrack.getTrack() > 0 && currentAudioTrack.getSongname() != null && currentAudioTrack.getSongname().length() > 0) {
            currentAudioTrack.setSongname(currentAudioTrack.getTrack() + "String_Node_Str" + currentAudioTrack.getSongname());
          }
          currentAudioTrack.setAlbum(MI.Get(general,0,"String_Node_Str"));
          currentAudioTrack.setArtist(MI.Get(general,0,"String_Node_Str"));
          currentAudioTrack.setGenre(MI.Get(general,0,"String_Node_Str"));
          String recordedDate=MI.Get(general,0,"String_Node_Str");
          Matcher matcher=yearPattern.matcher(recordedDate);
          if (matcher.matches()) {
            try {
              currentAudioTrack.setYear(Integer.parseInt(matcher.group(1)));
            }
 catch (            NumberFormatException nfe) {
              LOGGER.debug("String_Node_Str" + recordedDate + "String_Node_Str");
            }
          }
          value=MI.Get(audio,i,"String_Node_Str");
          if (!value.isEmpty()) {
            if (value.contains("String_Node_Str") && !FormatConfiguration.OGG.equals(media.getContainer())) {
              currentAudioTrack.setId(getSpecificID(value));
            }
 else {
              currentAudioTrack.setId(media.getAudioTracksList().size());
            }
          }
          value=MI.Get(general,i,"String_Node_Str");
          if (!value.isEmpty()) {
            try {
              currentAudioTrack.setTrack(Integer.parseInt(value));
            }
 catch (            NumberFormatException nfe) {
              LOGGER.debug("String_Node_Str" + value + "String_Node_Str");
            }
          }
          value=MI.Get(audio,i,"String_Node_Str");
          if (!value.isEmpty()) {
            try {
              currentAudioTrack.setBitsperSample(Integer.parseInt(value));
            }
 catch (            NumberFormatException nfe) {
              LOGGER.debug("String_Node_Str" + value + "String_Node_Str");
            }
          }
          addAudio(currentAudioTrack,media);
        }
      }
      media.setImageCount(MI.Count_Get(image));
      if (media.getImageCount() > 0) {
        getFormat(image,media,currentAudioTrack,MI.Get(image,0,"String_Node_Str"),file);
        media.setWidth(getPixelValue(MI.Get(image,0,"String_Node_Str")));
        media.setHeight(getPixelValue(MI.Get(image,0,"String_Node_Str")));
      }
      int subTracks=MI.Count_Get(text);
      if (subTracks > 0) {
        for (int i=0; i < subTracks; i++) {
          currentSubTrack=new DLNAMediaSubtitle();
          currentSubTrack.setType(SubtitleType.valueOfLibMediaInfoCodec(MI.Get(text,i,"String_Node_Str")));
          currentSubTrack.setType(SubtitleType.valueOfLibMediaInfoCodec(MI.Get(text,i,"String_Node_Str")));
          currentSubTrack.setLang(getLang(MI.Get(text,i,"String_Node_Str")));
          currentSubTrack.setSubtitlesTrackTitleFromMetadata((MI.Get(text,i,"String_Node_Str")).trim());
          value=MI.Get(text,i,"String_Node_Str");
          if (!value.isEmpty()) {
            if (value.contains("String_Node_Str") && !FormatConfiguration.OGG.equals(media.getContainer())) {
              currentSubTrack.setId(getSpecificID(value));
            }
 else {
              currentSubTrack.setId(media.getSubtitleTracksList().size());
            }
          }
          addSub(currentSubTrack,media);
        }
      }
      if (FormatConfiguration.MP4.equals(media.getContainer()) && isBlank(media.getCodecV()) && media.getAudioTracksList() != null && media.getAudioTracksList().size() == 1 && FormatConfiguration.AAC.equals(media.getAudioTracksList().get(0).getCodecA())) {
        media.setContainer(FormatConfiguration.AAC);
      }
      if (!media.is3d()) {
        String upperCaseFileName=file.getName().toUpperCase();
        if (upperCaseFileName.startsWith("String_Node_Str")) {
          LOGGER.debug("String_Node_Str" + file.getName());
          media.setStereoscopy(file.getName().substring(2,7));
        }
 else         if (upperCaseFileName.startsWith("String_Node_Str")) {
          LOGGER.debug("String_Node_Str" + file.getName());
          media.setStereoscopy(file.getName().substring(2,6));
        }
 else         if (upperCaseFileName.startsWith("String_Node_Str")) {
          LOGGER.debug("String_Node_Str" + file.getName());
          media.setStereoscopy(file.getName().substring(2,6));
        }
 else         if (upperCaseFileName.matches("String_Node_Str")) {
          LOGGER.debug("String_Node_Str" + file.getName());
          media.setStereoscopy("String_Node_Str");
        }
 else         if (upperCaseFileName.matches("String_Node_Str")) {
          LOGGER.debug("String_Node_Str" + file.getName());
          media.setStereoscopy("String_Node_Str");
        }
 else         if (upperCaseFileName.matches("String_Node_Str")) {
          if (media.getWidth() > 1920) {
            LOGGER.debug("String_Node_Str" + file.getName());
            media.setStereoscopy("String_Node_Str");
          }
 else {
            LOGGER.debug("String_Node_Str" + file.getName());
            media.setStereoscopy("String_Node_Str");
          }
        }
 else         if (upperCaseFileName.matches("String_Node_Str")) {
          if (media.getHeight() > 1080) {
            LOGGER.debug("String_Node_Str" + file.getName());
            media.setStereoscopy("String_Node_Str");
          }
 else {
            LOGGER.debug("String_Node_Str" + file.getName());
            media.setStereoscopy("String_Node_Str");
          }
        }
      }
      media.finalize(type,inputFile);
    }
 catch (    Exception e) {
      LOGGER.error("String_Node_Str",e);
    }
 finally {
      MI.Close();
      if (media.getContainer() == null) {
        media.setContainer(DLNAMediaLang.UND);
      }
      if (media.getCodecV() == null) {
        media.setCodecV(DLNAMediaLang.UND);
      }
      media.setMediaparsed(true);
    }
  }
}

Fixed version (ground truth):
/** 
 * Parse media via MediaInfo.
 */
public synchronized static void parse(DLNAMediaInfo media,InputFile inputFile,int type,RendererConfiguration renderer){
  File file=inputFile.getFile();
  if (!media.isMediaparsed() && file != null && MI.isValid() && MI.Open(file.getAbsolutePath()) > 0) {
    try {
      StreamType general=StreamType.General;
      StreamType video=StreamType.Video;
      StreamType audio=StreamType.Audio;
      StreamType image=StreamType.Image;
      StreamType text=StreamType.Text;
      DLNAMediaAudio currentAudioTrack=new DLNAMediaAudio();
      DLNAMediaSubtitle currentSubTrack;
      media.setSize(file.length());
      String value;
      getFormat(general,media,currentAudioTrack,MI.Get(general,0,"String_Node_Str"),file);
      getFormat(general,media,currentAudioTrack,MI.Get(general,0,"String_Node_Str").trim(),file);
      media.setDuration(getDuration(MI.Get(general,0,"String_Node_Str")));
      media.setBitrate(getBitrate(MI.Get(general,0,"String_Node_Str")));
      value=MI.Get(general,0,"String_Node_Str");
      if (!value.isEmpty()) {
        media.setThumb(new Base64().decode(value.getBytes(StandardCharsets.US_ASCII)));
      }
      value=MI.Get(general,0,"String_Node_Str");
      if (!value.isEmpty()) {
        media.setFileTitleFromMetadata(value);
      }
      value=MI.Get(general,0,"String_Node_Str");
      if (!value.isEmpty() && value.toLowerCase().contains("String_Node_Str")) {
        media.setEmbeddedFontExists(true);
      }
 else {
        media.setEmbeddedFontExists(false);
      }
      media.setVideoTrackCount(MI.Count_Get(video));
      if (media.getVideoTrackCount() > 0) {
        for (int i=0; i < media.getVideoTrackCount(); i++) {
          if (MI.Get(video,i,"String_Node_Str").startsWith("String_Node_Str")) {
            currentSubTrack=new DLNAMediaSubtitle();
            currentSubTrack.setType(SubtitleType.valueOfLibMediaInfoCodec(MI.Get(video,i,"String_Node_Str")));
            currentSubTrack.setType(SubtitleType.valueOfLibMediaInfoCodec(MI.Get(video,i,"String_Node_Str")));
            currentSubTrack.setId(media.getSubtitleTracksList().size());
            addSub(currentSubTrack,media);
          }
 else {
            getFormat(video,media,currentAudioTrack,MI.Get(video,i,"String_Node_Str"),file);
            getFormat(video,media,currentAudioTrack,MI.Get(video,i,"String_Node_Str"),file);
            getFormat(video,media,currentAudioTrack,MI.Get(video,i,"String_Node_Str"),file);
            media.setWidth(getPixelValue(MI.Get(video,i,"String_Node_Str")));
            media.setHeight(getPixelValue(MI.Get(video,i,"String_Node_Str")));
            media.setMatrixCoefficients(MI.Get(video,i,"String_Node_Str"));
            media.setStereoscopy(MI.Get(video,i,"String_Node_Str"));
            media.setAspectRatioContainer(MI.Get(video,i,"String_Node_Str"));
            media.setAspectRatioVideoTrack(MI.Get(video,i,"String_Node_Str"));
            media.setFrameRate(getFPSValue(MI.Get(video,i,"String_Node_Str")));
            media.setFrameRateMode(getFrameRateModeValue(MI.Get(video,i,"String_Node_Str")));
            media.setReferenceFrameCount(getReferenceFrameCount(MI.Get(video,i,"String_Node_Str")));
            media.setVideoTrackTitleFromMetadata(MI.Get(video,i,"String_Node_Str"));
            value=MI.Get(video,i,"String_Node_Str");
            if (!value.isEmpty()) {
              media.putExtra(FormatConfiguration.MI_QPEL,value);
            }
            value=MI.Get(video,i,"String_Node_Str");
            if (!value.isEmpty()) {
              media.putExtra(FormatConfiguration.MI_GMC,value);
            }
            value=MI.Get(video,i,"String_Node_Str");
            if (!value.isEmpty()) {
              media.putExtra(FormatConfiguration.MI_GOP,value);
            }
            media.setMuxingMode(MI.Get(video,i,"String_Node_Str"));
            if (!media.isEncrypted()) {
              media.setEncrypted("String_Node_Str".equals(MI.Get(video,i,"String_Node_Str")));
            }
            value=MI.Get(video,i,"String_Node_Str");
            if (!value.isEmpty()) {
              try {
                media.setVideoBitDepth(Integer.parseInt(value));
              }
 catch (              NumberFormatException nfe) {
                LOGGER.debug("String_Node_Str" + value + "String_Node_Str");
              }
            }
          }
        }
      }
      int audioTracks=MI.Count_Get(audio);
      if (audioTracks > 0) {
        for (int i=0; i < audioTracks; i++) {
          currentAudioTrack=new DLNAMediaAudio();
          getFormat(audio,media,currentAudioTrack,MI.Get(audio,i,"String_Node_Str"),file);
          getFormat(audio,media,currentAudioTrack,MI.Get(audio,i,"String_Node_Str"),file);
          getFormat(audio,media,currentAudioTrack,MI.Get(audio,i,"String_Node_Str"),file);
          getFormat(audio,media,currentAudioTrack,MI.Get(audio,i,"String_Node_Str"),file);
          currentAudioTrack.setLang(getLang(MI.Get(audio,i,"String_Node_Str")));
          currentAudioTrack.setAudioTrackTitleFromMetadata((MI.Get(audio,i,"String_Node_Str")).trim());
          currentAudioTrack.getAudioProperties().setNumberOfChannels(MI.Get(audio,i,"String_Node_Str"));
          currentAudioTrack.setSampleFrequency(getSampleFrequency(MI.Get(audio,i,"String_Node_Str")));
          currentAudioTrack.setBitRate(getBitrate(MI.Get(audio,i,"String_Node_Str")));
          currentAudioTrack.setSongname(MI.Get(general,0,"String_Node_Str"));
          if (renderer.isPrependTrackNumbers() && currentAudioTrack.getTrack() > 0 && currentAudioTrack.getSongname() != null && currentAudioTrack.getSongname().length() > 0) {
            currentAudioTrack.setSongname(currentAudioTrack.getTrack() + "String_Node_Str" + currentAudioTrack.getSongname());
          }
          currentAudioTrack.setAlbum(MI.Get(general,0,"String_Node_Str"));
          currentAudioTrack.setArtist(MI.Get(general,0,"String_Node_Str"));
          currentAudioTrack.setGenre(MI.Get(general,0,"String_Node_Str"));
          String recordedDate=MI.Get(general,0,"String_Node_Str");
          Matcher matcher=yearPattern.matcher(recordedDate);
          if (matcher.matches()) {
            try {
              currentAudioTrack.setYear(Integer.parseInt(matcher.group(1)));
            }
 catch (            NumberFormatException nfe) {
              LOGGER.debug("String_Node_Str" + recordedDate + "String_Node_Str");
            }
          }
          value=MI.Get(audio,i,"String_Node_Str");
          if (!value.isEmpty()) {
            if (value.contains("String_Node_Str") && !FormatConfiguration.OGG.equals(media.getContainer())) {
              currentAudioTrack.setId(getSpecificID(value));
            }
 else {
              currentAudioTrack.setId(media.getAudioTracksList().size());
            }
          }
          value=MI.Get(general,i,"String_Node_Str");
          if (!value.isEmpty()) {
            try {
              currentAudioTrack.setTrack(Integer.parseInt(value));
            }
 catch (            NumberFormatException nfe) {
              LOGGER.debug("String_Node_Str" + value + "String_Node_Str");
            }
          }
          value=MI.Get(audio,i,"String_Node_Str");
          if (!value.isEmpty()) {
            try {
              currentAudioTrack.setBitsperSample(Integer.parseInt(value));
            }
 catch (            NumberFormatException nfe) {
              LOGGER.debug("String_Node_Str" + value + "String_Node_Str");
            }
          }
          addAudio(currentAudioTrack,media);
        }
      }
      media.setImageCount(MI.Count_Get(image));
      if (media.getImageCount() > 0) {
        getFormat(image,media,currentAudioTrack,MI.Get(image,0,"String_Node_Str"),file);
        media.setWidth(getPixelValue(MI.Get(image,0,"String_Node_Str")));
        media.setHeight(getPixelValue(MI.Get(image,0,"String_Node_Str")));
      }
      int subTracks=MI.Count_Get(text);
      if (subTracks > 0) {
        for (int i=0; i < subTracks; i++) {
          currentSubTrack=new DLNAMediaSubtitle();
          currentSubTrack.setType(SubtitleType.valueOfLibMediaInfoCodec(MI.Get(text,i,"String_Node_Str")));
          currentSubTrack.setType(SubtitleType.valueOfLibMediaInfoCodec(MI.Get(text,i,"String_Node_Str")));
          currentSubTrack.setLang(getLang(MI.Get(text,i,"String_Node_Str")));
          currentSubTrack.setSubtitlesTrackTitleFromMetadata((MI.Get(text,i,"String_Node_Str")).trim());
          value=MI.Get(text,i,"String_Node_Str");
          if (!value.isEmpty()) {
            if (value.contains("String_Node_Str") && !FormatConfiguration.OGG.equals(media.getContainer())) {
              currentSubTrack.setId(getSpecificID(value));
            }
 else {
              currentSubTrack.setId(media.getSubtitleTracksList().size());
            }
          }
          addSub(currentSubTrack,media);
        }
      }
      if (FormatConfiguration.MP4.equals(media.getContainer()) && isBlank(media.getCodecV()) && media.getAudioTracksList() != null && media.getAudioTracksList().size() == 1 && FormatConfiguration.AAC.equals(media.getAudioTracksList().get(0).getCodecA())) {
        media.setContainer(FormatConfiguration.AAC);
      }
      if (!media.is3d()) {
        String upperCaseFileName=file.getName().toUpperCase();
        if (upperCaseFileName.startsWith("String_Node_Str")) {
          LOGGER.debug("String_Node_Str" + file.getName());
          media.setStereoscopy(file.getName().substring(2,7));
        }
 else         if (upperCaseFileName.startsWith("String_Node_Str")) {
          LOGGER.debug("String_Node_Str" + file.getName());
          media.setStereoscopy(file.getName().substring(2,6));
        }
 else         if (upperCaseFileName.startsWith("String_Node_Str")) {
          LOGGER.debug("String_Node_Str" + file.getName());
          media.setStereoscopy(file.getName().substring(2,6));
        }
 else         if (upperCaseFileName.matches("String_Node_Str")) {
          LOGGER.debug("String_Node_Str" + file.getName());
          media.setStereoscopy("String_Node_Str");
        }
 else         if (upperCaseFileName.matches("String_Node_Str")) {
          LOGGER.debug("String_Node_Str" + file.getName());
          media.setStereoscopy("String_Node_Str");
        }
 else         if (upperCaseFileName.matches("String_Node_Str")) {
          if (media.getWidth() > 1920) {
            LOGGER.debug("String_Node_Str" + file.getName());
            media.setStereoscopy("String_Node_Str");
          }
 else {
            LOGGER.debug("String_Node_Str" + file.getName());
            media.setStereoscopy("String_Node_Str");
          }
        }
 else         if (upperCaseFileName.matches("String_Node_Str")) {
          if (media.getHeight() > 1080) {
            LOGGER.debug("String_Node_Str" + file.getName());
            media.setStereoscopy("String_Node_Str");
          }
 else {
            LOGGER.debug("String_Node_Str" + file.getName());
            media.setStereoscopy("String_Node_Str");
          }
        }
      }
      media.finalize(type,inputFile);
    }
 catch (    Exception e) {
      LOGGER.error("String_Node_Str",e);
    }
 finally {
      MI.Close();
      if (media.getContainer() == null) {
        media.setContainer(DLNAMediaLang.UND);
      }
      if (media.getCodecV() == null) {
        media.setCodecV(DLNAMediaLang.UND);
      }
      media.setMediaparsed(true);
    }
  }
}