Buggy code:
public static final String PRODUCER_LOCAL_ID_PREFIX = "PRODUCER_LOCAL_ID_" ; public static final String PARAMETER_NAME_PREFIX = "PARAMETER_" ; public static final String FILE_INFO_PREFIX = "FILE_" ; public static final String PARAMETER_TYPE = "INTEGER" ; public static final String PARAMETER_VALUE = "10" ; public static final int MAX_DURATION = 20 ; public static final int MAX_VARIABLE_DURATION = 15 ; public static final int MAX_STATE_DURATION = 10000 ; List < EventProducer > producers = new ArrayList < EventProducer > ( ) ; List < EventProducer > leaves = new ArrayList < EventProducer > ( ) ; List < EventType > typesList = new ArrayList < EventType > ( ) ; long numberOfGeneratedEvents ; long maxTimeStamp ; TraceDBObject traceDB ; public int numberOfCategories ; public int getEventsPerCategory ( ) { } public long getNumberOfEvents ( int category ) { } public long getMaxTimestamp ( ) { } private long currentTimestamp = MIN_TIMESTAMP ; private boolean forceIndex = false ; public void generateTrace ( IProgressMonitor monitor ) throws SoCTraceException { traceDB = new TraceDBObject ( dbName , DBMode . DB_CREATE ) ; IdManager eIdManager = new IdManager ( ) ; IdManager etIdManager = new IdManager ( ) ; IdManager epIdManager = new IdManager ( ) ; IdManager eptIdManager = new IdManager ( ) ; IdManager tpIdManager = new IdManager ( ) ; IdManager tptIdManager = new IdManager ( ) ; IdManager producerIdManager = new IdManager ( ) ; Random rand = new Random ( ) ; monitor . subTask ( "Generating<seq2seq4repair_space>event<seq2seq4repair_space>types" ) ; int i = 0 ; for ( i = 0 ; i < ( numberOfEventType ) ; i ++ ) { int category = categories . get ( ( i % ( categories . size ( ) ) ) ) ; EventType aType = createTypes ( traceDB , category , etIdManager , eptIdManager ) ; typesList . add ( aType ) ; } monitor . subTask ( "Generating<seq2seq4repair_space>event<seq2seq4repair_space>producer" ) ; EventProducer root = createEventProd ( ( - 1 ) , producerIdManager , traceDB ) ; for ( i = 0 ; i < ( ( numberOfProducers ) - ( numberOfLeaves ) ) ; i ++ ) { createEventProd ( root . getId ( ) , producerIdManager , traceDB ) ; } int potentialParentsSize = producers . size ( ) ; for ( i = 0 ; i < ( numberOfLeaves ) ; i ++ ) { int parentId = producers . get ( ( ( rand . nextInt ( ( potentialParentsSize - 1 ) ) ) + 1 ) ) . getId ( ) ; leaves . add ( createEventProd ( parentId , producerIdManager , traceDB ) ) ; } traceDB . commit ( ) ; monitor . subTask ( "Generating<seq2seq4repair_space>events" ) ; createEvent ( eIdManager , epIdManager , monitor ) ; if ( monitor . isCanceled ( ) ) { traceDB . dropDatabase ( ) ; return ; } IdManager fileIdManager = new IdManager ( ) ; for ( i = 0 ; i < ( NUMBER_OF_FILES ) ; i ++ ) { File file = new File ( fileIdManager . getNextId ( ) ) ; file . setPath ( ( ( TraceGenerator . FILE_INFO_PREFIX ) + ( file . getId ( ) ) ) ) ; file . setDescription ( ( ( TraceGenerator . FILE_INFO_PREFIX ) + ( file . getId ( ) ) ) ) ; traceDB . save ( file ) ; } if ( forceIndex ) { monitor . subTask ( "Indexing<seq2seq4repair_space>timestamp" ) ; traceDB . createTimestampIndex ( ) ; monitor . subTask ( "Indexing<seq2seq4repair_space>event<seq2seq4repair_space>id<seq2seq4repair_space>in<seq2seq4repair_space>EVENT_PARAM" ) ; traceDB . createEventParamIndex ( ) ; } traceDB . close ( ) ; monitor . subTask ( "Filling<seq2seq4repair_space>trace<seq2seq4repair_space>metadata" ) ; <START_BUG> SystemDBObject sysDB = SystemDBObject . openNewIstance ( ) ; <END_BUG> TraceType tt = buildTraceType ( sysDB ) ; tptIdManager . setNextId ( ( ( sysDB . getMaxId ( TRACE_PARAM_TYPE . toString ( ) , "ID" ) ) + 1 ) ) ; for ( i = 0 ; i < ( NUMBER_OF_TRACE_PARAMETERS ) ; i ++ ) { TraceParamType tpt = new TraceParamType ( tptIdManager . getNextId ( ) ) ; tpt . setName ( ( ( TraceGenerator . PARAMETER_NAME_PREFIX ) + ( tpt . getId ( ) ) ) ) ; tpt . setType ( TraceGenerator . PARAMETER_TYPE ) ; tpt . setTraceType ( tt ) ; sysDB . save ( tpt ) ; } Trace t = new Trace ( sysDB . getNewId ( TRACE . toString ( ) , "ID" ) ) ; t . setAlias ( ( ( ( TraceGenerator . TRACE_NAME ) + "_" ) + ( t . getId ( ) ) ) ) ; t . setBoard ( TraceGenerator . METADATA ) ; t . setDbName ( dbName ) ; t . setDescription ( TraceGenerator . METADATA ) ; t . setNumberOfCpus ( 1 ) ; t . setNumberOfEvents ( ( ( int ) ( numberOfGeneratedEvents ) ) ) ; t . setOperatingSystem ( TraceGenerator . METADATA ) ; t . setOutputDevice ( TraceGenerator . METADATA ) ; t . setProcessed ( false ) ; t . setMinTimestamp ( MIN_TIMESTAMP ) ; t . setMaxTimestamp ( maxTimeStamp ) ; t . setTimeUnit ( NANOSECONDS . getInt ( ) ) ; t . setTracedApplication ( TraceGenerator . METADATA ) ; t . setTracingDate ( new Timestamp ( new Date ( ) . getTime ( ) ) ) ; t . setType ( tt ) ; tpIdManager . setNextId ( ( ( sysDB . getMaxId ( TRACE_PARAM . toString ( ) , "ID" ) ) + 1 ) ) ; for ( TraceParamType tpt : tt . getTraceParamTypes ( ) ) { TraceParam tp = new TraceParam ( tpIdManager . getNextId ( ) ) ; tp . setTraceParamType ( tpt ) ; tp . setTrace ( t ) ; tp . setValue ( TraceGenerator . PARAMETER_VALUE ) ; sysDB . save ( tp ) ; } sysDB . save ( t ) ; sysDB . close ( ) ;

Fix:
SystemDBObject sysDB = SystemDBObject . openNewInstance ( ) ;