[Demonstration 1]

[Buggy Method]
private void optimize(COSName objectName, PDImageXObject image) {
    try {
        LOG.debug("Optimizing image {}", objectName.getName());
        File tmpImageFile = ImageOptimizer.optimize(image.getImage(), parameters.getImageQuality(), parameters.getImageDpi(), parameters.getImageMaxWidthOrHeight());
        // we wrap the existing so we can identify it later as "in use" and already processed
        ReadOnlyFilteredCOSStream optimizedImage = ReadOnlyFilteredCOSStream.readOnly(image.getCOSObject());
        double sizeRate = tmpImageFile.length() * 100.0 / image.getCOSObject().getFilteredLength();
        // can be compressed
        if (sizeRate < 100) {
            String hash = Base64.getEncoder().encodeToString(MessageDigests.md5().digest(Files.readAllBytes(tmpImageFile.toPath())));
            optimizedImage = optimizedByHash.get(hash);
            // is it the same as something we already compressed?
            if (isNull(optimizedImage)) {
                LOG.debug(String.format("Compressed image to %.2f%% of original size", sizeRate));
                optimizedImage = createFromJpegFile(tmpImageFile);
                optimizedByHash.put(hash, optimizedImage);
            } else {
                LOG.debug("Reusing previously optimized image");
            }
        } else {
            LOG.trace(String.format("Skipping already compressed image, result is %.2f%% of original size", sizeRate));
        }
        COSDictionary resources = context.getResources().getCOSObject();
        COSDictionary xobjects = ofNullable(resources.getDictionaryObject(COSName.XOBJECT)).filter(b -> b instanceof COSDictionary).map(b -> (COSDictionary) b).orElseGet(() -> {
            COSDictionary ret = new COSDictionary();
            resources.setItem(COSName.XOBJECT, ret);
            return ret;
        });
        xobjects.setItem(objectName, optimizedImage);
        // free up resources used by the underlying COSStream
        // which stores both the filtered and unfiltered bytes[] and DecodeResult
        // potentially creating a large memory footprint
        image.getCOSObject().close();
    } catch (IOException | RuntimeException ex) {
        LOG.warn("Failed to optimize image, skipping and continuing with next.", ex);
    }
}

[Buggy Hunk]
image.getCOSObject().close();

[Patch]
image.getCOSObject().unDecode();

[Demonstration 2]

[Buggy Method]
private String getSuspectName() {
    String suspect = null;
    // Find suspect name in contacts db
    if (mCrime.getSuspectId() != null) {
        // dafault in case no permission to read name
        suspect = mCrime.getSuspectId();
        int permissionToReadContacts = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_CONTACTS);
        if (PackageManager.PERMISSION_GRANTED == permissionToReadContacts) {
            // TODO make a generic code to query without so much boilerplate
            String[] queryFields = new String[] { ContactsContract.Contacts.DISPLAY_NAME };
            // TODO make this in some utils
            String selection = ContactsContract.Contacts._ID + " = ?";
            String[] selectionArgs = new String[] { mCrime.getSuspectId() };
            Cursor c = getActivity().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, queryFields, selection, selectionArgs, null);
            try {
                if (c.getCount() > 0) {
                    c.moveToFirst();
                    suspect = c.getString(0);
                }
            } finally {
                c.close();
            }
        } else {
            askForReadContactsPermission();
        }
    }
    return suspect;
}

[Buggy Hunk]
String suspect = null;

[Patch]
String suspect = getString(R.string.crime_suspect_text);

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