[Demonstration 1]

[Buggy Method]
@Test
public void then_shouldBeCalledTwice_whenParentIsReused() throws InterruptedException {
    // create parent promise
    TriggeredPromise<Boolean> triggerPromise = new TriggeredPromise<>(() -> true);
    // add error handler
    triggerPromise.promise.error(e -> {
        fail("Unexpected error: " + e.getMessage());
    });
    // add child 1
    Box<Integer> result1 = new Box<>();
    Promise<Integer> promise1 = triggerPromise.promise.then(result -> {
        // assert
        assertEquals(result, Boolean.TRUE);
        // capture value
        result1.value = 1;
        // return
        return result1.value;
    });
    // add child 2
    Box<Integer> result2 = new Box<>();
    Promise<Integer> promise2 = triggerPromise.promise.then(result -> {
        // assert
        assertEquals(result, Boolean.TRUE);
        // capture value
        result2.value = 2;
        // return
        return result2.value;
    });
    // trigger
    triggerPromise.trigger();
    // wait
    triggerPromise.join();
    // assert
    assertEquals(result2.value, Integer.valueOf(2));
    assertEquals(result1.value, Integer.valueOf(1));
}

[Buggy Hunk]
triggerPromise.join();

[Patch]
triggerPromise.join(10000);

[Demonstration 2]

[Buggy Method]
@Override
public void afterPropertiesSet() throws Exception {
    JobTask jobTask = new JobTask();
    Map<String, Object> params = new HashMap<>();
    params.putIfAbsent(ShardConstant.SHARD_VALUE, "couponCodeExpired");
    jobTask.setParams(params);
    jobTask.setTaskId(UUID.randomUUID().toString());
    //天3点和18点各执行一次
    jobTask.setCronExpression("0 0 3,18 * * ?");
    jobHandler.raiseJob(jobTask);
}

[Buggy Hunk]
jobTask.setTaskId(UUID.randomUUID().toString());

[Patch]
jobTask.setTaskId("coupon-code-expired-job");

[Demonstration 3]

[Buggy Method]
public static boolean readNeighbors(int myId, List<String> neighbors) {
    System.out.println("Reading topology" + myId);
    try {
        Scanner sc = new Scanner(new FileReader("topology" + myId));
        while (sc.hasNext()) {
            String neighbor = sc.nextLine();
            neighbors.add(neighbor);
        }
    } catch (IOException e) {
        return false;
    }
    System.out.println(neighbors.toString());
    return true;
}

[Buggy Hunk]
Scanner sc = new Scanner(new FileReader("topology" + myId));

[Patch]
Scanner sc = new Scanner(new FileReader("topology" + myId + ".txt"));