[Demonstration 1]

[Buggy Method]
@Override
public JSONObject processInquiry(final JSONObject json) {
    // check if need reply
    try {
        boolean needReply = json.getBoolean("requestResponse");
        String type = json.getString("type");
        Log.d("Incoming Json", json.toString());
        int card = 0;
        if (json.has("card"))
            card = json.getInt("card");
        switch(type) {
            case "insert":
                // update the deck
                final int cardNo = card;
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        addCard(cardNo);
                    }
                });
                break;
            case "remove":
                final int cardNo2 = holdingCard.indexOf(json.getInt("score"));
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        removeCard(cardNo2);
                    }
                });
                break;
            case "request":
                // do this is no longer to remove card
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        makeToast("Your Turn! Select card to move");
                        clickable.release();
                    }
                });
                cardSelected.acquire();
                // selectedCard is now store INDEX of card which is selected
                JSONObject reply = new JSONObject();
                reply.put("card", selectedCard);
                return reply;
            case "score":
                final int score = json.getInt("score");
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        playerScore.setText(String.valueOf(score));
                    }
                });
                break;
            case "end":
                // game end
                win = json.getBoolean("win");
                // don't know if it has problem but hey... we are leaving
                listenServer.exit();
                break;
            default:
                Log.e("Player hand", "invalid type request");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

[Buggy Hunk]
final int cardNo2 = holdingCard.indexOf(json.getInt("score"));

[Patch]
final int cardNo2 = card;

[Demonstration 2]

[Buggy Method]
@Override
public void execute(Response resp) throws InterruptedException, SuspendExecution {
    // TODO Auto-generated method stub
    System.out.println("");
    this.displayPlan();
    System.out.println("");
    if (this.reqRate != 0) {
        this.running = true;
        this.reqsDetails.clear();
        for (int i = 0; i < httpreqlist.size(); i++) {
            Output outputrow = new Output();
            Date now = new Date();
            String strDate = sdf.format(now);
            outputrow.setRequest("TestPlan-" + this.getId() + "-Request-" + (i + 1));
            outputrow.setTime(strDate);
            outputrow.setInputload("0 reqs/sec");
            outputrow.setErrorrate("0%");
            outputrow.setAvgThroughput("0 reqs/sec");
            outputrow.setCurThroughput("0 reqs/sec");
            outputrow.setResponsetime("0 msec");
            MainController.outputlist.set(this.getOutputrowstart() + i, outputrow);
            List<Long> temp = new ArrayList<Long>();
            // Send Request Rate
            temp.add((long) 0);
            // Success Request count
            temp.add((long) 0);
            // Error Request count
            temp.add((long) 0);
            // Current Throughput
            temp.add((long) 0);
            // Response Time
            temp.add((long) 0);
            this.reqsDetails.put(httpreqlist.get(i), temp);
            // totalresptimes.put(httpreqlist.get(i), (long) 0);
        }
        /*
			 * System.out.println("Duration : "+ duration);
			 * System.out.println("Reqrate : "+ reqRate);
			 */
        Fiber.sleep(this.getStartDelay() * 1000);
        if (this.random == 1) {
            //System.out.println("Epoch Number : " + this.getId());
            logger.info("Epoch Number : " + this.getId());
        }
        int fiberArraysize = this.duration * this.reqRate;
        Fiber[] fibers = new Fiber[fiberArraysize];
        //System.out.println("Array Size = " + fiberArraysize);
        final int num = this.duration * this.reqRate;
        // int runningcount=num;
        this.setRunningcount(num);
        final RateLimiter rl = RateLimiter.create(this.reqRate);
        Date now1 = new Date();
        logger.info("starttime " + sdf.format(now1));
        this.outputFiber();
        final Semaphore sem = new Semaphore(1500000);
        for (int i = 0; i < num && MainController.test; i++) {
            rl.acquire();
            if (sem.availablePermits() == 0)
                logger.info("Maximum connections count reached, waiting...");
            sem.acquireUninterruptibly();
            new Fiber<Void>(() -> {
                try {
                    int k = 0;
                    Response currresp = new Response();
                    for (k = 0; k < this.testPlan.size(); k++) {
                        if (this.reqsDetails.get(k) != null) {
                            this.reqsDetails.get(k).set(0, (this.reqsDetails.get(k).get(0)) + 1);
                            long startTime = System.currentTimeMillis();
                            ((Feature) this.testPlan.get(k)).execute(currresp);
                            long elapsedTime = System.currentTimeMillis() - startTime;
                            if (currresp.getResponse().getStatusLine().toString().contains("OK")) {
                                this.reqsDetails.get(k).set(1, this.reqsDetails.get(k).get(1) + 1);
                                this.reqsDetails.get(k).set(2, this.reqsDetails.get(k).get(2));
                                this.reqsDetails.get(k).set(3, this.reqsDetails.get(k).get(3) + 1);
                                this.reqsDetails.get(k).set(4, this.reqsDetails.get(k).get(4) + elapsedTime);
                            } else {
                                this.reqsDetails.get(k).set(1, this.reqsDetails.get(k).get(1));
                                this.reqsDetails.get(k).set(2, this.reqsDetails.get(k).get(2) + 1);
                                this.reqsDetails.get(k).set(3, this.reqsDetails.get(k).get(3));
                                this.reqsDetails.get(k).set(4, this.reqsDetails.get(k).get(4));
                            }
                        } else {
                            ((Feature) this.testPlan.get(k)).execute(currresp);
                        }
                    }
                } catch (final Throwable t) {
                } finally {
                    // logger.info("inside finally");
                    sem.release();
                    this.setRunningcount(this.getRunningcount() - 1);
                }
            }).start();
        }
        Fiber.sleep(this.duration * 1000);
        while (true) {
            // logger.info(this.getRunningcount());
            if (this.runningcount <= 0) {
                this.running = false;
                break;
            }
        }
        Date now2 = new Date();
        logger.info("endtime " + sdf.format(now2));
        /*
			 * if (!MainController.test) { MainController.test = true; }
			 */
        try {
            fileWriter.flush();
            fileWriter.close();
        } catch (IOException e) {
            logger.info("Error while flushing/closing fileWriter !!!");
            e.printStackTrace();
        }
    }
    logger.info("TestPlan Finished");
}

[Buggy Hunk]
System.out.println(""); this.displayPlan(); System.out.println("");

[Patch]
this.displayPlan();

[Demonstration 3]

[Buggy Method]
public void messageArrived(String topic, MqttMessage message) throws Exception {
    String msgString = message.toString();
    JSONObject eventObject = new JSONObject(msgString);
    Gson gson = new GsonBuilder().create();
    Event event = gson.fromJson(eventObject.getString("event"), Event.class);
    String senseMeId = event.getMetaData().getDeviceId();
    if (msgString.contains("ULTRASONIC")) {
        sendSoundAlert(event, senseMeId);
    } else if (msgString.contains("PIR")) {
        sendLedAlert(event, senseMeId);
    } else {
        log.warn("Unknown message: " + message.toString());
    }
}

[Buggy Hunk]
Event event = gson.fromJson(eventObject.getString("event"), Event.class);

[Patch]
Event event = gson.fromJson(eventObject.getJSONObject("event").toString(), Event.class);