Program: 157225
Project: 157225
Buggy source:
private HardKeyboardSequenceHandler createPhysicalTranslatorFromResourceId(Context context,int qwertyTranslationId){
  HardKeyboardSequenceHandler translator=new HardKeyboardSequenceHandler();
  XmlPullParser parser=context.getResources().getXml(qwertyTranslationId);
  final String TAG="String_Node_Str";
  try {
    int event;
    boolean inTranslations=false;
    while ((event=parser.next()) != XmlPullParser.END_DOCUMENT) {
      String tag=parser.getName();
      if (event == XmlPullParser.START_TAG) {
        if (XML_TRANSLATION_TAG.equals(tag)) {
          inTranslations=true;
          AttributeSet attrs=Xml.asAttributeSet(parser);
          final String qwerty=attrs.getAttributeValue(null,XML_QWERTY_ATTRIBUTE);
          if (qwerty != null)           translator.addQwertyTranslation(qwerty);
        }
 else         if (inTranslations && XML_SEQUENCE_TAG.equals(tag)) {
          AttributeSet attrs=Xml.asAttributeSet(parser);
          final int[] keyCodes=getKeyCodesFromPhysicalSequence(attrs.getAttributeValue(null,XML_KEYS_ATTRIBUTE));
          final boolean isAlt=attrs.getAttributeBooleanValue(null,XML_ALT_ATTRIBUTE,false);
          final boolean isShift=attrs.getAttributeBooleanValue(null,XML_SHIFT_ATTRIBUTE,false);
          final String targetChar=attrs.getAttributeValue(null,XML_TARGET_ATTRIBUTE);
          final String targetCharCode=attrs.getAttributeValue(null,XML_TARGET_CHAR_CODE_ATTRIBUTE);
          final Integer target;
          if (targetCharCode == null)           target=(int)targetChar.charAt(0);
 else           target=Integer.valueOf(targetCharCode);
          if ((keyCodes == null) || (keyCodes.length == 0) || (target == null)) {
            Logger.e(TAG,"String_Node_Str" + XML_KEYS_ATTRIBUTE + "String_Node_Str"+ XML_TARGET_ATTRIBUTE);
          }
 else {
            if (!isAlt && !isShift) {
              translator.addSequence(keyCodes,target);
              translator.addShiftSequence(keyCodes,Character.toUpperCase(target));
            }
 else             if (isAlt) {
              translator.addAltSequence(keyCodes,target);
            }
 else {
              translator.addShiftSequence(keyCodes,target);
            }
          }
        }
 else         if (inTranslations && XML_MULTITAP_TAG.equals(tag)) {
          AttributeSet attrs=Xml.asAttributeSet(parser);
          final int[] keyCodes=getKeyCodesFromPhysicalSequence(attrs.getAttributeValue(null,XML_MULTITAP_KEY_ATTRIBUTE));
          if (keyCodes.length != 1)           throw new ParseException("String_Node_Str" + XML_MULTITAP_KEY_ATTRIBUTE + "String_Node_Str"+ XML_MULTITAP_TAG+ "String_Node_Str",parser.getLineNumber());
          final boolean isAlt=attrs.getAttributeBooleanValue(null,XML_ALT_ATTRIBUTE,false);
          final boolean isShift=attrs.getAttributeBooleanValue(null,XML_SHIFT_ATTRIBUTE,false);
          final String targetCharacters=attrs.getAttributeValue(null,XML_MULTITAP_CHARACTERS_ATTRIBUTE);
          if (TextUtils.isEmpty(targetCharacters) || targetCharacters.length() < 2)           throw new ParseException("String_Node_Str" + XML_MULTITAP_CHARACTERS_ATTRIBUTE + "String_Node_Str"+ XML_MULTITAP_TAG+ "String_Node_Str",parser.getLineNumber());
          for (int characterIndex=0; characterIndex <= targetCharacters.length(); characterIndex++) {
            int[] multiTapCodes=new int[characterIndex + 1];
            for (int tapIndex=0; tapIndex < multiTapCodes.length; tapIndex++) {
              multiTapCodes[tapIndex]=keyCodes[0];
            }
            if (characterIndex < targetCharacters.length()) {
              final int target=targetCharacters.charAt(characterIndex);
              if (!isAlt && !isShift) {
                translator.addSequence(multiTapCodes,target);
                translator.addShiftSequence(multiTapCodes,Character.toUpperCase(target));
              }
 else               if (isAlt) {
                translator.addAltSequence(keyCodes,target);
              }
 else {
                translator.addShiftSequence(keyCodes,target);
              }
            }
 else {
              if (!isAlt && !isShift) {
                translator.addSequence(multiTapCodes,KeyEventStateMachine.KEYCODE_FIRST_CHAR);
                translator.addShiftSequence(multiTapCodes,KeyEventStateMachine.KEYCODE_FIRST_CHAR);
              }
 else               if (isAlt) {
                translator.addAltSequence(keyCodes,KeyEventStateMachine.KEYCODE_FIRST_CHAR);
              }
 else {
                translator.addShiftSequence(keyCodes,KeyEventStateMachine.KEYCODE_FIRST_CHAR);
              }
            }
          }
        }
      }
 else       if (event == XmlPullParser.END_TAG) {
        if (XML_TRANSLATION_TAG.equals(tag)) {
          break;
        }
      }
    }
  }
 catch (  Exception e) {
    String errorMessage=String.format(Locale.US,"String_Node_Str",getKeyboardName(),getKeyboardId(),getKeyboardAddOn().getPackageName(),qwertyTranslationId);
    Logger.e(TAG,errorMessage,e);
    e.printStackTrace();
    if (BuildConfig.DEBUG)     throw new RuntimeException(errorMessage,e);
  }
  return translator;
}

Fixed version (ground truth):
private HardKeyboardSequenceHandler createPhysicalTranslatorFromResourceId(Context context,int qwertyTranslationId){
  HardKeyboardSequenceHandler translator=new HardKeyboardSequenceHandler();
  XmlPullParser parser=context.getResources().getXml(qwertyTranslationId);
  final String TAG="String_Node_Str";
  try {
    int event;
    boolean inTranslations=false;
    while ((event=parser.next()) != XmlPullParser.END_DOCUMENT) {
      String tag=parser.getName();
      if (event == XmlPullParser.START_TAG) {
        if (XML_TRANSLATION_TAG.equals(tag)) {
          inTranslations=true;
          AttributeSet attrs=Xml.asAttributeSet(parser);
          final String qwerty=attrs.getAttributeValue(null,XML_QWERTY_ATTRIBUTE);
          if (qwerty != null)           translator.addQwertyTranslation(qwerty);
        }
 else         if (inTranslations && XML_SEQUENCE_TAG.equals(tag)) {
          AttributeSet attrs=Xml.asAttributeSet(parser);
          final int[] keyCodes=getKeyCodesFromPhysicalSequence(attrs.getAttributeValue(null,XML_KEYS_ATTRIBUTE));
          final boolean isAlt=attrs.getAttributeBooleanValue(null,XML_ALT_ATTRIBUTE,false);
          final boolean isShift=attrs.getAttributeBooleanValue(null,XML_SHIFT_ATTRIBUTE,false);
          final String targetChar=attrs.getAttributeValue(null,XML_TARGET_ATTRIBUTE);
          final String targetCharCode=attrs.getAttributeValue(null,XML_TARGET_CHAR_CODE_ATTRIBUTE);
          final Integer target;
          if (targetCharCode == null)           target=(int)targetChar.charAt(0);
 else           target=Integer.valueOf(targetCharCode);
          if ((keyCodes.length == 0) || (target == null)) {
            Logger.e(TAG,"String_Node_Str" + XML_KEYS_ATTRIBUTE + "String_Node_Str"+ XML_TARGET_ATTRIBUTE);
          }
 else {
            if (!isAlt && !isShift) {
              translator.addSequence(keyCodes,target);
              translator.addShiftSequence(keyCodes,Character.toUpperCase(target));
            }
 else             if (isAlt) {
              translator.addAltSequence(keyCodes,target);
            }
 else {
              translator.addShiftSequence(keyCodes,target);
            }
          }
        }
 else         if (inTranslations && XML_MULTITAP_TAG.equals(tag)) {
          AttributeSet attrs=Xml.asAttributeSet(parser);
          final int[] keyCodes=getKeyCodesFromPhysicalSequence(attrs.getAttributeValue(null,XML_MULTITAP_KEY_ATTRIBUTE));
          if (keyCodes.length != 1)           throw new XmlPullParserException("String_Node_Str" + XML_MULTITAP_KEY_ATTRIBUTE + "String_Node_Str"+ XML_MULTITAP_TAG+ "String_Node_Str",parser,new ParseException(XML_MULTITAP_KEY_ATTRIBUTE,parser.getLineNumber()));
          final boolean isAlt=attrs.getAttributeBooleanValue(null,XML_ALT_ATTRIBUTE,false);
          final boolean isShift=attrs.getAttributeBooleanValue(null,XML_SHIFT_ATTRIBUTE,false);
          final String targetCharacters=attrs.getAttributeValue(null,XML_MULTITAP_CHARACTERS_ATTRIBUTE);
          if (TextUtils.isEmpty(targetCharacters) || targetCharacters.length() < 2)           throw new XmlPullParserException("String_Node_Str" + XML_MULTITAP_CHARACTERS_ATTRIBUTE + "String_Node_Str"+ XML_MULTITAP_TAG+ "String_Node_Str",parser,new ParseException(XML_MULTITAP_CHARACTERS_ATTRIBUTE,parser.getLineNumber()));
          for (int characterIndex=0; characterIndex <= targetCharacters.length(); characterIndex++) {
            int[] multiTapCodes=new int[characterIndex + 1];
            for (int tapIndex=0; tapIndex < multiTapCodes.length; tapIndex++) {
              multiTapCodes[tapIndex]=keyCodes[0];
            }
            if (characterIndex < targetCharacters.length()) {
              final int target=targetCharacters.charAt(characterIndex);
              if (!isAlt && !isShift) {
                translator.addSequence(multiTapCodes,target);
                translator.addShiftSequence(multiTapCodes,Character.toUpperCase(target));
              }
 else               if (isAlt) {
                translator.addAltSequence(keyCodes,target);
              }
 else {
                translator.addShiftSequence(keyCodes,target);
              }
            }
 else {
              if (!isAlt && !isShift) {
                translator.addSequence(multiTapCodes,KeyEventStateMachine.KEYCODE_FIRST_CHAR);
                translator.addShiftSequence(multiTapCodes,KeyEventStateMachine.KEYCODE_FIRST_CHAR);
              }
 else               if (isAlt) {
                translator.addAltSequence(keyCodes,KeyEventStateMachine.KEYCODE_FIRST_CHAR);
              }
 else {
                translator.addShiftSequence(keyCodes,KeyEventStateMachine.KEYCODE_FIRST_CHAR);
              }
            }
          }
        }
      }
 else       if (event == XmlPullParser.END_TAG) {
        if (XML_TRANSLATION_TAG.equals(tag)) {
          break;
        }
      }
    }
  }
 catch (  XmlPullParserException e) {
    Logger.e(TAG,e,"String_Node_Str",getKeyboardName(),getKeyboardId(),getKeyboardAddOn().getPackageName(),qwertyTranslationId);
    if (BuildConfig.DEBUG)     throw new RuntimeException("String_Node_Str",e);
  }
catch (  IOException e) {
    Logger.e(TAG,e,"String_Node_Str");
  }
  return translator;
}