[Demonstration 1]

[Buggy Method]
public byte[] fetchMagnet(String uri, int timeout, final int maxSize) {
    if (session == null) {
        return null;
    }
    add_torrent_params p = add_torrent_params.create_instance_disabled_storage();
    error_code ec = new error_code();
    libtorrent.parse_magnet_uri(uri, p, ec);
    if (ec.value() != 0) {
        throw new IllegalArgumentException(ec.message());
    }
    final sha1_hash info_hash = p.getInfo_hash();
    final byte[][] data = new byte[1][];
    final CountDownLatch signal = new CountDownLatch(1);
    AlertListener listener = new AlertListener() {

        @Override
        public int[] types() {
            return METADATA_ALERT_TYPES;
        }

        @Override
        public void alert(Alert<?> alert) {
            torrent_handle th = ((TorrentAlert<?>) alert).swig().getHandle();
            if (th == null || !th.is_valid() || th.info_hash().op_ne(info_hash)) {
                return;
            }
            AlertType type = alert.type();
            if (type.equals(AlertType.METADATA_RECEIVED)) {
                MetadataReceivedAlert a = ((MetadataReceivedAlert) alert);
                int size = a.metadataSize();
                if (size <= maxSize) {
                    data[0] = a.torrentData();
                }
            }
            signal.countDown();
        }
    };
    addListener(listener);
    boolean add = false;
    torrent_handle th = null;
    try {
        syncMagnet.lock();
        try {
            th = session.find_torrent(info_hash);
            if (th != null && th.is_valid()) {
                // we have a download with the same info-hash, let's wait
                add = false;
            } else {
                add = true;
            }
            if (add) {
                p.setName("fetch_magnet" + uri);
                p.setSave_path("fetch_magnet" + uri);
                long flags = p.get_flags();
                flags &= ~add_torrent_params.flags_t.flag_auto_managed.swigValue();
                p.set_flags(flags);
                ec.clear();
                th = session.add_torrent(p, ec);
                th.resume();
            }
        } finally {
            syncMagnet.unlock();
        }
        signal.await(timeout, TimeUnit.SECONDS);
    } catch (Throwable e) {
        LOG.error("Error fetching magnet", e);
    } finally {
        removeListener(listener);
        if (add && th != null && th.is_valid()) {
            session.remove_torrent(th);
        }
    }
    return data[0];
}

[Buggy Hunk]
if (add && th != null && th.is_valid()) {

[Patch]
if (session != null && add && th != null && th.is_valid()) {

[Demonstration 2]

[Buggy Method]
public List<String> get(long index, long endIndex) throws IOException {
    try {
        String output = con.getURL(baseURL + index + "-" + endIndex);
        if (output != null) {
            JSONArray data = new JSONArray(output);
            ArrayList<String> result = new ArrayList<String>(data.length());
            for (int i = 0; i < data.length(); i++) {
                String doc = data.getJSONObject(i).toString();
                result.add(doc);
            }
            return result;
        }
    } catch (Exception e) {
    }
    return null;
}

[Buggy Hunk]
JSONArray data=new JSONArray(output);

[Patch]
me.doubledutch.stroom.jsonjit.JSONArray data=new me.doubledutch.stroom.jsonjit.JSONArray(output);