[Demonstration 1]

[Buggy Method]
private static int getTimeoutProperty(String timeOutPropertyName, String tenantDomain, int defaultVal) {
    IdentityProviderManager identityProviderManager = IdentityProviderManager.getInstance();
    IdentityProvider identityProvider = null;
    int timeout = defaultVal;
    try {
        identityProvider = identityProviderManager.getResidentIdP(tenantDomain);
        FederatedAuthenticatorConfig federatedAuthenticatorConfig = IdentityApplicationManagementUtil.getFederatedAuthenticator(identityProvider.getFederatedAuthenticatorConfigs(), IdentityApplicationConstants.Authenticator.IDPProperties.NAME);
        Property property = IdentityApplicationManagementUtil.getProperty(federatedAuthenticatorConfig.getProperties(), timeOutPropertyName);
        timeout = Integer.parseInt(property.getValue()) * 60;
    } catch (IdentityProviderManagementException e) {
        log.error("Error when accessing the IdentityProviderManager for tenant : " + tenantDomain, e);
    }
    return timeout;
}

[Buggy Hunk]
IdentityApplicationConstants.Authenticator.IDPProperties.NAME);

[Patch]
IdentityApplicationConstants.NAME);

[Demonstration 2]

[Buggy Method]
public static void error(String className, String message, Throwable ex) {
    System.out.println(className + " : " + message + " : " + ex.getMessage());
    log.error(className + " : " + message, ex);
}

[Buggy Hunk]
log.error(className+" : "+message, ex);

[Patch]
log.error(className+" : "+message +" "+ex.getMessage());

[Demonstration 3]

[Buggy Method]
private Map<Category, BufferedImage> generateChartImages(Date dateFrom, Date dateTo) {
    Map<Category, BufferedImage> imagesMap = new LinkedHashMap<Category, BufferedImage>();
    List<Category> categories = recordService.getCategories();
    for (Category cat : categories) {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        Collection<Record> records = recordService.getRecords(null, dateFrom, dateTo, cat);
        Map<String, Double> map = new HashMap<String, Double>();
        Double maxAmount = 0.0;
        for (Record r : records) {
            if (null == r || null == r.getAmount()) {
                logger.warn("Bad record: " + r);
                continue;
            }
            String name = r.getDesc().trim().toLowerCase();
            if (null != map.get(name)) {
                Double amount = map.get(name);
                amount += r.getAmount();
                map.put(name, amount);
            } else {
                map.put(name, r.getAmount());
            }
            if (maxAmount < map.get(name)) {
                maxAmount = map.get(name);
            }
        }
        for (String label : map.keySet()) {
            dataset.addValue(map.get(label), "S1", label);
        }
        JFreeChart jfreechart = ChartFactory.createBarChart(cat.getName(), null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);
        TextTitle title = new TextTitle(cat.getName());
        title.setFont(new Font("SansSerif", java.awt.Font.PLAIN, 12));
        jfreechart.setTitle(title);
        CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
        categoryplot.setDomainGridlinesVisible(true);
        categoryplot.setBackgroundPaint(Color.white);
        categoryplot.setDomainGridlinePaint(Color.gray);
        categoryplot.setRangeGridlinePaint(Color.gray);
        categoryplot.getDomainAxis().setMaximumCategoryLabelWidthRatio(0.8F);
        NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
        barrenderer.setDrawBarOutline(false);
        barrenderer.setSeriesPaint(0, new Color(77, 77, 250));
        barrenderer.setShadowVisible(false);
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            ChartUtilities.writeChartAsJPEG(out, jfreechart, 500, getSizeY(categories.size()));
            ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
            BufferedImage image = ImageIO.read(in);
            out.close();
            in.close();
            imagesMap.put(cat, image);
        } catch (IOException e) {
            logger.error(e.getMessage());
            Dispatcher.forwardEvent(AppEvents.ShowError, e.getMessage());
            return null;
        }
    }
    return imagesMap;
}

[Buggy Hunk]
ChartUtilities.writeChartAsJPEG(out, jfreechart, 500, getSizeY(categories.size()));

[Patch]
ChartUtilities.writeChartAsJPEG(out, jfreechart, 500, getSizeY(map.size()));