[Demonstration 1]

[Buggy Method]
private List<ThreadPoolError> checkFuturesForErrors(boolean forceLock) {
    try {
        //when finishing processing, we want to guarantee a lock, but when doing an interim check,
        //we just try to get the lock and back off if we can't
        if (forceLock) {
            futuresLock.lock();
        } else {
            if (!futuresLock.tryLock()) {
                return new ArrayList<>();
            }
        }
        List<ThreadPoolError> ret = new ArrayList<>();
        //check all the futures to see if any raised an error. Also, remove any futures that
        //we know have completed without error.
        Iterator<Map.Entry<Future, Callable>> it = futures.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<Future, Callable> entry = it.next();
            Future future = entry.getKey();
            if (future.isDone()) {
                //if it's done, remove from the iterator, which will remove from the map
                it.remove();
                //just calling get on the future will cause any exception to be raised in this thread
                try {
                    future.get();
                } catch (Exception ex) {
                    //the true exception will be inside an ExecutionException, so get it out and wrap in our own exception
                    Exception cause = (Exception) ex.getCause();
                    Callable callable = entry.getValue();
                    ret.add(new ThreadPoolError(callable, cause));
                }
            }
        }
        return ret;
    } finally {
        futuresLock.unlock();
    }
}

[Buggy Hunk]
Exception cause = (Exception)ex.getCause();

[Patch]
Throwable cause = ex.getCause();

[Demonstration 2]

[Buggy Method]
ImagePlus doObjectAnalysis(ImagePlus mask, ImagePlus maximaImp, ArrayList<FindFociResult> resultsArray, boolean createObjectMask, ObjectAnalysisResult objectAnalysisResult) {
    if (resultsArray == null || resultsArray.isEmpty()) {
        // Allow the analysis to continue if we are creating the object mask or storing the analysis results
        if (!createObjectMask && objectAnalysisResult == null)
            return null;
    }
    final int[] maskImage = extractMask(mask);
    if (maskImage == null)
        return null;
    // Track all the objects. Allow more than the 16-bit capacity for counting objects.
    final int[] objects = new int[maskImage.length];
    int id = 0;
    int[] objectState = new int[10];
    // Label for 2D/3D processing
    final boolean is2D = (maskImage.length == maxx_maxy);
    int[] pList = new int[100];
    for (int i = 0; i < maskImage.length; i++) {
        if (maskImage[i] != 0 && objects[i] == 0) {
            id++;
            // Store the original mask value of new object
            if (objectState.length <= id)
                objectState = Arrays.copyOf(objectState, (int) (objectState.length * 1.5));
            objectState[id] = maskImage[i];
            if (is2D)
                pList = expandObjectXY(maskImage, objects, i, id, pList);
            else
                pList = expandObjectXYZ(maskImage, objects, i, id, pList);
        }
    }
    // For each maximum, mark the object and original mask value (state).
    // Count the number of foci in each object.
    int[] fociCount = new int[id + 1];
    if (resultsArray != null) {
        for (int i = 0; i < resultsArray.size(); i++) {
            final FindFociResult result = resultsArray.get(i);
            final int x = result.x;
            final int y = result.y;
            final int z = (is2D) ? 0 : result.z;
            final int index = getIndex(x, y, z);
            final int objectId = objects[index];
            result.object = objectId;
            result.state = objectState[objectId];
            fociCount[objectId]++;
        }
    }
    // Store the number of objects and their orignal mask value
    if (objectAnalysisResult != null) {
        objectAnalysisResult.numberOfObjects = id;
        objectAnalysisResult.objectState = objectState;
        objectAnalysisResult.fociCount = fociCount;
    }
    // Show the object mask
    ImagePlus maskImp = null;
    if (createObjectMask) {
        // Check we do not exceed capcity
        if (id > MAXIMA_CAPCITY) {
            log("The number of objects exceeds the 16-bit capacity used for diplay: " + MAXIMA_CAPCITY);
            return null;
        }
        final int n = (is2D) ? 1 : maxz;
        ImageStack stack = new ImageStack(maxx, maxy, n);
        for (int z = 0, index = 0; z < n; z++) {
            final short[] pixels = new short[maxx_maxy];
            for (int i = 0; i < pixels.length; i++, index++) pixels[i] = (short) objects[index];
            stack.setPixels(pixels, z + 1);
        }
        // Create a new ImagePlus so that the stack and calibration can be set
        ImagePlus imp = new ImagePlus("", stack);
        imp.setCalibration(maximaImp.getCalibration());
        maskImp = FindFoci.showImage(imp, mask.getTitle() + " Objects", false);
    }
    return maskImp;
}

[Buggy Hunk]
final boolean is2D = (maskImage.length == maxx_maxy);

[Patch]
final boolean is2D = is2D();

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