Program: 183465
Project: 183465
Buggy source:
private Uri endFile(FileCacheEntry entry,boolean ringtones,boolean notifications,boolean alarms,boolean music,boolean podcasts) throws RemoteException {
  Uri tableUri;
  boolean isAudio=MediaFile.isAudioFileType(mFileType);
  boolean isVideo=MediaFile.isVideoFileType(mFileType);
  boolean isImage=MediaFile.isImageFileType(mFileType);
  if (isVideo) {
    tableUri=mVideoUri;
  }
 else   if (isImage) {
    tableUri=mImagesUri;
  }
 else   if (isAudio) {
    tableUri=mAudioUri;
  }
 else {
    return null;
  }
  entry.mTableUri=tableUri;
  if (mArtist == null || mArtist.length() == 0) {
    mArtist=mAlbumArtist;
  }
  ContentValues values=toValues();
  String title=values.getAsString(MediaStore.MediaColumns.TITLE);
  if (TextUtils.isEmpty(title)) {
    title=values.getAsString(MediaStore.MediaColumns.DATA);
    int lastSlash=title.lastIndexOf('/');
    if (lastSlash >= 0) {
      lastSlash++;
      if (lastSlash < title.length()) {
        title=title.substring(lastSlash);
      }
    }
    int lastDot=title.lastIndexOf('.');
    if (lastDot > 0) {
      title=title.substring(0,lastDot);
    }
    values.put(MediaStore.MediaColumns.TITLE,title);
  }
  if (isAudio) {
    values.put(Audio.Media.IS_RINGTONE,ringtones);
    values.put(Audio.Media.IS_NOTIFICATION,notifications);
    values.put(Audio.Media.IS_ALARM,alarms);
    values.put(Audio.Media.IS_MUSIC,music);
    values.put(Audio.Media.IS_PODCAST,podcasts);
  }
 else   if (mFileType == MediaFile.FILE_TYPE_JPEG) {
    HashMap<String,String> exifData=ExifInterface.loadExifData(entry.mPath);
    if (exifData != null) {
      float[] latlng=ExifInterface.getLatLng(exifData);
      if (latlng != null) {
        values.put(Images.Media.LATITUDE,latlng[0]);
        values.put(Images.Media.LONGITUDE,latlng[1]);
      }
    }
  }
  Uri result=null;
  long rowId=entry.mRowId;
  if (rowId == 0) {
    result=mMediaProvider.insert(tableUri,values);
    if (result != null) {
      rowId=ContentUris.parseId(result);
      entry.mRowId=rowId;
    }
  }
 else {
    result=ContentUris.withAppendedId(tableUri,rowId);
    mMediaProvider.update(result,values,null,null);
  }
  if (mProcessGenres && mGenre != null) {
    String genre=mGenre;
    Uri uri=mGenreCache.get(genre);
    if (uri == null) {
      Cursor cursor=null;
      try {
        cursor=mMediaProvider.query(mGenresUri,GENRE_LOOKUP_PROJECTION,MediaStore.Audio.Genres.NAME + "String_Node_Str",new String[]{genre},null);
        if (cursor == null || cursor.getCount() == 0) {
          values.clear();
          values.put(MediaStore.Audio.Genres.NAME,genre);
          uri=mMediaProvider.insert(mGenresUri,values);
        }
 else {
          cursor.moveToNext();
          uri=ContentUris.withAppendedId(mGenresUri,cursor.getLong(0));
        }
        if (uri != null) {
          uri=Uri.withAppendedPath(uri,Genres.Members.CONTENT_DIRECTORY);
          mGenreCache.put(genre,uri);
        }
      }
  finally {
        if (cursor != null) {
          cursor.close();
        }
      }
    }
    if (uri != null) {
      values.clear();
      values.put(MediaStore.Audio.Genres.Members.AUDIO_ID,Long.valueOf(rowId));
      mMediaProvider.insert(uri,values);
    }
  }
  if (notifications && !mDefaultNotificationSet) {
    if (TextUtils.isEmpty(mDefaultNotificationFilename) || doesPathHaveFilename(entry.mPath,mDefaultNotificationFilename)) {
      setSettingIfNotSet(Settings.System.NOTIFICATION_SOUND,tableUri,rowId);
      mDefaultNotificationSet=true;
    }
  }
 else   if (ringtones && !mDefaultRingtoneSet) {
    if (TextUtils.isEmpty(mDefaultRingtoneFilename) || doesPathHaveFilename(entry.mPath,mDefaultRingtoneFilename)) {
      setSettingIfNotSet(Settings.System.RINGTONE,tableUri,rowId);
      mDefaultRingtoneSet=true;
    }
  }
  return result;
}

Fixed version (ground truth):
private Uri endFile(FileCacheEntry entry,boolean ringtones,boolean notifications,boolean alarms,boolean music,boolean podcasts) throws RemoteException {
  Uri tableUri;
  boolean isAudio=MediaFile.isAudioFileType(mFileType);
  boolean isVideo=MediaFile.isVideoFileType(mFileType);
  boolean isImage=MediaFile.isImageFileType(mFileType);
  if (isVideo) {
    tableUri=mVideoUri;
  }
 else   if (isImage) {
    tableUri=mImagesUri;
  }
 else   if (isAudio) {
    tableUri=mAudioUri;
  }
 else {
    return null;
  }
  entry.mTableUri=tableUri;
  if (mArtist == null || mArtist.length() == 0) {
    mArtist=mAlbumArtist;
  }
  ContentValues values=toValues();
  String title=values.getAsString(MediaStore.MediaColumns.TITLE);
  if (TextUtils.isEmpty(title.trim())) {
    title=values.getAsString(MediaStore.MediaColumns.DATA);
    int lastSlash=title.lastIndexOf('/');
    if (lastSlash >= 0) {
      lastSlash++;
      if (lastSlash < title.length()) {
        title=title.substring(lastSlash);
      }
    }
    int lastDot=title.lastIndexOf('.');
    if (lastDot > 0) {
      title=title.substring(0,lastDot);
    }
    values.put(MediaStore.MediaColumns.TITLE,title);
  }
  if (isAudio) {
    values.put(Audio.Media.IS_RINGTONE,ringtones);
    values.put(Audio.Media.IS_NOTIFICATION,notifications);
    values.put(Audio.Media.IS_ALARM,alarms);
    values.put(Audio.Media.IS_MUSIC,music);
    values.put(Audio.Media.IS_PODCAST,podcasts);
  }
 else   if (mFileType == MediaFile.FILE_TYPE_JPEG) {
    HashMap<String,String> exifData=ExifInterface.loadExifData(entry.mPath);
    if (exifData != null) {
      float[] latlng=ExifInterface.getLatLng(exifData);
      if (latlng != null) {
        values.put(Images.Media.LATITUDE,latlng[0]);
        values.put(Images.Media.LONGITUDE,latlng[1]);
      }
    }
  }
  Uri result=null;
  long rowId=entry.mRowId;
  if (rowId == 0) {
    result=mMediaProvider.insert(tableUri,values);
    if (result != null) {
      rowId=ContentUris.parseId(result);
      entry.mRowId=rowId;
    }
  }
 else {
    result=ContentUris.withAppendedId(tableUri,rowId);
    mMediaProvider.update(result,values,null,null);
  }
  if (mProcessGenres && mGenre != null) {
    String genre=mGenre;
    Uri uri=mGenreCache.get(genre);
    if (uri == null) {
      Cursor cursor=null;
      try {
        cursor=mMediaProvider.query(mGenresUri,GENRE_LOOKUP_PROJECTION,MediaStore.Audio.Genres.NAME + "String_Node_Str",new String[]{genre},null);
        if (cursor == null || cursor.getCount() == 0) {
          values.clear();
          values.put(MediaStore.Audio.Genres.NAME,genre);
          uri=mMediaProvider.insert(mGenresUri,values);
        }
 else {
          cursor.moveToNext();
          uri=ContentUris.withAppendedId(mGenresUri,cursor.getLong(0));
        }
        if (uri != null) {
          uri=Uri.withAppendedPath(uri,Genres.Members.CONTENT_DIRECTORY);
          mGenreCache.put(genre,uri);
        }
      }
  finally {
        if (cursor != null) {
          cursor.close();
        }
      }
    }
    if (uri != null) {
      values.clear();
      values.put(MediaStore.Audio.Genres.Members.AUDIO_ID,Long.valueOf(rowId));
      mMediaProvider.insert(uri,values);
    }
  }
  if (notifications && !mDefaultNotificationSet) {
    if (TextUtils.isEmpty(mDefaultNotificationFilename) || doesPathHaveFilename(entry.mPath,mDefaultNotificationFilename)) {
      setSettingIfNotSet(Settings.System.NOTIFICATION_SOUND,tableUri,rowId);
      mDefaultNotificationSet=true;
    }
  }
 else   if (ringtones && !mDefaultRingtoneSet) {
    if (TextUtils.isEmpty(mDefaultRingtoneFilename) || doesPathHaveFilename(entry.mPath,mDefaultRingtoneFilename)) {
      setSettingIfNotSet(Settings.System.RINGTONE,tableUri,rowId);
      mDefaultRingtoneSet=true;
    }
  }
  return result;
}