Buggy code:
public class JDBCDatabase implements IDatabase { private static final Logger logger = LoggerFactory . getLogger ( JDBCDatabase . class ) ; private static final String JDBC_URL = "jdbc:mysql:////localhost" + "//cloudcoder?user=root&password=root" ; private static class InUseConnection { Connection conn ; int refCount ; } private ThreadLocal < JDBCDatabase . InUseConnection > threadLocalConnection = new ThreadLocal < JDBCDatabase . InUseConnection > ( ) ; private Connection getConnection ( ) throws SQLException { } private void releaseConnection ( ) throws SQLException { } @ Override public ConfigurationSetting getConfigurationSetting ( final ConfigurationSettingName name ) { } @ Override public User authenticateUser ( final String userName , final String password ) { } @ Override public Problem getProblem ( final User user , final int problemId ) { } @ Override public Change getMostRecentChange ( final User user , final int problemId ) { } @ Override public Change getMostRecentFullTextChange ( final User user , final int problemId ) { } @ Override public List < Change > getAllChangesNewerThan ( final User user , final int problemId , final int baseRev ) { } @ Override public List < ? extends Object [ ] > getCoursesForUser ( final User user ) { } @ Override public List < Problem > getProblemsInCourse ( final User user , final Course course ) { } @ Override public void storeChanges ( final Change [ ] changeList ) { } @ Override public List < TestCase > getTestCasesForProblem ( final int problemId ) { } @ Override public void insertSubmissionReceipt ( final SubmissionReceipt receipt , final TestResult [ ] testResultList_ ) { } @ Override public void getOrAddLatestSubmissionReceipt ( final User user , final Problem problem ) { databaseRun ( new AbstractDatabaseRunnable < SubmissionReceipt > ( ) { @ Override public SubmissionReceipt run ( Connection conn ) throws SQLException { <START_BUG> PreparedStatement stmt = prepareStatement ( conn , ( "select<seq2seq4repair_space>r.*<seq2seq4repair_space>from<seq2seq4repair_space>submission_receipts<seq2seq4repair_space>as<seq2seq4repair_space>r,<seq2seq4repair_space>events<seq2seq4repair_space>as<seq2seq4repair_space>e<seq2seq4repair_space>" + ( ( ( ( "<seq2seq4repair_space>where<seq2seq4repair_space>r.event_id<seq2seq4repair_space>=<seq2seq4repair_space>e.id<seq2seq4repair_space>" + "<seq2seq4repair_space>and<seq2seq4repair_space>e.id<seq2seq4repair_space>=<seq2seq4repair_space>(select<seq2seq4repair_space>max(ee.id)<seq2seq4repair_space>from<seq2seq4repair_space>submission_receipts<seq2seq4repair_space>as<seq2seq4repair_space>rr,<seq2seq4repair_space>events<seq2seq4repair_space>as<seq2seq4repair_space>ee<seq2seq4repair_space>" ) + "<seq2seq4repair_space>where<seq2seq4repair_space>rr.event_id<seq2seq4repair_space>=<seq2seq4repair_space>ee.id<seq2seq4repair_space>" ) + "<seq2seq4repair_space>and<seq2seq4repair_space>ee.problem_id<seq2seq4repair_space>=<seq2seq4repair_space>?<seq2seq4repair_space>" ) + "<seq2seq4repair_space>and<seq2seq4repair_space>ee.user_id<seq2seq4repair_space>=<seq2seq4repair_space>?)" ) ) ) ; <END_BUG> stmt . setInt ( 1 , problem . getProblemId ( ) ) ; stmt . setInt ( 2 , user . getId ( ) ) ; ResultSet resultSet = executeQuery ( stmt ) ; if ( resultSet . next ( ) ) { SubmissionReceipt submissionReceipt = new SubmissionReceipt ( ) ; load ( submissionReceipt , resultSet , 1 ) ; load ( submissionReceipt . getEvent ( ) , resultSet , ( ( SubmissionReceipt . NUM_FIELDS ) + 1 ) ) ; return submissionReceipt ; } SubmissionStatus status = SubmissionStatus . STARTED ; SubmissionReceipt receipt = SubmissionReceipt . create ( user , problem , status , ( - 1 ) ) ; doInsertSubmissionReceipt ( receipt , new TestResult [ 0 ] , conn , this ) ; return receipt ; } @ Override public String getDescription ( ) { return "adding<seq2seq4repair_space>initial<seq2seq4repair_space>submission<seq2seq4repair_space>receipt<seq2seq4repair_space>if<seq2seq4repair_space>necessary" ; } } ) ; } private < E > E databaseRun ( DatabaseRunnable < E > databaseRunnable ) { } private void storeEvents ( final IContainsEvent [ ] containsEventList , Connection conn , AbstractDatabaseRunnable < ? > dbRunnable ) throws SQLException { } private void doInsertSubmissionReceipt ( final SubmissionReceipt receipt , final TestResult [ ] testResultList_ , Connection conn , AbstractDatabaseRunnable < ? > dbRunnable ) throws SQLException { } private void load ( ConfigurationSetting configurationSetting , ResultSet resultSet , int index ) throws SQLException { } private void load ( User user , ResultSet resultSet , int index ) throws SQLException { } protected void load ( Problem problem , ResultSet resultSet , int index ) throws SQLException { } protected void load ( Change change , ResultSet resultSet , int index ) throws SQLException { } protected void load ( Course course , ResultSet resultSet , int index ) throws SQLException { } protected void load ( Term term , ResultSet resultSet , int index ) throws SQLException { } protected void load ( TestCase testCase , ResultSet resultSet , int index ) throws SQLException { } protected void load ( SubmissionReceipt submissionReceipt , ResultSet resultSet , int index ) throws SQLException { } protected void load ( Event event , ResultSet resultSet , int index ) throws SQLException { } protected void storeNoId ( Event event , PreparedStatement stmt , int index ) throws SQLException { } protected void storeNoId ( Change change , PreparedStatement stmt , int index ) throws SQLException { } protected void storeNoId ( SubmissionReceipt receipt , PreparedStatement stmt , int index ) throws SQLException { } protected void storeNoId ( TestResult testResult , PreparedStatement stmt , int index ) throws SQLException { } }

Fix:
PreparedStatement stmt = prepareStatement ( conn , ( "select<seq2seq4repair_space>r.*,<seq2seq4repair_space>e.*<seq2seq4repair_space>from<seq2seq4repair_space>submission_receipts<seq2seq4repair_space>as<seq2seq4repair_space>r,<seq2seq4repair_space>events<seq2seq4repair_space>as<seq2seq4repair_space>e<seq2seq4repair_space>" + ( ( ( ( "<seq2seq4repair_space>where<seq2seq4repair_space>r.event_id<seq2seq4repair_space>=<seq2seq4repair_space>e.id<seq2seq4repair_space>" + "<seq2seq4repair_space>and<seq2seq4repair_space>e.id<seq2seq4repair_space>=<seq2seq4repair_space>(select<seq2seq4repair_space>max(ee.id)<seq2seq4repair_space>from<seq2seq4repair_space>submission_receipts<seq2seq4repair_space>as<seq2seq4repair_space>rr,<seq2seq4repair_space>events<seq2seq4repair_space>as<seq2seq4repair_space>ee<seq2seq4repair_space>" ) + "<seq2seq4repair_space>where<seq2seq4repair_space>rr.event_id<seq2seq4repair_space>=<seq2seq4repair_space>ee.id<seq2seq4repair_space>" ) + "<seq2seq4repair_space>and<seq2seq4repair_space>ee.problem_id<seq2seq4repair_space>=<seq2seq4repair_space>?<seq2seq4repair_space>" ) + "<seq2seq4repair_space>and<seq2seq4repair_space>ee.user_id<seq2seq4repair_space>=<seq2seq4repair_space>?)" ) ) ) ;