[Demonstration 1]

[Buggy Method]
private List<CalmMachine> getAllMachinesFromApp(String appID, String appName) throws CalmIntegrationException {
    List<CalmMachine> machineList = new ArrayList<CalmMachine>();
    HTTPResponseData respo;
    respo = HTTPHandlerInternal(false, url + "/api/1/default/resources?calm_application_name=" + appName, null, "Fetching Machine list ");
    JSONArray resourceList = respo.getJSONBody().getJSONObject("data").getJSONArray("rows");
    JSONObject m, bpArch;
    bpArch = HTTPHandlerInternal(false, url + "/api/1/default/applications/" + appID, null, "Fetching Application detail ").getJSONBody().getJSONObject("data").getJSONObject("row").getJSONObject("bp");
    String vmID, vmName, serviceName, ipAddress, port, credentialName, credUser, application, applicationID, cpro, proid, credid;
    for (int i = 0; i < resourceList.length(); i++) {
        m = resourceList.getJSONObject(i);
        vmID = m.getString("calm_machine_id");
        vmName = m.getString("vm_name");
        serviceName = m.getString("calm_machine_name");
        serviceName = serviceName.substring(0, (serviceName.lastIndexOf("[") < 1 ? serviceName.length() - 1 : serviceName.lastIndexOf("["))).trim();
        ipAddress = m.getString("vm_ip");
        application = m.getString("calm_application_name");
        applicationID = m.getString("calm_application_id");
        cpro = getValueInJsonArray(bpArch.getJSONArray("architecture"), "name", serviceName, "current_profile");
        proid = getValueInJsonArray(bpArch.getJSONArray("profiles"), "uid", cpro, "provider");
        port = String.valueOf(getIntValueInJsonArray(bpArch.getJSONArray("profiles"), "uid", cpro, "service_port"));
        credid = getValueInJsonArray(bpArch.getJSONArray("tasks"), "uid", proid, "credential_id");
        credentialName = getValueInJsonArray(bpArch.getJSONArray("credentials"), "uid", credid, "name");
        credUser = getValueInJsonArray(bpArch.getJSONArray("credentials"), "uid", credid, "username");
        machineList.add(new CalmMachine(vmID, vmName, serviceName, ipAddress, credentialName, application, applicationID, credUser, port));
    }
    return machineList;
}

[Buggy Hunk]
serviceName = serviceName.substring(0, (serviceName.lastIndexOf("[") < 1 ? serviceName.length() - 1 : serviceName.lastIndexOf("["))).trim();

[Patch]
serviceName = serviceName.substring(0, (serviceName.lastIndexOf("[") < 1 ? serviceName.length(): serviceName.lastIndexOf("["))).trim();

[Demonstration 2]

[Buggy Method]
public static Result service(String ownerName, String projectName, String service, boolean isAdvertise) throws IOException, UnsupportedOperationException, ServletException {
    if (!isSupportedService(service)) {
        return forbidden(String.format("Unsupported service: '%s'", service));
    }
    Project project = Project.findByOwnerAndProjectName(ownerName, projectName);
    if (project == null) {
        return notFound();
    }
    models.User user = UserApp.currentUser();
    if (!isAllowed(project, service)) {
        if (user.isAnonymous()) {
            return BasicAuthAction.unauthorized(response());
        } else {
            // If you want the Git client showing your custom message to
            // the user, the Content-Type should be exact "text/plain"
            // without any parameter. For more details, see the code at
            // https://github.com/git/git/commit/426e70d4a11ce3b4f70636d57c6a0ab16ae08a00#diff-eea0ad565ec5903a11b6023755d491cfR154
            response().setHeader("Content-Type", "text/plain");
            return forbidden(String.format("'%s' has no permission to '%s/%s'.", user.name, ownerName, projectName));
        }
    }
    if (isAdvertise) {
        return ok(RepositoryService.gitAdvertise(project, service, response()));
    } else {
        if (request().body().isMaxSizeExceeded()) {
            return status(REQUEST_ENTITY_TOO_LARGE);
        } else {
            user.visits(project);
            return ok(RepositoryService.gitRpc(project, service, request(), response()));
        }
    }
}

[Buggy Hunk]
user.name, ownerName, projectName));

[Patch]
user.loginId, ownerName, projectName));

[Demonstration 3]

[Buggy Method]
protected static WebServerContent getWebServerContent(HTTPRequest httpRequest) {
    String parameter = httpRequest.getResourcePath();
    if (parameter.startsWith("/")) {
        parameter = parameter.substring(1);
    }
    int index = parameter.indexOf('/');
    if (index != -1) {
        String type = parameter.substring(0, index);
        parameter = parameter.substring(index + 1);
        if ("class".equals(type)) {
            index = parameter.indexOf('/');
            WebServer webServer = (WebServer) ObjectRegistry.getInstance().get(Integer.parseInt(parameter.substring(0, index)));
            if (webServer == null) {
                return null;
            }
            parameter = parameter.substring(index + 1);
            index = parameter.indexOf('/');
            String className = parameter.substring(0, index);
            parameter = Utils.decodeURL(parameter.substring(index + 1));
            httpRequest = httpRequest.clone();
            try {
                Class<?> clazz = null;
                for (ClassLoader referenceClassLoader : webServer.referenceClassLoaderList) {
                    try {
                        clazz = Class.forName(className, true, referenceClassLoader);
                        break;
                    } catch (Exception e) {
                    }
                }
                if (clazz == null) {
                    clazz = Class.forName(className);
                }
                Method getWebServerContentMethod = clazz.getDeclaredMethod("getWebServerContent", HTTPRequest.class);
                getWebServerContentMethod.setAccessible(true);
                httpRequest.setResourcePath(parameter);
                return (WebServerContent) getWebServerContentMethod.invoke(null, httpRequest);
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
        if ("classpath".equals(type)) {
            index = parameter.indexOf('/');
            final WebServer webServer = (WebServer) ObjectRegistry.getInstance().get(Integer.parseInt(parameter.substring(0, index)));
            if (webServer == null) {
                return null;
            }
            parameter = parameter.substring(index + 1);
            final String resourcePath = removeHTMLAnchor(parameter);
            return new WebServerContent() {

                @Override
                public String getContentType() {
                    int index = resourcePath.lastIndexOf('.');
                    return getDefaultMimeType(index == -1 ? null : resourcePath.substring(index));
                }

                @Override
                public InputStream getInputStream() {
                    try {
                        for (ClassLoader referenceClassLoader : webServer.referenceClassLoaderList) {
                            InputStream in = referenceClassLoader.getResourceAsStream(resourcePath);
                            if (in != null) {
                                return in;
                            }
                        }
                        return WebServer.class.getResourceAsStream('/' + resourcePath);
                    } catch (Exception e) {
                        e.printStackTrace();
                        return null;
                    }
                }
            };
        }
        if ("location".equals(type)) {
            index = parameter.indexOf('/');
            String codeBase = Utils.decodeBase64(parameter.substring(0, index));
            parameter = Utils.decodeURL(removeHTMLAnchor(parameter.substring(index + 1)));
            String resourceURL;
            try {
                URL url = new URL(codeBase);
                int port = url.getPort();
                resourceURL = url.getProtocol() + "://" + url.getHost() + (port != -1 ? ":" + port : "");
                if (parameter.startsWith("/")) {
                    resourceURL += parameter;
                } else {
                    String path = url.getPath();
                    path = path.substring(0, path.lastIndexOf('/') + 1) + parameter;
                    resourceURL += path.startsWith("/") ? path : "/" + path;
                }
            } catch (Exception e) {
                // Exception when creating a URL, so it is malformed: it is likely to be a local file.
                File file = Utils.getLocalFile(new File(codeBase, parameter).getAbsolutePath());
                if (file != null) {
                    resourceURL = new File(codeBase, parameter).toURI().toString();
                } else {
                    resourceURL = codeBase + "/" + parameter;
                }
            }
            final String resourceURL_ = resourceURL;
            return new WebServerContent() {

                @Override
                public long getContentLength() {
                    File file = Utils.getLocalFile(resourceURL_);
                    if (file != null) {
                        return file.length();
                    }
                    return super.getContentLength();
                }

                @Override
                public String getContentType() {
                    int index = resourceURL_.lastIndexOf('.');
                    return getDefaultMimeType(index == -1 ? null : resourceURL_.substring(index));
                }

                @Override
                public InputStream getInputStream() {
                    try {
                        return new URL(resourceURL_).openStream();
                    } catch (Exception e) {
                    }
                    try {
                        return new FileInputStream("/" + resourceURL_);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return null;
                }
            };
        }
        if ("resource".equals(type)) {
            index = parameter.indexOf('/');
            if (index > 0) {
                String subs = parameter.substring(index - 1);
                if (subs.startsWith("://")) {
                    index = parameter.indexOf('/', index + 2);
                }
            }
            String codeBase = Utils.decodeURL(parameter.substring(0, index));
            parameter = Utils.decodeURL(parameter.substring(index + 1));
            String resourceURL;
            try {
                URL url = new URL(codeBase);
                int port = url.getPort();
                resourceURL = url.getProtocol() + "://" + url.getHost() + (port != -1 ? ":" + port : "");
                if (parameter.startsWith("/")) {
                    resourceURL += removeHTMLAnchor(parameter);
                } else {
                    String path = url.getPath();
                    path = path.substring(0, path.lastIndexOf('/') + 1) + parameter;
                    resourceURL += path.startsWith("/") ? path : "/" + path;
                }
            } catch (Exception e) {
                File file = Utils.getLocalFile(new File(codeBase, removeHTMLAnchor(parameter)).getAbsolutePath());
                if (file != null) {
                    resourceURL = new File(codeBase, removeHTMLAnchor(parameter)).toURI().toString();
                } else {
                    resourceURL = codeBase + "/" + removeHTMLAnchor(parameter);
                }
            }
            final String resourceURL_ = resourceURL;
            return new WebServerContent() {

                @Override
                public long getContentLength() {
                    File file = Utils.getLocalFile(resourceURL_);
                    if (file != null) {
                        return file.length();
                    }
                    return super.getContentLength();
                }

                @Override
                public String getContentType() {
                    int index = resourceURL_.lastIndexOf('.');
                    return getDefaultMimeType(index == -1 ? null : resourceURL_.substring(index));
                }

                @Override
                public InputStream getInputStream() {
                    try {
                        return new URL(resourceURL_).openStream();
                    } catch (Exception e) {
                    }
                    try {
                        return new FileInputStream("/" + resourceURL_);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return null;
                }
            };
        }
    }
    for (WebServerContentProvider contentProvider : webServer.contentProviderList) {
        WebServerContent webServerContent = contentProvider.getWebServerContent(httpRequest);
        if (webServerContent != null) {
            return webServerContent;
        }
    }
    return null;
}

[Buggy Hunk]
final String resourcePath = removeHTMLAnchor(parameter);

[Patch]
final String resourcePath = Utils.decodeURL(removeHTMLAnchor(parameter));