Buggy code:
public class PostgresSystemRSSManager extends SystemRSSManager { private static final Log log = LogFactory . getLog ( PostgresSystemRSSManager . class ) ; private RSSInstanceDAO rssInstanceDAO ; public PostgresSystemRSSManager ( Environment environment ) { } public Database addDatabase ( Database database ) throws RSSManagerException { } public void removeDatabase ( String rssInstanceName , String databaseName ) throws RSSManagerException { Connection conn = null ; Connection txConn = null ; PreparedStatement nativeRemoveDBStatement = null ; PreparedStatement nativeDetachUserStatement = null ; RSSInstance rssInstance = null ; try { rssInstance = resolveRSSInstanceByDatabase ( databaseName , RM_TYPE_SYSTEM ) ; } catch ( RSSDatabaseConnectionException e ) { String msg = ( "Database<seq2seq4repair_space>server<seq2seq4repair_space>error<seq2seq4repair_space>at<seq2seq4repair_space>removing<seq2seq4repair_space>database<seq2seq4repair_space>" + databaseName ) + ( e . getMessage ( ) ) ; handleException ( msg , e ) ; } if ( rssInstance == null ) { String msg = ( "Unresolvable<seq2seq4repair_space>RSS<seq2seq4repair_space>Instance.<seq2seq4repair_space>Database<seq2seq4repair_space>" + databaseName ) + "<seq2seq4repair_space>does<seq2seq4repair_space>not<seq2seq4repair_space>exist" ; PostgresSystemRSSManager . log . error ( msg ) ; throw new RSSManagerException ( msg ) ; } try { txConn = RSSManagerUtil . getTxConnection ( ) ; RSSManagerUtil . checkIfParameterSecured ( databaseName ) ; conn = getConnection ( rssInstance . getName ( ) ) ; conn . setAutoCommit ( true ) ; String removeDBQuery = ( "DROP<seq2seq4repair_space>DATABASE<seq2seq4repair_space>\"" + databaseName ) + "\"" ; <START_BUG> String detachUserQuery = ( ( "SELECT<seq2seq4repair_space>pg_terminate_backend(pg_stat_activity.pid)<seq2seq4repair_space>FROM<seq2seq4repair_space>pg_stat_activity<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "pg_stat_activity.datname<seq2seq4repair_space>=<seq2seq4repair_space>\"" ) + databaseName ) + "\"<seq2seq4repair_space>AND<seq2seq4repair_space>pid<seq2seq4repair_space><><seq2seq4repair_space>pg_backend_pid()" ; <END_BUG> nativeRemoveDBStatement = conn . prepareStatement ( removeDBQuery ) ; nativeDetachUserStatement = conn . prepareStatement ( detachUserQuery ) ; super . removeDatabase ( txConn , rssInstance . getName ( ) , databaseName , rssInstance , RM_TYPE_SYSTEM ) ; nativeDetachUserStatement . execute ( ) ; nativeRemoveDBStatement . execute ( ) ; RSSManagerUtil . commitTx ( txConn ) ; } catch ( Exception e ) { String msg = ( ( ( ( ( "Error<seq2seq4repair_space>while<seq2seq4repair_space>dropping<seq2seq4repair_space>the<seq2seq4repair_space>database<seq2seq4repair_space>'" + databaseName ) + "'<seq2seq4repair_space>on<seq2seq4repair_space>RSS<seq2seq4repair_space>" ) + "instance<seq2seq4repair_space>'" ) + ( rssInstance . getName ( ) ) ) + "'<seq2seq4repair_space>:<seq2seq4repair_space>" ) + ( e . getMessage ( ) ) ; RSSManagerUtil . rollBackTx ( txConn ) ; handleException ( msg , e ) ; } finally { RSSManagerUtil . cleanupResources ( null , nativeRemoveDBStatement , conn ) ; RSSManagerUtil . cleanupResources ( null , nativeDetachUserStatement , txConn ) ; } } public DatabaseUser addDatabaseUser ( DatabaseUser user ) throws RSSManagerException { } private void dropAddedUsers ( Map < String , String > mapUserwithInstance ) { } private void checkConnections ( RSSInstance [ ] instances ) throws RSSManagerException { } public void removeDatabaseUser ( String type , String username ) throws RSSManagerException { } public void updateDatabaseUserPrivileges ( DatabasePrivilegeSet privileges , DatabaseUser user , String databaseName ) throws RSSManagerException { } private void createPostgresPrivilegeSet ( PostgresPrivilegeSet postgresPrivs , DatabasePrivilegeSet privileges ) { } public void attachUser ( UserDatabaseEntry entry , DatabasePrivilegeSet privileges ) throws RSSManagerException { } public void detachUser ( UserDatabaseEntry entry ) throws RSSManagerException { } private void composePreparedStatement ( Connection con , String databaseName , String username , PostgresPrivilegeSet privileges ) throws SQLException , RSSManagerException { } private void composePreparedStatement ( Connection con , String databaseName , String username , PostgresPrivilegeSet privileges , PostgresSystemRSSManager . PrivilegeTypes type , boolean grantEnable ) throws SQLException , RSSManagerException { } private void grantConnect ( Connection con , String databaseName , String username ) throws SQLException , RSSManagerException { } private void grantUsage ( Connection con , String databaseName , String username ) throws SQLException , RSSManagerException { } private String createPrivilegesString ( final PostgresPrivilegeSet privileges , PostgresSystemRSSManager . PrivilegeTypes type ) { } private void addToPrivilegesList ( final List < PostgresSystemRSSManager . Privileges > privList , PostgresSystemRSSManager . Privileges privEnum , String priv ) { } private void disAllowedConnect ( Connection conn , String databaseName , String userName ) throws SQLException , RSSManagerException { } private void revokeAllPrivileges ( Connection conn , String databaseName , String userName ) throws SQLException , RSSManagerException { } public boolean isDatabaseExist ( String rssInstanceName , String databaseName ) throws RSSManagerException { } public Database getDatabase ( String rssInstanceName , String databaseName ) throws RSSManagerException { } public boolean isDatabaseUserExist ( String rssInstanceName , String username ) throws RSSManagerException { } @ Override public DatabaseUser editDatabaseUser ( DatabaseUser databaseUser ) { } private enum Privileges { SELECT , INSERT , UPDATE , DELETE , TRUNCATE , REFERENCES , TRIGGER , CREATE , CONNECT , TEMPORARY , EXECUTE , USAGE , TEMP ; } private enum PrivilegeTypes { TABLE , DATABASE , SEQUENCE , FUNCTION , LANGUAGE , LARGE_OBJECT , SCHEMA , TABLESPACE ; } @ Override public void createSnapshot ( String databaseName ) throws RSSManagerException { } }

Fix:
String detachUserQuery = ( ( "SELECT<seq2seq4repair_space>pg_terminate_backend(pg_stat_activity.pid)<seq2seq4repair_space>FROM<seq2seq4repair_space>pg_stat_activity<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "pg_stat_activity.datname<seq2seq4repair_space>=<seq2seq4repair_space>'" ) + databaseName ) + "'<seq2seq4repair_space>AND<seq2seq4repair_space>pid<seq2seq4repair_space><><seq2seq4repair_space>pg_backend_pid()" ;