Program: 107635
Project: 107635
Buggy source:
/** 
 * Gets a <tt>List</tt> of the <tt>AudioFormat</tt>s supported by a specific <tt>IAudioClient</tt>.
 * @param iAudioClient the <tt>IAudioClient</tt> to get the <tt>List</tt> ofsupported <tt>AudioFormat</tt>s of
 * @return a <tt>List</tt> of the <tt>AudioFormat</tt>s supported by thespecified <tt>iAudioClient</tt>
 * @throws HResultException if an error occurs while retrieving the<tt>List</tt> of <tt>AudioFormat</tt>s supported by the specified <tt>iAudioClient</tt> in a native WASAPI function which returns an <tt>HRESULT</tt> value
 */
private List<AudioFormat> getIAudioClientSupportedFormats(long iAudioClient) throws HResultException {
  char cbSize=0;
  List<AudioFormat> supportedFormats=new ArrayList<AudioFormat>();
  for (char nChannels=1; nChannels <= 2; nChannels++) {
    for (int i=0; i < Constants.AUDIO_SAMPLE_RATES.length; i++) {
      int nSamplesPerSec=(int)Constants.AUDIO_SAMPLE_RATES[i];
      for (char wBitsPerSample=16; wBitsPerSample > 0; wBitsPerSample-=8) {
        char nBlockAlign=(char)((nChannels * wBitsPerSample) / 8);
        WASAPI.WAVEFORMATEX_fill(waveformatex,WAVE_FORMAT_PCM,nChannels,nSamplesPerSec,nSamplesPerSec * nBlockAlign,nBlockAlign,wBitsPerSample,cbSize);
        long pClosestMatch=IAudioClient_IsFormatSupported(iAudioClient,AUDCLNT_SHAREMODE_SHARED,waveformatex);
        if (pClosestMatch == 0)         continue;
        try {
          if (pClosestMatch != waveformatex) {
            if (WAVEFORMATEX_getWFormatTag(pClosestMatch) != WAVE_FORMAT_PCM)             continue;
            nChannels=WAVEFORMATEX_getNChannels(pClosestMatch);
            nSamplesPerSec=WAVEFORMATEX_getNSamplesPerSec(pClosestMatch);
            wBitsPerSample=WAVEFORMATEX_getWBitsPerSample(pClosestMatch);
          }
          AudioFormat supportedFormat;
          if (nChannels == 2) {
            supportedFormat=new AudioFormat(AudioFormat.LINEAR,nSamplesPerSec,wBitsPerSample,1,AudioFormat.LITTLE_ENDIAN,AudioFormat.SIGNED,Format.NOT_SPECIFIED,Format.NOT_SPECIFIED,Format.byteArray);
            if (!supportedFormats.contains(supportedFormat))             supportedFormats.add(supportedFormat);
          }
          supportedFormat=new AudioFormat(AudioFormat.LINEAR,nSamplesPerSec,wBitsPerSample,nChannels,AudioFormat.LITTLE_ENDIAN,AudioFormat.SIGNED,Format.NOT_SPECIFIED,Format.NOT_SPECIFIED,Format.byteArray);
          if (!supportedFormats.contains(supportedFormat))           supportedFormats.add(supportedFormat);
        }
  finally {
          if (pClosestMatch != waveformatex)           CoTaskMemFree(pClosestMatch);
        }
      }
    }
  }
  return supportedFormats;
}

Fixed version (ground truth):
/** 
 * Gets a <tt>List</tt> of the <tt>AudioFormat</tt>s supported by a specific <tt>IAudioClient</tt>.
 * @param iAudioClient the <tt>IAudioClient</tt> to get the <tt>List</tt> ofsupported <tt>AudioFormat</tt>s of
 * @return a <tt>List</tt> of the <tt>AudioFormat</tt>s supported by thespecified <tt>iAudioClient</tt>
 * @throws HResultException if an error occurs while retrieving the<tt>List</tt> of <tt>AudioFormat</tt>s supported by the specified <tt>iAudioClient</tt> in a native WASAPI function which returns an <tt>HRESULT</tt> value
 */
private List<AudioFormat> getIAudioClientSupportedFormats(long iAudioClient) throws HResultException {
  char cbSize=0;
  List<AudioFormat> supportedFormats=new ArrayList<AudioFormat>();
  for (char nChannels=1; nChannels <= 2; nChannels++) {
    for (int i=0; i < Constants.AUDIO_SAMPLE_RATES.length; i++) {
      int nSamplesPerSec=(int)Constants.AUDIO_SAMPLE_RATES[i];
      for (char wBitsPerSample=16; wBitsPerSample > 0; wBitsPerSample-=8) {
        char nBlockAlign=(char)((nChannels * wBitsPerSample) / 8);
        WASAPI.WAVEFORMATEX_fill(waveformatex,WAVE_FORMAT_PCM,nChannels,nSamplesPerSec,nSamplesPerSec * nBlockAlign,nBlockAlign,wBitsPerSample,cbSize);
        long pClosestMatch=IAudioClient_IsFormatSupported(iAudioClient,AUDCLNT_SHAREMODE_SHARED,waveformatex);
        if (pClosestMatch == 0)         continue;
        try {
          if (pClosestMatch != waveformatex) {
            if (WAVEFORMATEX_getWFormatTag(pClosestMatch) != WAVE_FORMAT_PCM)             continue;
            nChannels=WAVEFORMATEX_getNChannels(pClosestMatch);
            nSamplesPerSec=WAVEFORMATEX_getNSamplesPerSec(pClosestMatch);
            wBitsPerSample=WAVEFORMATEX_getWBitsPerSample(pClosestMatch);
          }
          AudioFormat supportedFormat;
          if (nChannels == 2) {
            supportedFormat=new NativelySupportedAudioFormat(AudioFormat.LINEAR,nSamplesPerSec,wBitsPerSample,1,AudioFormat.LITTLE_ENDIAN,AudioFormat.SIGNED,Format.NOT_SPECIFIED,Format.NOT_SPECIFIED,Format.byteArray);
            if (!supportedFormats.contains(supportedFormat))             supportedFormats.add(supportedFormat);
          }
          supportedFormat=new NativelySupportedAudioFormat(AudioFormat.LINEAR,nSamplesPerSec,wBitsPerSample,nChannels,AudioFormat.LITTLE_ENDIAN,AudioFormat.SIGNED,Format.NOT_SPECIFIED,Format.NOT_SPECIFIED,Format.byteArray);
          if (!supportedFormats.contains(supportedFormat))           supportedFormats.add(supportedFormat);
        }
  finally {
          if (pClosestMatch != waveformatex)           CoTaskMemFree(pClosestMatch);
        }
      }
    }
  }
  return supportedFormats;
}