Program: 67888
Project: 67888
Buggy source:
/** 
 * Set the lock mode for an entity object contained in the persistence context.
 * @param entity
 * @param lockMode
 * @throws PersistenceException if an unsupported lock call is made
 * @throws IllegalArgumentException if the instance is not an entity or is a detached entity
 * @throws javax.persistence.TransactionRequiredException if there is no transaction
 */
public void lock(Object entity,LockModeType lockMode,Map properties){
  try {
    verifyOpen();
    if (lockMode.name().contains(ObjectLevelReadQuery.PESSIMISTIC)) {
      ReadObjectQuery query=getReadObjectQuery(entity,properties);
      if (properties == null || !properties.containsKey(QueryHints.REFRESH)) {
        query.refreshIdentityMapResult();
      }
      if (properties == null || !properties.containsKey(QueryHints.REFRESH_CASCADE)) {
        query.cascadePrivateParts();
      }
      executeQuery(query,lockMode,getActivePersistenceContext(checkForTransaction(false)));
    }
 else {
      RepeatableWriteUnitOfWork context=getActivePersistenceContext(checkForTransaction(false));
      ClassDescriptor descriptor=context.getDescriptor(entity);
      OptimisticLockingPolicy lockingPolicy=descriptor.getOptimisticLockingPolicy();
      if ((lockingPolicy == null) || !(lockingPolicy instanceof VersionLockingPolicy)) {
        throw new PersistenceException(ExceptionLocalization.buildMessage("String_Node_Str",null));
      }
      context.forceUpdateToVersionField(entity,(lockMode == LockModeType.WRITE || lockMode.name().equals(ObjectLevelReadQuery.OPTIMISTIC_FORCE_INCREMENT)));
    }
  }
 catch (  LockTimeoutException e) {
    throw e;
  }
catch (  RuntimeException e) {
    setRollbackOnly();
    throw e;
  }
}

Fixed version (ground truth):
/** 
 * Set the lock mode for an entity object contained in the persistence context.
 * @param entity
 * @param lockMode
 * @throws PersistenceException if an unsupported lock call is made
 * @throws IllegalArgumentException if the instance is not an entity or is a detached entity
 * @throws javax.persistence.TransactionRequiredException if there is no transaction
 */
public void lock(Object entity,LockModeType lockMode,Map properties){
  try {
    verifyOpen();
    if (entity == null) {
      throw new IllegalArgumentException(ExceptionLocalization.buildMessage("String_Node_Str",new Object[]{entity}));
    }
    UnitOfWork uow=getActivePersistenceContext(checkForTransaction(true));
    if (!contains(entity,uow)) {
      throw new IllegalArgumentException(ExceptionLocalization.buildMessage("String_Node_Str",new Object[]{entity}));
    }
    if (lockMode == null || lockMode == LockModeType.NONE) {
      return;
    }
    if (lockMode == LockModeType.PESSIMISTIC || lockMode == LockModeType.PESSIMISTIC_FORCE_INCREMENT) {
      ReadObjectQuery query=getReadObjectQuery(entity,properties);
      if (properties == null || !properties.containsKey(QueryHints.REFRESH)) {
        query.refreshIdentityMapResult();
      }
      if (properties == null || !properties.containsKey(QueryHints.REFRESH_CASCADE)) {
        query.cascadePrivateParts();
      }
      executeQuery(query,lockMode,getActivePersistenceContext(checkForTransaction(false)));
    }
 else {
      RepeatableWriteUnitOfWork context=getActivePersistenceContext(checkForTransaction(false));
      ClassDescriptor descriptor=context.getDescriptor(entity);
      OptimisticLockingPolicy lockingPolicy=descriptor.getOptimisticLockingPolicy();
      if ((lockingPolicy == null) || !(lockingPolicy instanceof VersionLockingPolicy)) {
        throw new PersistenceException(ExceptionLocalization.buildMessage("String_Node_Str",null));
      }
      context.forceUpdateToVersionField(entity,(lockMode == LockModeType.WRITE || lockMode.name().equals(ObjectLevelReadQuery.OPTIMISTIC_FORCE_INCREMENT)));
    }
  }
 catch (  LockTimeoutException e) {
    throw e;
  }
catch (  RuntimeException e) {
    setRollbackOnly();
    throw e;
  }
}