Program: 192344
Project: 192344
Buggy source:
private void onVolumeStateChangedLocked(VolumeInfo vol,int oldState,int newState){
  if (vol.isMountedReadable() && !TextUtils.isEmpty(vol.fsUuid)) {
    VolumeRecord rec=mRecords.get(vol.fsUuid);
    if (rec == null) {
      rec=new VolumeRecord(vol.type,vol.fsUuid);
      rec.partGuid=vol.partGuid;
      rec.createdMillis=System.currentTimeMillis();
      if (vol.type == VolumeInfo.TYPE_PRIVATE) {
        rec.nickname=vol.disk.getDescription();
      }
      mRecords.put(rec.fsUuid,rec);
      writeSettingsLocked();
    }
 else {
      if (TextUtils.isEmpty(rec.partGuid)) {
        rec.partGuid=vol.partGuid;
        writeSettingsLocked();
      }
    }
  }
  mCallbacks.notifyVolumeStateChanged(vol,oldState,newState);
  if (mBootCompleted && isBroadcastWorthy(vol)) {
    final Intent intent=new Intent(VolumeInfo.ACTION_VOLUME_STATE_CHANGED);
    intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID,vol.id);
    intent.putExtra(VolumeInfo.EXTRA_VOLUME_STATE,newState);
    intent.putExtra(VolumeRecord.EXTRA_FS_UUID,vol.fsUuid);
    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
    mHandler.obtainMessage(H_INTERNAL_BROADCAST,intent).sendToTarget();
  }
  final String oldStateEnv=VolumeInfo.getEnvironmentForState(oldState);
  final String newStateEnv=VolumeInfo.getEnvironmentForState(newState);
  if (!Objects.equals(oldStateEnv,newStateEnv)) {
    for (    int userId : mSystemUnlockedUsers) {
      if (vol.isVisibleForRead(userId)) {
        final StorageVolume userVol=vol.buildStorageVolume(mContext,userId,false);
        mHandler.obtainMessage(H_VOLUME_BROADCAST,userVol).sendToTarget();
        mCallbacks.notifyStorageStateChanged(userVol.getPath(),oldStateEnv,newStateEnv);
      }
    }
  }
  if (vol.type == VolumeInfo.TYPE_PUBLIC && vol.state == VolumeInfo.STATE_EJECTING) {
    mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_FLUSH_MOUNT_STATE,vol.path));
  }
}

Fixed version (ground truth):
private void onVolumeStateChangedLocked(VolumeInfo vol,int oldState,int newState){
  if (vol.isMountedReadable() && !TextUtils.isEmpty(vol.fsUuid)) {
    VolumeRecord rec=mRecords.get(vol.fsUuid);
    if (rec == null) {
      rec=new VolumeRecord(vol.type,vol.fsUuid);
      rec.partGuid=vol.partGuid;
      rec.createdMillis=System.currentTimeMillis();
      if (vol.type == VolumeInfo.TYPE_PRIVATE) {
        rec.nickname=vol.disk.getDescription();
      }
      mRecords.put(rec.fsUuid,rec);
      writeSettingsLocked();
    }
 else {
      if (TextUtils.isEmpty(rec.partGuid)) {
        rec.partGuid=vol.partGuid;
        writeSettingsLocked();
      }
    }
  }
  mCallbacks.notifyVolumeStateChanged(vol,oldState,newState);
  if (mBootCompleted && isBroadcastWorthy(vol)) {
    final Intent intent=new Intent(VolumeInfo.ACTION_VOLUME_STATE_CHANGED);
    intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID,vol.id);
    intent.putExtra(VolumeInfo.EXTRA_VOLUME_STATE,newState);
    intent.putExtra(VolumeRecord.EXTRA_FS_UUID,vol.fsUuid);
    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
    mHandler.obtainMessage(H_INTERNAL_BROADCAST,intent).sendToTarget();
  }
  final String oldStateEnv=VolumeInfo.getEnvironmentForState(oldState);
  final String newStateEnv=VolumeInfo.getEnvironmentForState(newState);
  if (!Objects.equals(oldStateEnv,newStateEnv)) {
    for (    int userId : mSystemUnlockedUsers) {
      if (vol.isVisibleForRead(userId)) {
        final StorageVolume userVol=vol.buildStorageVolume(mContext,userId,false);
        mHandler.obtainMessage(H_VOLUME_BROADCAST,userVol).sendToTarget();
        mCallbacks.notifyStorageStateChanged(userVol.getPath(),oldStateEnv,newStateEnv);
      }
    }
  }
  if (vol.type == VolumeInfo.TYPE_PUBLIC && vol.state == VolumeInfo.STATE_EJECTING) {
    mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_FLUSH_MOUNT_STATE,vol.path));
  }
}