[Demonstration 1]

[Buggy Method]
@Path("/device/addprofile")
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces("application/json")
public Response addNewDeviceProfile(@FormParam("profilename") String profileName, @FormParam("vender") String vender, @FormParam("cpu") String cpu, @FormParam("memory") String memory, @FormParam("os") String os, @FormParam("disk") String disk, @FormParam("other") String other) {
    String tenantId = Integer.toString(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true));
    boolean status = false;
    if (tenantId != null) {
        deviceProfile deviceProfile = new deviceProfile();
        deviceProfile.setTenantId(tenantId);
        deviceProfile.setProfileName(profileName);
        deviceProfile.setVender(vender);
        deviceProfile.setCpu(cpu);
        deviceProfile.setMemory(memory);
        deviceProfile.setOs(os);
        deviceProfile.setDisk(disk);
        deviceProfile.setOther(other);
        try {
            status = laptopDAOImpl.addDeviceProfile(deviceProfile);
        } catch (DeviceTypeException e) {
            e.printStackTrace();
        }
    }
    return Response.status(Response.Status.OK).entity(status).build();
}

[Buggy Hunk]
deviceProfile deviceProfile = new deviceProfile();

[Patch]
DeviceProfile deviceProfile = new DeviceProfile();

[Demonstration 2]

[Buggy Method]
public void createAnAlarmForPromise(PromiseListItem promise) {
    Calendar promiseTime = DateUtils.convertStringToCalendar(promise.getmBaseTime());
    Intent i = promise.toIntent(mContext, PromisesAlarmsBroadcastReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
    mAlarmManager.set(AlarmManager.RTC_WAKEUP, promiseTime.getTimeInMillis(), pi);
}

[Buggy Hunk]
PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

[Patch]
PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, i, PendingIntent.FLAG_ONE_SHOT);

[Demonstration 3]

[Buggy Method]
@Async
public Future<Boolean> mine(Integer i) throws Exception {
    if (block == null)
        initializeService();
    if (difficulty == -1) {
        System.err.println("Complessità per il calcolo del blocco errata, impossibile minare");
        return new AsyncResult<Boolean>(Boolean.FALSE);
    }
    if (transactions.isEmpty() || block.getUserContainer() == null)
        return new AsyncResult<Boolean>(Boolean.FALSE);
    // Calcolo le maschere per il check dell'hash.
    calculateMasks();
    // Tempo di inizio mining
    long startTime = new Date().getTime();
    // Nonce
    Integer nonce = new Random().nextInt();
    Integer nonceStart = nonce;
    Integer nonceFinish = 0;
    float totalTime = 0;
    System.out.println("Nonce di partenza: " + nonce);
    // Hash del blocco
    byte[] hash;
    System.out.println("Sono il miner numero : " + i);
    do {
        // Genera nuovo hash
        hash = org.apache.commons.codec.digest.DigestUtils.sha256(block.toString() + nonce);
        // Incremento il nonce
        nonce++;
        if (nonce % 1000000 == 0)
            System.out.println("Sono il miner numero : " + i + " e sto minando nonce " + nonce);
    } while (!verifyHash(hash) && !stopMining);
    System.out.println("Sono il miner numero : " + i + " e mi sono fermato a minare");
    if (stopMining) {
        return new AsyncResult<Boolean>(Boolean.TRUE);
    }
    // avviso sonoro
    AudioUtil.alert();
    nonceFinish = nonce - 1;
    totalTime = (new Date().getTime() - startTime) / 1000.0f;
    // Calcolo hash corretto in esadecimale
    // Spiegazione nonce - 1: Viene fatto -1 perché nell'ultima iterazione
    // viene incrementato anche se l'hash era corretto.
    String hexHash = org.apache.commons.codec.digest.DigestUtils.sha256Hex(block.toString() + (nonce - 1));
    // Impostazione dell'hash e del nonce
    block.setHashBlock(hexHash);
    block.setNonce(nonce - 1);
    // private key null
    block.setSignature(CryptoUtil.sign(hexHash, privateKey));
    block.setMinerPublicKey(publicKey);
    block.setFatherBlockContainer(previousBlock.getHashBlock());
    // per ogni transazione mette il riferimento al blocco container
    int indexInBlock = 0;
    User temp;
    for (Transaction trans : transactions) {
        temp = userRepository.findByPublicKeyHash(trans.getAuthorContainer().getPublicKeyHash());
        if (temp == null) {
            userRepository.save(trans.getAuthorContainer());
        }
        trans.setBlockContainer(block.getHashBlock());
        trans.setIndexInBlock(indexInBlock);
        System.out.println(trans.getIndexInBlock());
        //transRepo.save(trans);
        indexInBlock++;
    }
    block.setTransactionsContainer(transactions);
    block.setCreationTime(Long.toString(System.currentTimeMillis()));
    System.out.println("Hash trovato: " + block.getHashBlock() + " con difficoltà: " + difficulty + " Nonce: " + nonce + " Tempo impiegato: " + totalTime + " secondi");
    System.out.println("Hash provati: " + (Math.abs(nonceFinish - nonceStart)) + " HashRate: " + (((Math.abs(nonceFinish - nonceStart)) / totalTime) / 1000000.0f) + " MH/s");
    // Salvo il blocco
    try {
        if (blockRepository != null)
            blockRepository.save(block);
        sendBlockToMiners();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return new AsyncResult<Boolean>(Boolean.TRUE);
}

[Buggy Hunk]
System.out.println("Sono il miner numero : " + i + " e sto minando nonce " + nonce);

[Patch]
System.out.println("Sono il miner numero : " + i + " e sto minando con nonce " + nonce+ "sto trovando il Blocco N° "+block.getChainLevel());