Buggy code:
class JqmEngine implements JqmEngineMBean { private static Logger jqmlogger = Logger . getLogger ( JqmEngine . class ) ; static String latestNodeStartedName = "" ; private Semaphore ended = new Semaphore ( 0 ) ; private boolean hasEnded = false ; private Node node = null ; private LibraryCache cache = new LibraryCache ( ) ; private ObjectName name ; private List < QueuePoller > pollers = new ArrayList < QueuePoller > ( ) ; private InternalPoller intPoller = null ; private JettyServer server = null ; private Calendar startTime = Calendar . getInstance ( ) ; private Thread killHook = null ; boolean loadJmxBeans = true ; void start ( String nodeName ) { } @ Override public void stop ( ) { } Node getNode ( ) { } synchronized void checkEngineEnd ( ) { } private void purgeDeadJobInstances ( EntityManager em , Node node ) { em . getTransaction ( ) . begin ( ) ; <START_BUG> for ( JobInstance ji : em . createQuery ( "SELECT<seq2seq4repair_space>ji<seq2seq4repair_space>FROM<seq2seq4repair_space>JobInstance<seq2seq4repair_space>ji<seq2seq4repair_space>WHERE<seq2seq4repair_space>ji.node<seq2seq4repair_space>=<seq2seq4repair_space>:node<seq2seq4repair_space>AND<seq2seq4repair_space>(ji.state<seq2seq4repair_space>=<seq2seq4repair_space>'SUBMITTED'<seq2seq4repair_space>OR<seq2seq4repair_space>ji.state<seq2seq4repair_space>=<seq2seq4repair_space>'RUNNING')" , JobInstance . class ) . setParameter ( "node" , node ) . getResultList ( ) ) { <END_BUG> History h = em . find ( History . class , ji . getId ( ) ) ; if ( h == null ) { h = Helpers . createHistory ( ji , em , CRASHED , Calendar . getInstance ( ) ) ; Message m = new Message ( ) ; m . setJi ( ji . getId ( ) ) ; m . setTextMessage ( "Job<seq2seq4repair_space>was<seq2seq4repair_space>supposed<seq2seq4repair_space>to<seq2seq4repair_space>be<seq2seq4repair_space>running<seq2seq4repair_space>at<seq2seq4repair_space>server<seq2seq4repair_space>startup<seq2seq4repair_space>-<seq2seq4repair_space>usually<seq2seq4repair_space>means<seq2seq4repair_space>it<seq2seq4repair_space>was<seq2seq4repair_space>killed<seq2seq4repair_space>along<seq2seq4repair_space>a<seq2seq4repair_space>server<seq2seq4repair_space>by<seq2seq4repair_space>an<seq2seq4repair_space>admin<seq2seq4repair_space>or<seq2seq4repair_space>a<seq2seq4repair_space>crash" ) ; em . persist ( m ) ; } em . createQuery ( "DELETE<seq2seq4repair_space>FROM<seq2seq4repair_space>JobInstance<seq2seq4repair_space>WHERE<seq2seq4repair_space>id<seq2seq4repair_space>=<seq2seq4repair_space>:i" ) . setParameter ( "i" , ji . getId ( ) ) . executeUpdate ( ) ; } em . getTransaction ( ) . commit ( ) ; } @ Override public long getCumulativeJobInstancesCount ( ) { } @ Override public float getJobsFinishedPerSecondLastMinute ( ) { } @ Override public long getCurrentlyRunningJobCount ( ) { } @ Override public boolean isAllPollersPolling ( ) { } @ Override public boolean isFull ( ) { } @ Override public long getUptime ( ) { } @ Override public String getVersion ( ) { } }

Fix:
for ( JobInstance ji : em . createQuery ( "SELECT<seq2seq4repair_space>ji<seq2seq4repair_space>FROM<seq2seq4repair_space>JobInstance<seq2seq4repair_space>ji<seq2seq4repair_space>WHERE<seq2seq4repair_space>ji.node<seq2seq4repair_space>=<seq2seq4repair_space>:node<seq2seq4repair_space>AND<seq2seq4repair_space>(ji.state<seq2seq4repair_space>=<seq2seq4repair_space>'ATTRIBUTED'<seq2seq4repair_space>OR<seq2seq4repair_space>ji.state<seq2seq4repair_space>=<seq2seq4repair_space>'RUNNING')" , JobInstance . class ) . setParameter ( "node" , node ) . getResultList ( ) ) {