[Demonstration 1]

[Buggy Method]
private boolean setFieldVal(CmInfo vo, SysField field, String val, Method[] methods, Map<String, SysField> fieldRefs, boolean newIfNotExist) {
    Method method = lookupMethod(methods, "set" + field.getFname());
    if (method == null)
        return false;
    boolean succ = false;
    String stype = field.getStype();
    String ftype = field.getFtype();
    String srcName = field.getSrcName();
    if ("text".equals(stype) || "date".equals(stype)) {
        try {
            if ("int".equals(ftype)) {
                method.invoke(vo, Integer.parseInt(val));
            } else if ("double".equals(ftype)) {
                method.invoke(vo, Double.parseDouble(val));
            } else {
                method.invoke(vo, val);
            }
            succ = true;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("Bean反射设值异常,TYPE:" + stype + ",FIELD:" + field.getFname() + ",VAL:" + val, e);
        }
    } else if ("dist".equals(stype)) {
        try {
            SysDist dist = getDistByVal(field.getDistType(), val, false);
            if (dist == null) {
                method.invoke(vo, "-100");
                if (srcName != null && srcName.length() > 0) {
                    Method srcMethod = lookupMethod(methods, "set" + srcName);
                    if (srcMethod != null) {
                        srcMethod.invoke(vo, val);
                    }
                }
            } else {
                method.invoke(vo, dist.getKey());
            }
            succ = true;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("Bean反射设值异常,TYPE:" + stype + ",FIELD:" + field.getFname() + ",VAL:" + val, e);
        }
    } else if ("tree".equals(stype)) {
        int pid = -1;
        try {
            if (field.getTreeLevel() == 1) {
                pid = 0;
            } else {
                SysField ref = fieldRefs.get(field.getFname());
                if (ref != null) {
                    Method refMethod = lookupMethod(methods, "get" + ref.getFname());
                    Integer obj = (Integer) refMethod.invoke(vo);
                    if (obj != null)
                        pid = obj;
                }
            }
            SysTree tree = getTreeByVal(field.getDistType(), val, pid, field.getTreeLevel(), false);
            if (tree == null && pid > -1 && field.getTreeLevel() > 1) {
                tree = getTreeByVal(field.getDistType(), val, -1, field.getTreeLevel(), false);
            }
            if (tree == null) {
                method.invoke(vo, -100);
                if (srcName != null && srcName.length() > 0) {
                    Method srcMethod = lookupMethod(methods, "set" + srcName);
                    if (srcMethod != null) {
                        srcMethod.invoke(vo, val);
                    }
                }
            } else {
                method.invoke(vo, tree.getId());
            }
            succ = true;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("Bean反射设值异常,TYPE:" + stype + ",FIELD:" + field.getFname() + ",VAL:" + val, e);
        }
    } else if ("org".equals(stype)) {
        int pid = -1;
        try {
            if (field.getTreeLevel() == 1) {
                pid = 0;
            } else {
                SysField ref = fieldRefs.get(field.getFname());
                if (ref != null) {
                    Method refMethod = lookupMethod(methods, "get" + ref.getFname());
                    Integer obj = (Integer) refMethod.invoke(vo);
                    if (obj != null)
                        pid = obj;
                }
            }
            SysOrg org = null;
            org = getOrgByVal(val, pid, false);
            if (org == null && pid > -1 && field.getTreeLevel() == 3) {
                org = getOrgByVal(val, -1, false);
            }
            if (org == null)
                return false;
            method.invoke(vo, org.getId());
            succ = true;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("Bean反射设值异常,TYPE:" + stype + ",FIELD:" + field.getFname() + ",VAL:" + val, e);
        }
    }
    return succ;
}

[Buggy Hunk]
method.invoke(vo, Integer.parseInt(val));

[Patch]
method.invoke(vo, (int)Double.parseDouble(val));

[Demonstration 2]

[Buggy Method]
private int extractInt(XmlResourceParser xpp) throws IOException, XmlPullParserException {
    xpp.next();
    int val = Integer.parseInt(xpp.getName());
    xpp.next();
    xpp.next();
    return val;
}

[Buggy Hunk]
int val = Integer.parseInt(xpp.getName());

[Patch]
int val = Integer.parseInt(xpp.getText());

[Demonstration 3]

[Buggy Method]
private void respond(String prompt) {
    // strip the code of punctuation, tabs, and trailing spaces
    // then, make everything lowercase
    prompt = prompt.replace(".,!?\t", "").trim().toLowerCase();
    // uses correct command if prompt matches keyword
    for (Keyword k : commands) {
        if (prompt.matches(k.getRegex())) {
            pickAction(k.getResult(), prompt);
            return;
        }
    }
    textReply(prompt);
}

[Buggy Hunk]
prompt = prompt.replace(".,!?\t", "").trim().toLowerCase();

[Patch]
prompt = prompt.replaceAll("[.,!?\t]", "").trim().toLowerCase();