Program: 67541
Project: 67541
Buggy source:
/** 
 * INTERNAL: Prepare the receiver for execution in a session.
 */
protected void prePrepare() throws QueryException {
  buildSelectionCriteria(session);
  checkDescriptor(session);
  if (getQueryMechanism().isExpressionQueryMechanism() && getDescriptor().getObjectBuilder().hasJoinedAttributes()) {
    getJoinedAttributeManager().processJoinedMappings();
    if (getJoinedAttributeManager().hasOrderByExpressions()) {
      Iterator<Expression> it=getJoinedAttributeManager().getOrderByExpressions().iterator();
      while (it.hasNext()) {
        addOrdering(it.next());
      }
    }
  }
  if (lockModeType != null) {
    if (lockModeType.equals(NONE)) {
      setLockMode(ObjectBuildingQuery.NO_LOCK);
    }
 else     if (lockModeType.contains(PESSIMISTIC)) {
      Integer timeout=(waitTimeout == null) ? getSession().getPessimisticLockTimeoutDefault() : waitTimeout;
      if (timeout == null) {
        setLockMode(ObjectBuildingQuery.LOCK);
      }
 else {
        if (timeout.intValue() == 0) {
          setLockMode(ObjectBuildingQuery.LOCK_NOWAIT);
        }
 else {
          lockingClause=ForUpdateClause.newInstance(timeout);
        }
      }
    }
  }
  if (isDefaultLock()) {
    setWasDefaultLockMode(true);
    ForUpdateOfClause lockingClause=null;
    if (hasJoining()) {
      lockingClause=getJoinedAttributeManager().setupLockingClauseForJoinedExpressions(lockingClause,getSession());
    }
    if (descriptor.hasPessimisticLockingPolicy()) {
      lockingClause=new ForUpdateOfClause();
      lockingClause.setLockMode(descriptor.getCMPPolicy().getPessimisticLockingPolicy().getLockingMode());
      lockingClause.addLockedExpression(getExpressionBuilder());
    }
    if (lockingClause == null) {
      this.lockingClause=ForUpdateClause.newInstance(NO_LOCK);
    }
 else {
      this.lockingClause=lockingClause;
      dontUseDistinct();
    }
  }
 else   if ((getLockMode() == NO_LOCK) && (!descriptor.hasPessimisticLockingPolicy())) {
    setWasDefaultLockMode(true);
  }
  if (hasJoining() && hasPartialAttributeExpressions()) {
    session.log(SessionLog.WARNING,SessionLog.QUERY,"String_Node_Str",new Object[]{this,this.getName()});
  }
}

Fixed version (ground truth):
/** 
 * INTERNAL: Prepare the receiver for execution in a session.
 */
protected void prePrepare() throws QueryException {
  buildSelectionCriteria(session);
  checkDescriptor(session);
  if (getQueryMechanism().isExpressionQueryMechanism() && getDescriptor().getObjectBuilder().hasJoinedAttributes()) {
    getJoinedAttributeManager().processJoinedMappings();
    if (getJoinedAttributeManager().hasOrderByExpressions()) {
      Iterator<Expression> it=getJoinedAttributeManager().getOrderByExpressions().iterator();
      while (it.hasNext()) {
        addOrdering(it.next());
      }
    }
  }
  if (lockModeType != null) {
    if (lockModeType.equals(NONE)) {
      setLockMode(ObjectBuildingQuery.NO_LOCK);
    }
 else     if (lockModeType.contains(PESSIMISTIC_)) {
      Integer timeout=(waitTimeout == null) ? getSession().getPessimisticLockTimeoutDefault() : waitTimeout;
      if (timeout == null) {
        setLockMode(ObjectBuildingQuery.LOCK);
      }
 else {
        if (timeout.intValue() == 0) {
          setLockMode(ObjectBuildingQuery.LOCK_NOWAIT);
        }
 else {
          lockingClause=ForUpdateClause.newInstance(timeout);
        }
      }
    }
  }
  if (isDefaultLock()) {
    setWasDefaultLockMode(true);
    ForUpdateOfClause lockingClause=null;
    if (hasJoining()) {
      lockingClause=getJoinedAttributeManager().setupLockingClauseForJoinedExpressions(lockingClause,getSession());
    }
    if (descriptor.hasPessimisticLockingPolicy()) {
      lockingClause=new ForUpdateOfClause();
      lockingClause.setLockMode(descriptor.getCMPPolicy().getPessimisticLockingPolicy().getLockingMode());
      lockingClause.addLockedExpression(getExpressionBuilder());
    }
    if (lockingClause == null) {
      this.lockingClause=ForUpdateClause.newInstance(NO_LOCK);
    }
 else {
      this.lockingClause=lockingClause;
      dontUseDistinct();
    }
  }
 else   if ((getLockMode() == NO_LOCK) && (!descriptor.hasPessimisticLockingPolicy())) {
    setWasDefaultLockMode(true);
  }
  if (hasJoining() && hasPartialAttributeExpressions()) {
    session.log(SessionLog.WARNING,SessionLog.QUERY,"String_Node_Str",new Object[]{this,this.getName()});
  }
}