Program: 66783
Project: 66783
Buggy source:
public void testLockWithJoinedInheritanceStrategy(){
  ServerSession session=JUnitTestCase.getServerSession();
  Assert.assertFalse("String_Node_Str",session.getPlatform().isSybase());
  if (!isOnServer() && isSelectForUpateSupported()) {
    Employee emp=null;
    LargeProject largeProject=null;
    EntityManager em=createEntityManager();
    try {
      beginTransaction(em);
      emp=new Employee();
      largeProject=new LargeProject();
      largeProject.setName("String_Node_Str");
      largeProject.setBudget(50000);
      emp.addProject(largeProject);
      em.persist(emp);
      commitTransaction(em);
    }
 catch (    RuntimeException ex) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }
      closeEntityManager(em);
      throw ex;
    }
    try {
      beginTransaction(em);
      emp=em.find(Employee.class,emp.getId());
      Project lp1=emp.getProjects().iterator().next();
      em.lock(lp1,LockModeType.PESSIMISTIC_WRITE);
      lp1.setName("String_Node_Str");
      EntityManager em2=createEntityManager();
      try {
        beginTransaction(em2);
        LargeProject lp2=em2.find(LargeProject.class,lp1.getId());
        HashMap properties=new HashMap();
        properties.put(QueryHints.PESSIMISTIC_LOCK_TIMEOUT,0);
        em2.lock(lp2,LockModeType.PESSIMISTIC_WRITE,properties);
      }
 catch (      PersistenceException ex) {
        if (!(ex instanceof javax.persistence.PessimisticLockException)) {
          throw ex;
        }
      }
 finally {
        rollbackTransaction(em2);
        closeEntityManager(em2);
      }
      commitTransaction(em);
    }
 catch (    RuntimeException ex) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }
      throw ex;
    }
 finally {
      closeEntityManager(em);
    }
  }
}

Fixed version (ground truth):
public void testLockWithJoinedInheritanceStrategy(){
  ServerSession session=JUnitTestCase.getServerSession();
  if (!isOnServer() && isSelectForUpateSupported()) {
    Employee emp=null;
    LargeProject largeProject=null;
    EntityManager em=createEntityManager();
    try {
      beginTransaction(em);
      emp=new Employee();
      largeProject=new LargeProject();
      largeProject.setName("String_Node_Str");
      largeProject.setBudget(50000);
      emp.addProject(largeProject);
      em.persist(emp);
      commitTransaction(em);
    }
 catch (    RuntimeException ex) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }
      closeEntityManager(em);
      throw ex;
    }
    try {
      beginTransaction(em);
      emp=em.find(Employee.class,emp.getId());
      Project lp1=emp.getProjects().iterator().next();
      em.lock(lp1,LockModeType.PESSIMISTIC_WRITE);
      lp1.setName("String_Node_Str");
      EntityManager em2=createEntityManager();
      try {
        beginTransaction(em2);
        LargeProject lp2=em2.find(LargeProject.class,lp1.getId());
        HashMap properties=new HashMap();
        properties.put(QueryHints.PESSIMISTIC_LOCK_TIMEOUT,0);
        em2.lock(lp2,LockModeType.PESSIMISTIC_WRITE,properties);
      }
 catch (      PersistenceException ex) {
        if (!(ex instanceof javax.persistence.PessimisticLockException)) {
          throw ex;
        }
      }
 finally {
        rollbackTransaction(em2);
        closeEntityManager(em2);
      }
      commitTransaction(em);
    }
 catch (    RuntimeException ex) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }
      throw ex;
    }
 finally {
      closeEntityManager(em);
    }
  }
}