Program: 23546
Project: 23546
Buggy source:
@Override public void onReceive(Context context,Intent intent){
synchronized (mMethodMap) {
    buildInputMethodListLocked(mMethodList,mMethodMap);
    InputMethodInfo curIm=null;
    String curInputMethodId=Settings.Secure.getString(context.getContentResolver(),Settings.Secure.DEFAULT_INPUT_METHOD);
    final int N=mMethodList.size();
    if (curInputMethodId != null) {
      for (int i=0; i < N; i++) {
        if (mMethodList.get(i).getId().equals(curInputMethodId)) {
          curIm=mMethodList.get(i);
        }
      }
    }
    boolean changed=false;
    Uri uri=intent.getData();
    String pkg=uri != null ? uri.getSchemeSpecificPart() : null;
    if (curIm != null && curIm.getPackageName().equals(pkg)) {
      ServiceInfo si=null;
      try {
        si=mContext.getPackageManager().getServiceInfo(curIm.getComponent(),0);
      }
 catch (      PackageManager.NameNotFoundException ex) {
      }
      if (si == null) {
        Log.i(TAG,"String_Node_Str" + curInputMethodId);
        List<InputMethodInfo> enabled=getEnabledInputMethodListLocked();
        if (enabled != null && enabled.size() > 0) {
          changed=true;
          curIm=enabled.get(0);
          curInputMethodId=curIm.getId();
          Log.i(TAG,"String_Node_Str" + curInputMethodId);
          Settings.Secure.putString(mContext.getContentResolver(),Settings.Secure.DEFAULT_INPUT_METHOD,curInputMethodId);
        }
 else         if (curIm != null) {
          changed=true;
          curIm=null;
          curInputMethodId="String_Node_Str";
          Log.i(TAG,"String_Node_Str");
          Settings.Secure.putString(mContext.getContentResolver(),Settings.Secure.DEFAULT_INPUT_METHOD,curInputMethodId);
        }
      }
    }
 else     if (curIm == null) {
      List<InputMethodInfo> enabled=getEnabledInputMethodListLocked();
      if (enabled != null && enabled.size() > 0) {
        changed=true;
        curIm=enabled.get(0);
        curInputMethodId=curIm.getId();
        Log.i(TAG,"String_Node_Str" + curInputMethodId);
        Settings.Secure.putString(mContext.getContentResolver(),Settings.Secure.DEFAULT_INPUT_METHOD,curInputMethodId);
      }
    }
    if (changed) {
      updateFromSettingsLocked();
    }
  }
}

Fixed version (ground truth):
@Override public void onReceive(Context context,Intent intent){
synchronized (mMethodMap) {
    buildInputMethodListLocked(mMethodList,mMethodMap);
    InputMethodInfo curIm=null;
    String curInputMethodId=Settings.Secure.getString(context.getContentResolver(),Settings.Secure.DEFAULT_INPUT_METHOD);
    final int N=mMethodList.size();
    if (curInputMethodId != null) {
      for (int i=0; i < N; i++) {
        if (mMethodList.get(i).getId().equals(curInputMethodId)) {
          curIm=mMethodList.get(i);
        }
      }
    }
    boolean changed=false;
    Uri uri=intent.getData();
    String pkg=uri != null ? uri.getSchemeSpecificPart() : null;
    if (curIm != null && curIm.getPackageName().equals(pkg)) {
      ServiceInfo si=null;
      try {
        si=mContext.getPackageManager().getServiceInfo(curIm.getComponent(),0);
      }
 catch (      PackageManager.NameNotFoundException ex) {
      }
      if (si == null) {
        Log.i(TAG,"String_Node_Str" + curInputMethodId);
        if (!chooseNewDefaultIME()) {
          changed=true;
          curIm=null;
          curInputMethodId="String_Node_Str";
          Log.i(TAG,"String_Node_Str");
          Settings.Secure.putString(mContext.getContentResolver(),Settings.Secure.DEFAULT_INPUT_METHOD,curInputMethodId);
        }
      }
    }
 else     if (curIm == null) {
      changed=chooseNewDefaultIME();
    }
    if (changed) {
      updateFromSettingsLocked();
    }
  }
}