Program: 66787
Project: 66787
Buggy source:
public void testPESSIMISTIC_READLock(){
  ServerSession session=JUnitTestCase.getServerSession();
  Assert.assertFalse("String_Node_Str",session.getPlatform().isSybase());
  if (!isOnServer() && isSelectForUpateNoWaitSupported()) {
    EntityManager em=createEntityManager();
    Department dept=null;
    try {
      beginTransaction(em);
      dept=new Department();
      dept.setName("String_Node_Str");
      em.persist(dept);
      commitTransaction(em);
    }
 catch (    RuntimeException ex) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }
      closeEntityManager(em);
      throw ex;
    }
    Exception pessimisticLockException=null;
    try {
      beginTransaction(em);
      dept=em.find(Department.class,dept.getId());
      em.lock(dept,LockModeType.PESSIMISTIC_READ);
      dept.setName("String_Node_Str");
      EntityManager em2=createEntityManager();
      try {
        beginTransaction(em2);
        Department dept2=em2.find(Department.class,dept.getId());
        HashMap properties=new HashMap();
        properties.put(QueryHints.PESSIMISTIC_LOCK_TIMEOUT,0);
        em2.lock(dept2,LockModeType.PESSIMISTIC_READ,properties);
      }
 catch (      PersistenceException ex) {
        if (ex instanceof javax.persistence.PessimisticLockException) {
          pessimisticLockException=ex;
        }
 else {
          throw ex;
        }
      }
 finally {
        rollbackTransaction(em2);
        closeEntityManager(em2);
      }
      commitTransaction(em);
    }
 catch (    RuntimeException ex) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }
      throw ex;
    }
 finally {
      closeEntityManager(em);
    }
    assertFalse("String_Node_Str",pessimisticLockException == null);
  }
}

Fixed version (ground truth):
public void testPESSIMISTIC_READLock(){
  ServerSession session=JUnitTestCase.getServerSession();
  if (!isOnServer() && isSelectForUpateNoWaitSupported()) {
    EntityManager em=createEntityManager();
    Department dept=null;
    try {
      beginTransaction(em);
      dept=new Department();
      dept.setName("String_Node_Str");
      em.persist(dept);
      commitTransaction(em);
    }
 catch (    RuntimeException ex) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }
      closeEntityManager(em);
      throw ex;
    }
    Exception pessimisticLockException=null;
    try {
      beginTransaction(em);
      dept=em.find(Department.class,dept.getId());
      em.lock(dept,LockModeType.PESSIMISTIC_READ);
      dept.setName("String_Node_Str");
      EntityManager em2=createEntityManager();
      try {
        beginTransaction(em2);
        Department dept2=em2.find(Department.class,dept.getId());
        HashMap properties=new HashMap();
        properties.put(QueryHints.PESSIMISTIC_LOCK_TIMEOUT,0);
        em2.lock(dept2,LockModeType.PESSIMISTIC_READ,properties);
      }
 catch (      PersistenceException ex) {
        if (ex instanceof javax.persistence.PessimisticLockException) {
          pessimisticLockException=ex;
        }
 else {
          throw ex;
        }
      }
 finally {
        rollbackTransaction(em2);
        closeEntityManager(em2);
      }
      commitTransaction(em);
    }
 catch (    RuntimeException ex) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }
      throw ex;
    }
 finally {
      closeEntityManager(em);
    }
    assertFalse("String_Node_Str",pessimisticLockException == null);
  }
}