[Demonstration 1]

[Buggy Method]
private void loadAppPackageInfo() {
    AppInstallInfo appInfo = null;
    PackageManager packageManager = getPackageManager();
    List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
    for (int i = 0; i < pinfo.size(); i++) {
        PackageInfo packageInfo = pinfo.get(i);
        if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
            appInfo = new AppInstallInfo();
            appInfo.setId(i);
            appInfo.setIcon(packageInfo.applicationInfo.loadIcon(packageManager));
            appInfo.setName(packageInfo.applicationInfo.loadLabel(packageManager).toString());
            appInfo.setPackageName(packageInfo.packageName);
            appInfo.setVersionCode(packageInfo.versionCode);
            appInfo.setVersionName(packageInfo.versionName);
            appInfo.setState(Constants.APP_HAVE_INSTALLED);
            appInfo.setLastUpdateTime(packageInfo.lastUpdateTime);
            mAppInstallMap.put(packageInfo.packageName, appInfo);
        }
    }
}

[Buggy Hunk]
if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {

[Patch]
if (isDisplayApplication(packageInfo)) {

[Demonstration 2]

[Buggy Method]
private static void parseGzipHeader(InputStream in, byte[] header, CRC32 crc, byte[] scratch) throws IOException {
    final byte flags = header[3];
    final boolean hcrc = (flags & FHCRC) != 0;
    if (hcrc) {
        crc.update(header, 0, header.length);
    }
    if ((flags & FEXTRA) != 0) {
        Streams.readFully(in, header, 0, 2);
        if (hcrc) {
            crc.update(header, 0, 2);
        }
        int length = Memory.peekShort(scratch, 0, ByteOrder.LITTLE_ENDIAN) & 0xffff;
        while (length > 0) {
            int max = length > scratch.length ? scratch.length : length;
            int result = in.read(scratch, 0, max);
            if (result == -1) {
                throw new EOFException();
            }
            if (hcrc) {
                crc.update(scratch, 0, result);
            }
            length -= result;
        }
    }
    if ((flags & FNAME) != 0) {
        readZeroTerminated(in, crc, hcrc);
    }
    if ((flags & FCOMMENT) != 0) {
        readZeroTerminated(in, crc, hcrc);
    }
    if (hcrc) {
        Streams.readFully(in, header, 0, 2);
        short crc16 = Memory.peekShort(scratch, 0, ByteOrder.LITTLE_ENDIAN);
        if ((short) crc.getValue() != crc16) {
            throw new IOException("CRC mismatch");
        }
        crc.reset();
    }
}

[Buggy Hunk]
short crc16 = Memory.peekShort(scratch, 0, ByteOrder.LITTLE_ENDIAN);

[Patch]
short crc16 = Memory.peekShort(header, 0, ByteOrder.LITTLE_ENDIAN);

[Demonstration 3]

[Buggy Method]
private void initialiseZigBee() {
    logger.debug("Initialising ZigBee coordinator");
    // Start the discovery service
    discoveryService = new ZigBeeDiscoveryService(this);
    discoveryService.activate();
    // And register it as an OSGi service
    discoveryRegistration = bundleContext.registerService(DiscoveryService.class.getName(), discoveryService, new Hashtable<String, Object>());
    // ZigBeeNetworkStateSerializer networkStateSerializer = new ZigBeeNetworkStateSerializerImpl();
    // Configure the network manager
    networkManager = new ZigBeeNetworkManager(zigbeeTransport);
    // networkManager.setNetworkStateSerializer(networkStateSerializer);
    networkManager.setSerializer(serializerClass, deserializerClass);
    networkManager.addNetworkStateListener(this);
    networkManager.addNetworkNodeListener(this);
    logger.debug("Key initialise {}", networkKey);
    // Initialise the network
    ZigBeeInitializeResponse initResponse = networkManager.initialize();
    if (initResponse == ZigBeeInitializeResponse.FAILED) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, getI18nConstant(ZigBeeBindingConstants.OFFLINE_INITIALIZE_FAIL));
        return;
    }
    logger.debug("initResponse is {}", initResponse);
    // If we're not joined, then join
    if (initResponse == ZigBeeInitializeResponse.NOT_JOINED) {
        initializeNetwork = true;
    }
    logger.debug("initializeNetwork is {}", initializeNetwork);
    // Get the initial network configuration
    int currentChannel = networkManager.getZigBeeChannel();
    int currentPanId = networkManager.getZigBeePanId();
    ExtendedPanId currentExtendedPanId = networkManager.getZigBeeExtendedPanId();
    if (initializeNetwork) {
        networkManager.setZigBeeSecurityKey(networkKey);
        networkManager.setZigBeeChannel(channelId);
        networkManager.setZigBeePanId(panId);
        networkManager.setZigBeeExtendedPanId(extendedPanId);
    }
    // Call startup. The setting of the bring to ONLINE will be done via the state listener.
    if (!networkManager.startup(initializeNetwork)) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, getI18nConstant(ZigBeeBindingConstants.OFFLINE_STARTUP_FAIL));
        return;
    }
    // Get the final network configuration
    currentChannel = networkManager.getZigBeeChannel();
    currentPanId = networkManager.getZigBeePanId();
    currentExtendedPanId = networkManager.getZigBeeExtendedPanId();
    logger.debug("Initialise done....... {}  {}  {}", currentChannel, currentPanId, currentExtendedPanId);
    try {
        // Persist the network configuration
        Configuration configuration = editConfiguration();
        configuration.put(CONFIGURATION_PANID, currentPanId);
        configuration.put(CONFIGURATION_EXTENDEDPANID, String.format("%016X", currentExtendedPanId));
        configuration.put(CONFIGURATION_CHANNEL, currentChannel);
        // If the thing is defined statically, then this will fail and we will never start!
        updateConfiguration(configuration);
    } catch (IllegalStateException e) {
        logger.debug("Error updating configuration", e);
    }
}

[Buggy Hunk]
configuration.put(CONFIGURATION_EXTENDEDPANID, String.format("%016X", currentExtendedPanId));

[Patch]
configuration.put(CONFIGURATION_EXTENDEDPANID, currentExtendedPanId.toString());