Buggy code:
@ RestController public class InsightController { @ RequestMapping ( "//customer//{crn}" ) public String customer ( @ PathVariable String crn ) { JSONObject json = new JSONObject ( ) ; Connection connection = null ; try { connection = getConnection ( ) ; Map < String , String [ ] > displayNames = new HashMap < String , String [ ] > ( ) ; Statement stmt = connection . createStatement ( ) ; ResultSet rs1 = stmt . executeQuery ( "select<seq2seq4repair_space>column_name,<seq2seq4repair_space>section_name,<seq2seq4repair_space>display_name<seq2seq4repair_space>from<seq2seq4repair_space>display_names<seq2seq4repair_space>dn<seq2seq4repair_space>join<seq2seq4repair_space>sections<seq2seq4repair_space>se<seq2seq4repair_space>on<seq2seq4repair_space>se.section_id<seq2seq4repair_space>=<seq2seq4repair_space>dn.section_id<seq2seq4repair_space>order<seq2seq4repair_space>by<seq2seq4repair_space>se.display_order,<seq2seq4repair_space>dn.display_order" ) ; while ( rs1 . next ( ) ) { displayNames . put ( rs1 . getString ( "column_name" ) , new String [ ] { rs1 . getString ( "section_name" ) , rs1 . getString ( "display_name" ) } ) ; } ResultSet rs = stmt . executeQuery ( ( ( "select<seq2seq4repair_space>crn,<seq2seq4repair_space>title,<seq2seq4repair_space>firstname,<seq2seq4repair_space>lastname,<seq2seq4repair_space>after_hours_phone,<seq2seq4repair_space>email,<seq2seq4repair_space>street_number,<seq2seq4repair_space>street_name,<seq2seq4repair_space>cu.suburb,<seq2seq4repair_space>state,<seq2seq4repair_space>customer_type,<seq2seq4repair_space>gender,<seq2seq4repair_space>marital_status,<seq2seq4repair_space>nab_segment,<seq2seq4repair_space>is_nab_main_bank,<seq2seq4repair_space>retail_customer_rating,<seq2seq4repair_space>ib_activity,<seq2seq4repair_space>cc_activity,<seq2seq4repair_space>branch_activity,<seq2seq4repair_space>nab_atm_activity,<seq2seq4repair_space>num_dd_competitors,<seq2seq4repair_space>num_competitor_debits,<seq2seq4repair_space>value_competitor_debits,<seq2seq4repair_space>most_recent_competitor,<seq2seq4repair_space>total_most_recent_comp_debits,<seq2seq4repair_space>most_recent_comp_debit_dt,<seq2seq4repair_space>most_recent_comp_debit_value,<seq2seq4repair_space>second_recent_competitor,<seq2seq4repair_space>total_second_competitor_debits,<seq2seq4repair_space>second_comp_debit_dt,<seq2seq4repair_space>second_comp_debit_value,<seq2seq4repair_space>num_siebel_contacts,<seq2seq4repair_space>most_recent_siebel_response,<seq2seq4repair_space>siebel_activity_code,<seq2seq4repair_space>num_previous_ecl_applications,<seq2seq4repair_space>most_recent_comp_debit_dt,<seq2seq4repair_space>most_recent_product_applied,<seq2seq4repair_space>most_recent_prod_app_decision,<seq2seq4repair_space>occupation_cd,<seq2seq4repair_space>num_salary_credits,<seq2seq4repair_space>salary_credits_value,<seq2seq4repair_space>employer_from_application,<seq2seq4repair_space>primary_employer_from_credits,<seq2seq4repair_space>secondary_employer,<seq2seq4repair_space>median_sale_price,<seq2seq4repair_space>average_tom,<seq2seq4repair_space>median_rent,<seq2seq4repair_space>annual_growth_percent,<seq2seq4repair_space>three_year_growth_percent<seq2seq4repair_space>from<seq2seq4repair_space>customers<seq2seq4repair_space>cu<seq2seq4repair_space>join<seq2seq4repair_space>rpdata<seq2seq4repair_space>rp<seq2seq4repair_space>on<seq2seq4repair_space>rp.suburb<seq2seq4repair_space>=<seq2seq4repair_space>cu.suburb<seq2seq4repair_space>where<seq2seq4repair_space>crn<seq2seq4repair_space>=<seq2seq4repair_space>'" + crn ) + "'" ) ) ; JSONObject obj = new JSONObject ( ) ; ResultSetMetaData metadata = rs . getMetaData ( ) ; int k = metadata . getColumnCount ( ) ; String currentSection = "" ; boolean first = true ; rs . next ( ) ; for ( int i = 1 ; i <= k ; i ++ ) { String columnName = metadata . getColumnName ( i ) ; String [ ] labels = displayNames . get ( columnName ) ; String displayName = columnName ; if ( labels == null ) { currentSection = "" ; } else { if ( ! ( currentSection . equals ( labels [ 0 ] ) ) ) { if ( ! first ) json . put ( currentSection , obj ) ; first = false ; obj = new JSONObject ( ) ; currentSection = labels [ 0 ] ; } displayName = labels [ 1 ] ; } if ( ( metadata . getColumnType ( i ) ) == ( Types . INTEGER ) ) { obj . put ( displayName , rs . getInt ( columnName ) ) ; } else if ( ( metadata . getColumnType ( i ) ) == ( Types . BOOLEAN ) ) { obj . put ( displayName , rs . getBoolean ( columnName ) ) ; } else { obj . put ( displayName , rs . getString ( columnName ) ) ; } } <START_BUG> json . put ( obj ) ; <END_BUG> } catch ( Exception e ) { e . printStackTrace ( ) ; System . out . println ( ( "There<seq2seq4repair_space>was<seq2seq4repair_space>an<seq2seq4repair_space>error:<seq2seq4repair_space>" + ( e . getMessage ( ) ) ) ) ; } finally { if ( connection != null ) try { connection . close ( ) ; } catch ( SQLException e ) { } } return json . toString ( ) ; } private Connection getConnection ( ) throws URISyntaxException , SQLException { } No newline ; at end ; of file ; }

Fix:
json . put ( currentSection , obj ) ;