[Demonstration 1]

[Buggy Method]
public PushCommand push() {
    return new PushCommand() {

        public URIish remote;

        public String refspec;

        public boolean force;

        public boolean tags;

        public PushCommand to(URIish remote) {
            this.remote = remote;
            return this;
        }

        public PushCommand ref(String refspec) {
            this.refspec = refspec;
            return this;
        }

        public PushCommand force() {
            this.force = true;
            return this;
        }

        public PushCommand tags(boolean tags) {
            this.tags = tags;
            return this;
        }

        public PushCommand timeout(Integer timeout) {
            // noop in jgit
            return this;
        }

        public void execute() throws GitException, InterruptedException {
            RefSpec ref = (refspec != null) ? new RefSpec(fixRefSpec()) : Transport.REFSPEC_PUSH_ALL;
            Repository repo = null;
            try {
                repo = getRepository();
                Git g = git(repo);
                Config config = g.getRepository().getConfig();
                config.setString("remote", "org_jenkinsci_plugins_gitclient_JGitAPIImpl", "url", remote.toPrivateASCIIString());
                org.eclipse.jgit.api.PushCommand pc = g.push().setRemote("org_jenkinsci_plugins_gitclient_JGitAPIImpl").setRefSpecs(ref).setProgressMonitor(new JGitProgressMonitor(listener)).setCredentialsProvider(getProvider()).setForce(force);
                if (tags) {
                    pc.setPushTags();
                }
                Iterable<PushResult> results = pc.call();
                for (PushResult result : results) for (RemoteRefUpdate update : result.getRemoteUpdates()) {
                    RemoteRefUpdate.Status status = update.getStatus();
                    if (!OK.equals(status) && !UP_TO_DATE.equals(status)) {
                        String messageJGit = update.getMessage() + " " + status + " for '" + ref + "'";
                        String messageArgs = "refspec '" + refspec != null ? refspec : "" + "' to " + remote.toPrivateASCIIString();
                        throw new GitException(messageJGit + " " + messageArgs);
                    }
                }
                config.unset("remote", "org_jenkinsci_plugins_gitclient_JGitAPIImpl", "url");
            } catch (JGitInternalException je) {
                throw new GitException(je);
            } catch (GitAPIException e) {
                throw new GitException(e);
            } finally {
                if (repo != null)
                    repo.close();
            }
        }

        /**
         * JGit 3.7.1 does not support Git CLI-style refspec parsing. See
         * discussion from Shawn Pearce (one of the JGit authors) describing
         * why JGit does not accept (e.g.) HEAD:master at:
         * http://git.661346.n2.nabble.com/JGit-Push-to-new-Amazon-S3-does-not-work-quot-funny-refname-quot-td2441026.html
         *
         * This method tries to fix the refspec as a workaround until JGit
         * implements parsing arbitrary refspecs (see JENKINS-20393).
         *
         * @return a (hopefully) fixed refspec string.
         */
        private String fixRefSpec() {
            int colon = refspec.indexOf(':');
            String[] specs = new String[] { (colon != -1 ? refspec.substring(0, colon) : refspec).trim(), refspec.substring(colon + 1).trim() };
            if (//special case for HEAD, if e.g. HEAD:branch, HEAD should be pushed to branch, we can't parse head, so assume to push branch:branch
            "HEAD".equals(specs[0]))
                specs[0] = specs[1];
            for (int spec = 0; spec < specs.length; spec++) if (specs[spec].isEmpty()) {
                //generally means to push "matching" branches, hard to implement the right way, simple-fix here
                if (//empty for the first spec. if fine (see https://github.com/eclipse/jgit/blob/master/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java#L104-L122)
                spec != 0)
                    specs[spec] = "refs/heads/master";
            } else if (!specs[spec].startsWith("refs/") && !specs[spec].startsWith("+refs/")) {
                if (//should read <git-dir>/HEAD file, which is also quite hard, simple-fix here aswell
                "HEAD".equalsIgnoreCase(specs[spec]))
                    specs[spec] = "refs/heads/master";
                else {
                    if (!specs[spec].startsWith("/"))
                        specs[spec] = "/" + specs[spec];
                    if (!specs[spec].startsWith("/heads/") && !specs[spec].startsWith("/remotes/") && !specs[spec].startsWith("/tags/"))
                        specs[spec] = "/heads" + specs[spec];
                    specs[spec] = "refs" + specs[spec];
                }
            }
            return specs[0] + ":" + specs[1];
        }
    };
}

[Buggy Hunk]
String messageArgs = "refspec '" + refspec != null ? refspec : "" + "' to " + remote.toPrivateASCIIString();

[Patch]
String messageArgs = "refspec '" + refspec + "' to " + remote.toPrivateASCIIString();

[Demonstration 2]

[Buggy Method]
public Object getComplexObj(String var) throws IllegalArgumentException, NoSuchFieldException, IllegalAccessException {
    String[] spl = var.split(Pattern.quote("/"));
    JsonNode ref = rootJson;
    for (int i = 0; i < spl.length; i++) {
        String field = (spl[i].contains("[")) ? spl[i].substring(0, spl[i].indexOf("[")) : spl[i];
        String index = (spl[i].contains("[")) ? spl[i].substring(spl[i].indexOf("[") + 1, spl[i].indexOf("]")) : null;
        if (ref.isObject()) {
            if (((ObjectNode) ref).get(field) != null) {
                ref = ((ObjectNode) ref).get(field);
                if (index != null && !index.equals("")) {
                    ref = ((ArrayNode) ref).get(0);
                }
                if (index != null && index.equals("") && i != spl.length - 1)
                    return null;
                continue;
            } else {
                //System.out.println(var + " not found");
                return null;
            }
        } else {
            if (((ArrayNode) ref).elements().hasNext() == false) {
                //System.out.println(var + " not found-array version");
                return null;
            }
            ref = ((ArrayNode) ref).get(0);
            if (((ObjectNode) ref).get(field) == null) {
                //System.out.println(var +" not found!");
                return null;
            }
            continue;
        }
    }
    log.info("Created tree: " + ref);
    //System.out.println(ref);
    if (ref.isValueNode()) {
        //is a leaf, but it is not present in state
        String varJava = fromYangToJava(var);
        log.info("Var java " + varJava);
        Object value = getLeafValue(varJava.substring(5));
        //            ObjectNode result = mapper.createObjectNode();
        //            result.put(var.substring(var.lastIndexOf("/")+1), value.toString());
        return value;
    }
    // = (ref.isObject())?mapper.createObjectNode():mapper.createArrayNode();
    JsonNode res;
    var = (ref.isArray() && var.endsWith("[]")) ? var.substring(0, var.length() - 2) : var;
    res = fillResult(ref, var);
    if (var.endsWith("]") && res.size() == 0)
        res = null;
    //System.out.println(res);
    //        log.info("The result is "+res);
    JsonNode r = mapper.createObjectNode();
    ((ObjectNode) r).put(var.substring(var.lastIndexOf("/") + 1), res);
    //        log.info("The result is ready");
    return res;
}

[Buggy Hunk]
Object value = getLeafValue(varJava.substring(5));

[Patch]
Object value = getLeafValue(varJava.substring(5), var);

[Demonstration 3]

[Buggy Method]
public static boolean areAnagramsUsingHashMap(final String s1, final String s2) {
    if ((s1 == null) || (s1 == null) || (s1.length() != s2.length()))
        return false;
    final Map<Character, Integer> occurrences = new HashMap<>();
    countCharOccurrences(s1, occurrences);
    countCharOccurrences(s2, occurrences);
    for (final int count : occurrences.values()) if (count != 2)
        return false;
    return true;
}

[Buggy Hunk]
if ((s1 == null) || (s1 == null) || (s1.length() != s2.length()))

[Patch]
if ((s1 == null) || (s2 == null) || (s1.length() != s2.length()))