Program: 66786
Project: 66786
Buggy source:
public void testRefreshPESSIMISTIC_WRITELock(){
  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_WRITE);
      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.refresh(dept2,LockModeType.PESSIMISTIC_WRITE,properties);
      }
 catch (      PersistenceException ex) {
        if (ex instanceof javax.persistence.PessimisticLockException) {
          pessimisticLockException=ex;
        }
 else {
          throw ex;
        }
      }
 finally {
        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 testRefreshPESSIMISTIC_WRITELock(){
  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_WRITE);
      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.refresh(dept2,LockModeType.PESSIMISTIC_WRITE,properties);
      }
 catch (      PersistenceException ex) {
        if (ex instanceof javax.persistence.PessimisticLockException) {
          pessimisticLockException=ex;
        }
 else {
          throw ex;
        }
      }
 finally {
        closeEntityManager(em2);
      }
      commitTransaction(em);
    }
 catch (    RuntimeException ex) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }
      throw ex;
    }
 finally {
      closeEntityManager(em);
    }
    assertFalse("String_Node_Str",pessimisticLockException == null);
  }
}