[Demonstration 1]

[Buggy Method]
private static Dataset loadDataset(String path, String name, boolean asGrey, boolean keepBitWidth) throws ScanFileHolderException {
    if (!name.startsWith(IMAGE_NAME_PREFIX)) {
        throw new ScanFileHolderException("Dataset of name '" + name + "' does not contain prefix " + IMAGE_NAME_PREFIX);
    }
    String number = name.substring(IMAGE_NAME_FORMAT.length());
    int num = -1;
    try {
        num = Integer.parseInt(number) - 1;
    } catch (NumberFormatException e) {
    }
    if (num < 0) {
        throw new ScanFileHolderException("Dataset of name '" + name + "' does not contain image number");
    }
    IDataHolder holder = LoaderFactory.fetchData(path, false, num);
    if (holder != null) {
        return (Dataset) holder.getDataset(0);
    }
    File f = new File(path);
    ImageInputStream iis = null;
    try {
        iis = ImageIO.createImageInputStream(f);
    } catch (Exception e) {
        logger.error("Problem creating input stream for file " + path, e);
        throw new ScanFileHolderException("Problem creating input stream for file " + path, e);
    }
    if (iis == null) {
        logger.error("File format in '{}' cannot be read", path);
        throw new ScanFileHolderException("File format in '" + path + "' cannot be read");
    }
    Iterator<ImageReader> it = ImageIO.getImageReaders(iis);
    while (it.hasNext()) {
        ImageReader reader = it.next();
        reader.setInput(iis, false, true);
        Dataset data;
        try {
            data = createDataset(reader.read(num), asGrey, keepBitWidth);
            data.setName(name);
            holder = new DataHolder();
            holder.setFilePath(path);
            holder.addDataset(name, data);
            LoaderFactory.cacheData(holder, num);
            return data;
        } catch (IndexOutOfBoundsException e) {
            throw new ScanFileHolderException("Image number is incorrect");
        } catch (IOException e) {
            logger.error("Problem reading file", e);
        } catch (ScanFileHolderException e) {
            logger.error("Problem creating dataset", e);
        }
    }
    return null;
}

[Buggy Hunk]
String number = name.substring(IMAGE_NAME_FORMAT.length());

[Patch]
String number = name.substring(IMAGE_NAME_PREFIX.length());

[Demonstration 2]

[Buggy Method]
@ConfigurationDependency(pid = CONFIG_PID)
public synchronized void updated(Dictionary<String, ?> properties) throws SystemException {
    if (properties != null) {
        shouldStartBroker = Boolean.parseBoolean(Optional.ofNullable((String) properties.get(PROP_START_BROKER)).orElse("true"));
        connectionUri = Optional.ofNullable((String) properties.get(PROP_CONNECTIOn_URI)).orElse("tcp://localhost:61616");
        openwireTransport = Optional.ofNullable((String) properties.get(PROP_OPENWIRE_TRANSPORT)).orElse("tcp://localhost:61616");
        stompTransport = Optional.ofNullable((String) properties.get(PROP_STOMP_TRANSPORT)).orElse("tcp://localhost:61613");
        requestQueue = Optional.ofNullable((String) properties.get(GossCoreContants.PROP_REQUEST_QUEUE)).orElse("Request");
        //start();
    }
    //    	else {
    //    		if(isRunning()){
    //    			stop();
    //    		}
    //    	}
    //
    //	    	validatedAndStart();
    //
    //	    	String brokerConfig = "xbean:conf/" + (String) properties.get("goss.broker.file"); // config.get(PROP_ACTIVEMQ_CONFIG);
    //	        log.debug("Starting broker using config: " + brokerConfig);
    //	        System.setProperty("activemq.base", System.getProperty("user.dir"));
    //	        log.debug("ActiveMQ base directory set as: "+System.getProperty("activemq.base"));
    //	        //log.debug("Broker started not using xbean "+ (String)config.get(PROP_OPENWIRE_URI));
    //	        try {
    //	        	openWireUri = (String)properties.get(PROP_OPENWIRE_URI);
    //	        	start();
    //
    ////	        	broker = new BrokerService();
    ////
    ////				broker.addConnector((String)properties.get(PROP_OPENWIRE_URI));
    ////
    ////		        log.warn("Persistent storage is off");
    ////		        String datadir = System.getProperty("java.io.tmpdir") + File.separatorChar
    ////		                + "gossdata";
    ////		        broker.setDataDirectory(datadir);
    ////		        // TODO allow configuration.
    ////		        // Should start less than 10 seconds.
    ////		        broker.start(); //.waitUntilStarted(10000);
    //	        } catch (Exception e) {
    //				// TODO Auto-generated catch block
    //				e.printStackTrace();
    //			}
    //    	}
    //
    //        try {
    //			broker = BrokerFactory.createBroker(brokerConfig, true);
    //			broker.setDataDirectory(System.getProperty("activemq.base")+"/data");
    //			broker.waitUntilStarted();
    //			String brokerURI = (String)properties.get(PROP_OPENWIRE_URI);
    //			URI uri = URI.create(brokerURI);
    //			makeActiveMqConnection(uri, "goss", "goss");
    //		} catch (Exception e) {
    //			e.printStackTrace();
    //		}
}

[Buggy Hunk]
.ofNullable((String)properties.get(PROP_CONNECTIOn_URI))

[Patch]
.ofNullable((String)properties.get(PROP_CONNECTION_URI))

[Demonstration 3]

[Buggy Method]
private Response getResource(String path, boolean meta, String type, UriInfo uriInfo) {
    try {
        Resource resource = null;
        ResourceCollection resourceCollection = null;
        // Check, if the path is a resource or a collection or it does not exist.
        resource = mongoResourceDAO.getResource(path);
        if (resource == null) {
            resourceCollection = mongoCollectionDAO.getCollection(path);
            if (resourceCollection == null || meta)
                return Response.status(Response.Status.NOT_FOUND).type("application/xml").entity(new RepositoryException(Response.Status.NOT_FOUND, "Collection or resource not found")).build();
            else
                return RestHelper.multiFormatResponse(resourceCollection, ResourceCollection.class, type, uriInfo);
        }
        if (!meta) {
            // Obtain the resource content from virtuoso triple store.
            if (!type.equalsIgnoreCase(resource.getContentMimeType()) && RestHelper.isRDF(type)) {
                resource.setContent(virtuosoResourceDAO.getResource(resource.getContentUrl(), RestHelper.typeMap.get(type)).getContent());
            } else // Obtain the resource content mongo DB.
            {
                resource.setContent(mongoResourceDAO.getResourceContent(path).getContent());
            }
            if (resource.getContent() == null) {
                return Response.status(Response.Status.NO_CONTENT).build();
            }
            return Response.status(Response.Status.OK).header("content-length", resource.getContent().length).entity(resource.getContent()).type(type).build();
        } else {
            return RestHelper.multiFormatResponse(resource, Resource.class, type, uriInfo);
        }
    } catch (DatasourceException | JAXBException ex) {
        return Response.status(Status.INTERNAL_SERVER_ERROR).type("application/xml").entity(new RepositoryException(Status.INTERNAL_SERVER_ERROR, ex.getMessage())).build();
    }
}

[Buggy Hunk]
return Response.status(Response.Status.OK).header("content-length", resource.getContent().length).entity(resource.getContent()).type(type).build();

[Patch]
return Response.status(Response.Status.OK).header("content-length", resource.getContent().length).entity(resource.getContent()).build();