[Demonstration 1]

[Buggy Method]
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    this.callbackContext = callbackContext;
    if (action.equals(ACTION)) {
        // Expect four parameters: max representing the upperbound of the number of files
        // which can be returned each time, and three time stamps
        // TODO: max is supposed to be used when we return a list of images rather than a single image...
        @SuppressWarnings("unused")
        int max = args.getInt(0);
        double startTimeTick = args.getDouble(1);
        double endTimeTick = args.getDouble(2);
        double scanStartTimeTick = args.getDouble(3);
        boolean foundImage = false;
        boolean foundVideo = false;
        Result searchResult = new Result();
        IImageList imageList = ImageManager.makeImageList(context.getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI, ImageManager.SORT_DESCENDING);
        searchResult.totalImages = imageList.getCount();
        for (int i = 0; i < imageList.getCount(); i++) {
            IImage image = imageList.getImageAt(i);
            long timestamp = image.getDateTaken();
            // Count new images
            if (timestamp > scanStartTimeTick) {
                searchResult.newImages++;
                continue;
            }
            // Skip those pictures between scanStartTimeTick and startTimeTick
            if (timestamp >= startTimeTick) {
                continue;
            }
            // Once we pass endTimeTick, we can stop right now
            if (endTimeTick >= timestamp) {
                break;
            }
            // The first time we reach here, the image accessible is what we are interested
            // in.
            if (!foundImage) {
                searchResult.timestamp = timestamp;
                searchResult.path = image.fullSizeImageUri().toString();
                // To determine the extension of a file name, we may
                // map the MimeType to a known extension. Refer Apache Tika...
                // A lightweight way is to extract the extension from the
                // data path
                String datapath = image.getDataPath();
                searchResult.filename = datapath.substring(datapath.lastIndexOf("\\") + 1);
                foundImage = true;
            } else {
                // Count images waiting to be scanned next
                searchResult.waitingTobeUploaded++;
            }
        }
        IImageList videoList = ImageManager.makeImageList(context.getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI, ImageManager.SORT_DESCENDING);
        searchResult.totalImages += videoList.getCount();
        for (int i = 0; i < videoList.getCount(); i++) {
            IImage image = imageList.getImageAt(i);
            long timestamp = image.getDateTaken();
            // Count new images
            if (timestamp > scanStartTimeTick) {
                searchResult.newImages++;
                continue;
            }
            // Skip those pictures between scanStartTimeTick and startTimeTick
            if (timestamp >= startTimeTick) {
                continue;
            }
            // Once we pass endTimeTick, we can stop right now
            if (endTimeTick >= timestamp) {
                break;
            }
            // The first time we reach here, the image accessible is what we are interested
            // in.
            if (!foundVideo) {
                if (!foundImage || searchResult.timestamp < timestamp)
                    searchResult.timestamp = timestamp;
                searchResult.path = image.fullSizeImageUri().toString();
                // To determine the extension of a file name, we may
                // map the MimeType to a known extension. Refer Apache Tika...
                // A lightweight way is to extract the extension from the
                // data path
                String datapath = image.getDataPath();
                searchResult.filename = datapath.substring(datapath.lastIndexOf("\\") + 1);
                foundVideo = true;
            } else {
                // Count images waiting to be scanned next
                searchResult.waitingTobeUploaded++;
            }
        }
        // Return
        if (foundImage || foundVideo) {
            this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, searchResult.toJSONObject()));
        } else {
            this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "There are no photos."));
        }
    } else {
        this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, "Something wrong."));
    }
    return true;
}

[Buggy Hunk]
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,

[Patch]
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,

[Demonstration 2]

[Buggy Method]
void remove(long currTime) {
    synchronized (lock) {
        while (!ttlList.isEmpty()) {
            long timestamp = ttiList.back().timestamp;
            if ((currTime - timestamp) >= cachingTime) {
                Entry e = ttlList.removeBack();
                Pair<NodeIteratorImpl, NodeIteratorImpl> rv = map.get(e.address);
                map.remove(e.address);
                ttiList.remove(rv.getElement0().listLocation);
            } else {
                break;
            }
        }
    }
}

[Buggy Hunk]
long timestamp = ttiList.back().timestamp;

[Patch]
long timestamp = ttlList.back().timestamp;

[Demonstration 3]

[Buggy Method]
public SimpleFeatureType getTypeForTracks() {
    final SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder();
    featureTypeBuilder.setName("Point");
    featureTypeBuilder.add("id", String.class);
    featureTypeBuilder.add("timestamp", Integer.class);
    // set crs first
    featureTypeBuilder.setCRS(DefaultGeographicCRS.WGS84);
    // then add geometry
    featureTypeBuilder.add("location", Point.class);
    return featureTypeBuilder.buildFeatureType();
}

[Buggy Hunk]
featureTypeBuilder.add("timestamp", Integer.class);

[Patch]
featureTypeBuilder.add("timestamp", Long.class);