Program: 157300
Project: 157300
Buggy source:
public static KeyboardExtension getCurrentKeyboardExtension(@NonNull Context context,@KeyboardExtension.KeyboardExtensionType final int type){
  SharedPreferences sharedPreferences=PreferenceManager.getDefaultSharedPreferences(context);
  final String settingKey;
  final String defaultValue;
switch (type) {
case KeyboardExtension.TYPE_BOTTOM:
    settingKey=context.getString(R.string.settings_key_ext_kbd_bottom_row_key);
  defaultValue=context.getString(R.string.settings_default_ext_kbd_bottom_row_key);
break;
case KeyboardExtension.TYPE_TOP:
settingKey=context.getString(R.string.settings_key_ext_kbd_top_row_key);
defaultValue=context.getString(R.string.settings_default_top_row_key);
break;
case KeyboardExtension.TYPE_EXTENSION:
settingKey=context.getString(R.string.settings_key_ext_kbd_ext_ketboard_key);
defaultValue=context.getString(R.string.settings_default_ext_keyboard_key);
break;
default :
throw new RuntimeException("String_Node_Str" + type);
}
String selectedKeyId=sharedPreferences.getString(settingKey,defaultValue);
KeyboardExtension selectedKeyboard=null;
List<KeyboardExtension> keys=msInstance.getAllAddOns(context);
for (KeyboardExtension aKey : keys) {
if (aKey.getExtensionType() != type) continue;
if (aKey.getId().equals(selectedKeyId)) {
selectedKeyboard=aKey;
break;
}
}
if (selectedKeyboard == null) {
for (KeyboardExtension aKey : keys) {
if (aKey.getExtensionType() != type) continue;
selectedKeyboard=aKey;
break;
}
if (selectedKeyboard != null) {
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString(settingKey,selectedKeyboard.getId());
editor.commit();
}
}
return selectedKeyboard;
}

Fixed version (ground truth):
public static KeyboardExtension getCurrentKeyboardExtension(@NonNull Context context,@KeyboardExtension.KeyboardExtensionType final int type){
  SharedPreferences sharedPreferences=PreferenceManager.getDefaultSharedPreferences(context);
  final String settingKey;
  final String defaultValue;
switch (type) {
case KeyboardExtension.TYPE_BOTTOM:
    settingKey=context.getString(R.string.settings_key_ext_kbd_bottom_row_key);
  defaultValue=context.getString(R.string.settings_default_ext_kbd_bottom_row_key);
break;
case KeyboardExtension.TYPE_TOP:
settingKey=context.getString(R.string.settings_key_ext_kbd_top_row_key);
defaultValue=context.getString(R.string.settings_default_top_row_key);
break;
case KeyboardExtension.TYPE_EXTENSION:
settingKey=context.getString(R.string.settings_key_ext_kbd_ext_ketboard_key);
defaultValue=context.getString(R.string.settings_default_ext_keyboard_key);
break;
default :
throw new RuntimeException("String_Node_Str" + type);
}
String selectedKeyId=sharedPreferences.getString(settingKey,defaultValue);
KeyboardExtension selectedKeyboard=null;
List<KeyboardExtension> keys=msInstance.getAllAddOns(context);
for (KeyboardExtension aKey : keys) {
if (aKey.getExtensionType() != type) continue;
if (aKey.getId().equals(selectedKeyId)) {
selectedKeyboard=aKey;
break;
}
}
if (selectedKeyboard == null) {
for (KeyboardExtension aKey : keys) {
if (aKey.getExtensionType() != type) continue;
selectedKeyboard=aKey;
break;
}
if (selectedKeyboard != null) {
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString(settingKey,selectedKeyboard.getId());
SharedPreferencesCompat.EditorCompat.getInstance().apply(editor);
}
}
return selectedKeyboard;
}