[Demonstration 1]

[Buggy Method]
public JMXConnector getJMXConnection(final boolean registerURL) {
    JMXConnector connection = null;
    // Reference to repository
    Repository repository = Repository.get();
    try {
        String jmxSerURL = "";
        if (LOGGER.infoEnabled()) {
            LOGGER.info(resourceBundle.getString("LOG_MSG_USE_LOCATOR_VALUE") + ":" + repository.getJmxUseLocator());
        }
        if (repository.getJmxUseLocator()) {
            JmxManagerInfo jmxManagerInfo = getManagerInfoFromLocator(repository);
            if (jmxManagerInfo.port == 0) {
                if (LOGGER.infoEnabled()) {
                    LOGGER.info(resourceBundle.getString("LOG_MSG_LOCATOR_COULD_NOT_FIND_MANAGER"));
                }
            } else {
                if (LOGGER.infoEnabled()) {
                    LOGGER.info(resourceBundle.getString("LOG_MSG_LOCATOR_FOUND_MANAGER") + " : " + resourceBundle.getString("LOG_MSG_HOST") + " : " + jmxManagerInfo.host + " & " + resourceBundle.getString("LOG_MSG_PORT") + " : " + jmxManagerInfo.port + (jmxManagerInfo.ssl ? resourceBundle.getString("LOG_MSG_WITH_SSL") : resourceBundle.getString("LOG_MSG_WITHOUT_SSL")));
                }
                jmxSerURL = formJMXServiceURLString(jmxManagerInfo.host, String.valueOf(jmxManagerInfo.port));
            }
        } else {
            if (LOGGER.infoEnabled()) {
                LOGGER.info(resourceBundle.getString("LOG_MSG_HOST") + " : " + this.serverName + " & " + resourceBundle.getString("LOG_MSG_PORT") + " : " + this.port);
            }
            jmxSerURL = formJMXServiceURLString(this.serverName, this.port);
        }
        if (StringUtils.isNotNullNotEmptyNotWhiteSpace(jmxSerURL)) {
            JMXServiceURL url = new JMXServiceURL(jmxSerURL);
            String[] creds = { this.userName, this.userPassword };
            Map<String, Object> env = new HashMap<String, Object>();
            env.put(JMXConnector.CREDENTIALS, creds);
            if (repository.isUseSSLManager()) {
                // use ssl to connect
                env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory());
            }
            LOGGER.info("Connecting to jmxURL : " + jmxSerURL);
            connection = JMXConnectorFactory.connect(url, env);
            // Register Pulse URL if not already present in the JMX Manager
            if (registerURL) {
                registerPulseUrlToManager(connection);
            }
        }
    } catch (Exception e) {
        if (e instanceof UnknownHostException) {
            cluster.setConnectionErrorMsg(resourceBundle.getString("LOG_MSG_JMX_CONNECTION_UNKNOWN_HOST"));
        }
        StringWriter swBuffer = new StringWriter();
        PrintWriter prtWriter = new PrintWriter(swBuffer);
        e.printStackTrace(prtWriter);
        LOGGER.severe("Exception Details : " + swBuffer.toString() + "\n");
        if (this.conn != null) {
            try {
                this.conn.close();
            } catch (Exception e1) {
                LOGGER.severe("Error closing JMX connection " + swBuffer.toString() + "\n");
            }
            this.conn = null;
        }
    }
    return connection;
}

[Buggy Hunk]
String[] creds = {this.userName, this.userPassword};

[Patch]
String[] creds = {this.cluster.getJmxUserName(), this.cluster.getJmxUserPassword()};

[Demonstration 2]

[Buggy Method]
@Override
public JdbcConnectionContainer openConnection(ConnectionDescriptor connectionDescriptor) {
    final Connection connection;
    try {
        connection = JdbcDataSource.getInstance(connectionDescriptor).getConnection();
    } catch (Exception e) {
        throw new ConnectionException(e);
    }
    return new JdbcConnectionContainer(connection);
}

[Buggy Hunk]
connection = JdbcDataSource.getInstance(connectionDescriptor).getConnection();

[Patch]
connection = jdbcDataSource.getInstance(connectionDescriptor).getConnection();

[Demonstration 3]

[Buggy Method]
private void init() throws SQLException {
    connection = DriverManager.getConnection("jdbc:sqlite:cache.db");
    Statement stmt = connection.createStatement();
    stmt.executeUpdate("CREATE TABLE IF NOT EXISTS cache (dayoffset INT NOT NULL, restaurant INT NOT NULL, response BLOB NOT NULL, timestamp INT NOT NULL) ");
}

[Buggy Hunk]
connection = DriverManager.getConnection("jdbc:sqlite:cache.db");

[Patch]
connection = AppInitializer.dbConnection;