Buggy code:
public class DataSourceWorkflowInstanceRepository extends AbstractPaginatibleInstanceRepository { private DataSource dataSource = null ; private static final Logger LOG = Logger . getLogger ( DataSourceWorkflowInstanceRepository . class . getName ( ) ) ; private boolean quoteFields = false ; public DataSourceWorkflowInstanceRepository ( DataSource ds , boolean quoteFields , int pageSize ) { } public synchronized void addWorkflowInstance ( WorkflowInstance wInst ) throws InstanceRepositoryException { <START_BUG> Connoection conn = null ; <END_BUG> Statement statement = null ; ResultSet rs = null ; try { conn = dataSource . getConnection ( ) ; conn . setAutoCommit ( false ) ; statement = conn . createStatement ( ) ; String startWorkflowSql ; String taskIdField ; String workflowIdField ; if ( quoteFields ) { taskIdField = ( "'" + ( wInst . getWorkflow ( ) . getTasks ( ) . get ( 0 ) . getTaskId ( ) ) ) + "'" ; workflowIdField = ( "'" + ( wInst . getWorkflow ( ) . getId ( ) ) ) + "'" ; } else { taskIdField = wInst . getWorkflow ( ) . getTasks ( ) . get ( 0 ) . getTaskId ( ) ; workflowIdField = wInst . getWorkflow ( ) . getId ( ) ; } startWorkflowSql = ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( "INSERT<seq2seq4repair_space>INTO<seq2seq4repair_space>workflow_instances<seq2seq4repair_space>" + ( ( ( "(workflow_instance_status,<seq2seq4repair_space>workflow_id,<seq2seq4repair_space>current_task_id," + "start_date_time,<seq2seq4repair_space>end_date_time,<seq2seq4repair_space>current_task_start_date_time," ) + "current_task_end_date_time,<seq2seq4repair_space>priority,<seq2seq4repair_space>times_blocked)<seq2seq4repair_space>" ) + "VALUES<seq2seq4repair_space>('" ) ) + ( wInst . getStatus ( ) ) ) + "',<seq2seq4repair_space>" ) + workflowIdField ) + "," ) + taskIdField ) + ",<seq2seq4repair_space>'" ) + ( wInst . getStartDateTimeIsoStr ( ) ) ) + "','" ) + ( wInst . getEndDateTimeIsoStr ( ) ) ) + "','" ) + ( wInst . getCurrentTaskStartDateTimeIsoStr ( ) ) ) + "','" ) + ( wInst . getCurrentTaskEndDateTimeIsoStr ( ) ) ) + "',<seq2seq4repair_space>" ) + ( wInst . getPriority ( ) . getValue ( ) ) ) + ",<seq2seq4repair_space>" ) + ( wInst . getTimesBlocked ( ) ) ) + ")" ; DataSourceWorkflowInstanceRepository . LOG . log ( Level . FINE , ( "sql:<seq2seq4repair_space>Executing:<seq2seq4repair_space>" + startWorkflowSql ) ) ; statement . execute ( startWorkflowSql ) ; String workflowInstId = "" ; synchronized ( workflowInstId ) { String getWorkflowInstIdSql = "SELECT<seq2seq4repair_space>MAX(workflow_instance_id)<seq2seq4repair_space>" + "AS<seq2seq4repair_space>max_id<seq2seq4repair_space>FROM<seq2seq4repair_space>workflow_instances" ; rs = statement . executeQuery ( getWorkflowInstIdSql ) ; while ( rs . next ( ) ) { workflowInstId = String . valueOf ( rs . getInt ( "max_id" ) ) ; } } conn . commit ( ) ; wInst . setId ( workflowInstId ) ; addWorkflowInstanceMetadata ( wInst ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; DataSourceWorkflowInstanceRepository . LOG . log ( Level . WARNING , ( "Exception<seq2seq4repair_space>starting<seq2seq4repair_space>workflow.<seq2seq4repair_space>Message:<seq2seq4repair_space>" + ( e . getMessage ( ) ) ) ) ; try { if ( conn != null ) { conn . rollback ( ) ; } } catch ( SQLException e2 ) { DataSourceWorkflowInstanceRepository . LOG . log ( Level . SEVERE , ( "Unable<seq2seq4repair_space>to<seq2seq4repair_space>rollback<seq2seq4repair_space>startWorkflow<seq2seq4repair_space>transaction.<seq2seq4repair_space>Message:<seq2seq4repair_space>" + ( e2 . getMessage ( ) ) ) ) ; } throw new InstanceRepositoryException ( e . getMessage ( ) ) ; } finally { if ( rs != null ) { try { rs . close ( ) ; } catch ( SQLException ignore ) { } } if ( statement != null ) { try { statement . close ( ) ; } catch ( SQLException ignore ) { } } if ( conn != null ) { try { conn . close ( ) ; } catch ( SQLException ignore ) { } } } } public synchronized void updateWorkflowInstance ( WorkflowInstance wInst ) throws InstanceRepositoryException { } public synchronized void removeWorkflowInstance ( WorkflowInstance wInst ) throws InstanceRepositoryException { } public WorkflowInstance getWorkflowInstanceById ( String workflowInstId ) throws InstanceRepositoryException { } public List getWorkflowInstances ( ) throws InstanceRepositoryException { } public List getWorkflowInstancesByStatus ( String status ) throws InstanceRepositoryException { } public int getNumWorkflowInstances ( ) throws InstanceRepositoryException { } public int getNumWorkflowInstancesByStatus ( String status ) throws InstanceRepositoryException { } protected List paginateWorkflows ( int pageNum , String status ) throws InstanceRepositoryException { } private Metadata getWorkflowInstanceMetadata ( String workflowInstId ) throws InstanceRepositoryException { } private synchronized void addWorkflowInstanceMetadata ( WorkflowInstance inst ) throws InstanceRepositoryException { } private synchronized void addMetadataValue ( String wInstId , String key , String val ) throws InstanceRepositoryException { } private synchronized void removeWorkflowInstanceMetadata ( String workflowInstId ) throws InstanceRepositoryException { } }

Fix:
Connection conn = null ;