[Demonstration 1]

[Buggy Method]
public static final byte[] serialize(Object value, Object meta, boolean insertMeta) {
    if (value == null) {
        return new byte[0];
    }
    // Try to serialize content (type-safe serialization)
    if ((value == null || value instanceof Serializable) && (meta == null || meta instanceof Serializable)) {
        Map<Object, Object> map = insertMeta(value, meta, insertMeta);
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
            baos.write(1);
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(value);
            oos.flush();
            return baos.toByteArray();
        } catch (IOException ignored) {
        } finally {
            removeMeta(map);
        }
    }
    // Write content as JSON
    byte[] bytes = TreeWriterRegistry.getWriter(null).toString(value, meta, false, insertMeta).getBytes(StandardCharsets.UTF_8);
    byte[] copy = new byte[bytes.length + 1];
    System.arraycopy(bytes, 0, copy, 1, bytes.length);
    return copy;
}

[Buggy Hunk]
} catch (IOException ignored) {

[Patch]
} catch (Throwable ignored) {

[Demonstration 2]

[Buggy Method]
public void handleError(final ClientHttpResponse response) throws IOException {
    if (!HttpStatus.Series.CLIENT_ERROR.equals(response.getStatusCode().series())) {
        // We should only care about 400 level errors. Ex: A 500 server error shouldn't
        // be an oauth related error.
        errorHandler.handleError(response);
    } else {
        // Need to use buffered response because input stream may need to be consumed multiple times.
        ClientHttpResponse bufferedResponse = new ClientHttpResponse() {

            private byte[] lazyBody;

            public HttpStatus getStatusCode() throws IOException {
                return response.getStatusCode();
            }

            public synchronized InputStream getBody() throws IOException {
                if (lazyBody == null) {
                    InputStream bodyStream = response.getBody();
                    if (bodyStream != null) {
                        lazyBody = FileCopyUtils.copyToByteArray(bodyStream);
                    } else {
                        lazyBody = new byte[0];
                    }
                }
                return new ByteArrayInputStream(lazyBody);
            }

            public HttpHeaders getHeaders() {
                return response.getHeaders();
            }

            public String getStatusText() throws IOException {
                return response.getStatusText();
            }

            public void close() {
                response.close();
            }

            public int getRawStatusCode() throws IOException {
                return response.getRawStatusCode();
            }
        };
        try {
            HttpMessageConverterExtractor<OAuth2Exception> extractor = new HttpMessageConverterExtractor<OAuth2Exception>(OAuth2Exception.class, messageConverters);
            try {
                OAuth2Exception body = extractor.extractData(bufferedResponse);
                if (body != null) {
                    // If we can get an OAuth2Exception already from the body, it is likely to have more information than
                    // the header does, so just re-throw it here.
                    throw body;
                }
            } catch (RestClientException e) {
                // ignore
            }
            // first try: www-authenticate error
            List<String> authenticateHeaders = bufferedResponse.getHeaders().get("WWW-Authenticate");
            if (authenticateHeaders != null) {
                for (String authenticateHeader : authenticateHeaders) {
                    maybeThrowExceptionFromHeader(authenticateHeader, OAuth2AccessToken.BEARER_TYPE);
                    maybeThrowExceptionFromHeader(authenticateHeader, OAuth2AccessToken.OAUTH2_TYPE);
                }
            }
            // then delegate to the custom handler
            errorHandler.handleError(bufferedResponse);
        } catch (OAuth2Exception ex) {
            if (bufferedResponse.getRawStatusCode() == 401 || !ex.getClass().equals(OAuth2Exception.class)) {
                // Status code 401 should always mean that we need a legitimate token.
                // Caught a specific, derived class so this is not just some generic error
                throw ex;
            } else {
                // This is not an exception that is really understood, so allow our delegate
                // to handle it in a non-oauth way
                errorHandler.handleError(bufferedResponse);
            }
        }
    }
}

[Buggy Hunk]
if (bufferedResponse.getRawStatusCode() == 401 || ! ex.getClass().equals(OAuth2Exception.class)) {

[Patch]
if (bufferedResponse.getRawStatusCode() == 403 || bufferedResponse.getRawStatusCode() == 401 || ! ex.getClass().equals(OAuth2Exception.class)) {

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