[Demonstration 1]

[Buggy Method]
private void ResolveOverlaps(JPanel pane, ArrayList<src.Image> images, Boolean timeline) {
    //pane = (Container) gui.getContentPane().getComponent(1);
    //pane=gui.getContentPane();
    double MIN_S;
    if (timeline) {
        MIN_S = (MIN / 10) - 4;
    } else {
        MIN_S = MIN;
    }
    ArrayList<Integer> containOverlaps = getAllOverlappingImages(pane, images, timeline);
    Random r = new Random();
    ArrayList<Integer> adjacency;
    int limit = images.size() / 5;
    int i = 0;
    PACKING_TRIAL_COUNT = 0;
    src.Image image;
    while (containOverlaps.size() > 0 && PACKING_TRIAL_COUNT <= limit) {
        if (INTERRUPT) {
            break;
        }
        // choose a random image containing overlaps
        i = r.nextInt(containOverlaps.size());
        if (timeline) {
            image = timelineLabelImageMap.get(containOverlaps.get(i));
        } else {
            image = labelImageMap.get(containOverlaps.get(i));
        }
        //TESTING
        //Image image = labelImageMap.get(1);
        // END TESTING
        IMAGE_TRIAL_COUNT = 0;
        double scaleDown = 1.2;
        adjacency = overlappedImages(image, pane, image.getId(), timeline);
        while (adjacency.size() > 0 && IMAGE_TRIAL_COUNT <= (limit / 2)) {
            if (INTERRUPT) {
                break;
            }
            if (IMAGE_TRIAL_COUNT > (limit / 8) && (image.getOriginal_height() / image.getHeight()) <= MIN_S && (image.getOriginal_width() / image.getWidth()) <= MIN_S && insideFrame(image)) {
                // Tried enough times. Now shrink and try
                animateMovement(pane, image, image.getHeight(), image.getWidth(), image.getHeight() / scaleDown, image.getWidth() / scaleDown, timeline);
                scaleDown += 0.2;
            }
            // Move the image to escape current overlaps
            MoveOverlappingImages(pane, image, adjacency, timeline);
            if (timeline) {
                adjacency = overlappedImages(timelineLabelImageMap.get(image.getId()), pane, image.getId(), timeline);
            } else {
                adjacency = overlappedImages(labelImageMap.get(image.getId()), pane, image.getId(), timeline);
            }
            IMAGE_TRIAL_COUNT++;
            System.out.println("Trying again...." + IMAGE_TRIAL_COUNT);
        }
        containOverlaps = getAllOverlappingImages(pane, images, timeline);
        PACKING_TRIAL_COUNT++;
    }
    if (INTERRUPT) {
        return;
    }
    if (containOverlaps.size() > 0) {
        if (INTERRUPT) {
            return;
        }
        // After 5 tries, overlaps still exist. Change positions of all images.
        try {
            // Remove all components
            System.out.println(containOverlaps.size() + " UNRESOLVED OVERLAPS");
            pane.removeAll();
            pane.revalidate();
            pane.repaint();
            if (timeline) {
                timelineLabels = new ArrayList<>();
                timelineLabelImageMap = new HashMap<>();
                // read all images in partcular frame again
            } else {
                labels = new ArrayList<>();
                labelImageMap = new HashMap<>();
                for (Image img : images) {
                    img.setHeight(img.getOriginal_height());
                    img.setWidth(img.getOriginal_width());
                    img.setLocation(null);
                    img.setImg(img.getOriginal_img());
                }
            }
            //wait
            long start = new Date().getTime();
            while (new Date().getTime() - start < 1L) {
            }
            // Add images in new positions
            addComponentsToPane(pane, images, timeline, true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else {
        if (INTERRUPT) {
            return;
        }
        System.out.println("Packed." + System.currentTimeMillis());
        //            while(ENLARGE_COUNT>=0){
        //                enlargeWherePossible(pane, images, timeline);
        //                ENLARGE_COUNT--;
        //            }
    }
}

[Buggy Hunk]
if (IMAGE_TRIAL_COUNT > (limit / 8) && (image.getOriginal_height() / image.getHeight()) <= MIN_S && (image.getOriginal_width() / image.getWidth()) <= MIN_S && insideFrame(image)) {

[Patch]
if (IMAGE_TRIAL_COUNT > (limit / 8) && (image.getOriginal_height() / image.getHeight()) <= MIN_S && (image.getOriginal_width() / image.getWidth()) <= MIN_S && insideFrame(pane,image)) {

[Demonstration 2]

[Buggy Method]
public List<Post> listPosts(int page, int limit, String... tags) throws IOException {
    String parameters = String.format("api_version=2&include_pools=1&page=%d&limit=%d&tags=%s", page, limit, Stream.of(tags).reduce((s1, s2) -> s1 + "+" + s2).orElse(""));
    URL url = new URL(siteConfig.getRootUrl() + POSTS_PATH + "?" + parameters);
    try (InputStream input = netIO.openStream(url)) {
        JsonNode root = mapper.readTree(input);
        JsonNode posts = root.get("posts");
        Map<Integer, Post> postMap = StreamSupport.stream(posts.spliterator(), false).map(post -> mapper.convertValue(post, Post.class)).collect(Collectors.toMap(Post::getId, Function.identity()));
        JsonNode pools = root.get("pools");
        Map<Integer, Pool> poolMap = StreamSupport.stream(pools.spliterator(), false).map(pool -> mapper.convertValue(pool, Pool.class)).collect(Collectors.toMap(Pool::getId, Function.identity()));
        JsonNode poolPosts = root.get("pool_posts");
        StreamSupport.stream(poolPosts.spliterator(), false).map(poolPost -> mapper.convertValue(poolPost, PoolPost.class)).forEach(poolPost -> {
            Post post = postMap.get(poolPost.getPostId());
            if (post != null) {
                post.setPool(poolMap.get(poolPost.getPoolId()));
            }
        });
        return new ArrayList<>(postMap.values());
    }
}

[Buggy Hunk]
.collect(Collectors.toMap(Pool::getId, Function.identity()));

[Patch]
.collect(Collectors.toMap(Pool::getId, Function.identity(), (a, b) -> a));

[Demonstration 3]

[Buggy Method]
private void removeOldestAccessedElementIfOversized() {
    if (getSize() > getMaxSize()) {
        final K entryToForget = removeAndReturnOldestAccessedElement();
        removeFromMap(entryToForget);
    }
}

[Buggy Hunk]
if (getSize() > getMaxSize()) {

[Patch]
if (getMapSize() > getMaxSize()) {