Program: 64005
Project: 64005
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<String,Object> 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.name().equals(ObjectLevelReadQuery.NONE)) {
      return;
    }
    if (lockMode.name().equals(ObjectLevelReadQuery.PESSIMISTIC_READ) || lockMode.name().equals(ObjectLevelReadQuery.PESSIMISTIC_WRITE) || lockMode.name().equals(ObjectLevelReadQuery.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;
  }
}

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<String,Object> 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.name().equals(ObjectLevelReadQuery.NONE)) {
      return;
    }
    if (lockMode.name().equals(ObjectLevelReadQuery.PESSIMISTIC_READ) || lockMode.name().equals(ObjectLevelReadQuery.PESSIMISTIC_WRITE) || lockMode.name().equals(ObjectLevelReadQuery.PESSIMISTIC_FORCE_INCREMENT)) {
      if (((UnitOfWorkImpl)uow).isPessimisticLocked(entity)) {
        return;
      }
      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;
  }
}