[Demonstration 1]

[Buggy Method]
private void addSubnode(Node node, String name, Object obj) throws RepositoryException {
    Node subNode;
    if (obj instanceof Map) {
        Map map = (Map) obj;
        if (map.containsKey(JCR_PRIMARY_TYPE)) {
            subNode = addSubnodeWithPrimaryType(node, name, map);
        } else {
            subNode = addSubnodeWithoutPrimaryType(node, name, map);
        }
        updateNode(subNode, map);
    } else if (obj instanceof Collection) {
        for (Object item : (Collection) obj) {
            addSubnode(node, name, item);
        }
    }
}

[Buggy Hunk]
if (map.containsKey(JCR_PRIMARY_TYPE)) {

[Patch]
if (map.containsKey(JCR_PRIMARY_TYPE) && !"".equals(map.get(JCR_PRIMARY_TYPE))) {

[Demonstration 2]

[Buggy Method]
public Map<String, Set<String>> getRackHostsMap(List<String> addedNodeNames) {
    if (!AmUtils.isAmbariServerGreaterOrEquals_2_1_0(ambariServerVersion)) {
        return null;
    }
    Map<String, Set<String>> rackHostsMap = new HashMap<String, Set<String>>();
    List<AmNodeDef> nodes = getNodes();
    for (AmNodeDef node : nodes) {
        // This logic is just for cluster resize
        if (addedNodeNames != null && !addedNodeNames.contains(node.getName())) {
            continue;
        }
        String rack = this.rackTopology.get(node.getIp());
        if (rack != null) {
            Set<String> hosts = rackHostsMap.get(rack);
            if (hosts == null) {
                hosts = new HashSet<String>();
            }
            hosts.add(node.getFqdn());
            rackHostsMap.put(rack, hosts);
        }
    }
    return rackHostsMap;
}

[Buggy Hunk]
if (!AmUtils.isAmbariServerGreaterOrEquals_2_1_0(ambariServerVersion)) {

[Patch]
if (this.rackTopology == null || !AmUtils.isAmbariServerGreaterOrEquals_2_1_0(ambariServerVersion)) {

[Demonstration 3]

[Buggy Method]
public static UserCache getUserCache(Context ctxt) {
    return new BuiltinUserCache(ctxt);
}

[Buggy Hunk]
return new BuiltinUserCache(ctxt);

[Patch]
return BuiltinUserCache.getDatabase(ctxt);