[Demonstration 1]

[Buggy Method]
@Test
public void deserializeNonNullObject() throws Exception {
    // Expected object but provided string
    String json = new JSONObject().put("bad", "bad").toString();
    Exception ex1 = throwsException(() -> gson.fromJson(json, NonNullObjectModel.class));
    assertThat(ex1, instanceOf(JsonParseException.class));
    // test that non-null cannot be null
    Exception ex2 = throwsException(() -> gson.fromJson(new JSONObject().toString(), NonNullObjectModel.class));
    assertThat(ex2, instanceOf(JsonGracefulException.class));
}

[Buggy Hunk]
assertThat(ex1, instanceOf(JsonParseException.class));

[Patch]
assertThat(ex1, instanceOf(JsonGracefulException.class));

[Demonstration 2]

[Buggy Method]
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void recentChangesWithErrors() throws RetryableException, ContainedException {
    WikibaseRepository proxyRepo = new WikibaseRepository("http", "localhost", 8812);
    JSONObject changes = proxyRepo.fetchRecentChanges(new Date(System.currentTimeMillis()), 500);
    Map<String, Object> c = changes;
    assertThat(c, not(hasKey("continue")));
    assertThat(c, hasKey("query"));
    assertThat((Map<String, Object>) c.get("query"), hasKey("recentchanges"));
}

[Buggy Hunk]
JSONObject changes = proxyRepo.fetchRecentChanges(new Date(System.currentTimeMillis()), 500);

[Patch]
JSONObject changes = proxyRepo.fetchRecentChanges(new Date(System.currentTimeMillis()), null, 500);

[Demonstration 3]

[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));