Program: 40221
Project: 40221
Buggy source:
/** 
 * Update an object
 */
@Override public void update(final Serializable id,final Object[] fields,final int[] dirtyFields,final boolean hasDirtyCollection,final Object[] oldFields,final Object oldVersion,final Object object,final Object rowId,final SessionImplementor session) throws HibernateException {
  final boolean[] tableUpdateNeeded=getTableUpdateNeeded(dirtyFields,hasDirtyCollection);
  final int span=getTableSpan();
  final boolean[] propsToUpdate;
  EntityEntry entry=session.getPersistenceContext().getEntry(object);
  if (entry == null && !isMutable()) {
    throw new IllegalStateException("String_Node_Str");
  }
  if ((dirtyFields != null)) {
    propsToUpdate=getPropertiesToUpdate(dirtyFields,hasDirtyCollection);
  }
 else   if (!isModifiableEntity(entry)) {
    propsToUpdate=getPropertiesToUpdate((dirtyFields == null ? ArrayHelper.EMPTY_INT_ARRAY : dirtyFields),hasDirtyCollection);
  }
 else {
    propsToUpdate=getPropertyUpdateability(object);
  }
  final SessionFactoryImplementor factory=getFactory();
  if (log.isTraceEnabled()) {
    log.trace("String_Node_Str" + MessageHelper.infoString(this,id,factory));
    if (isVersioned()) {
      log.trace("String_Node_Str" + oldVersion + "String_Node_Str"+ fields[getVersionProperty()]);
    }
  }
  for (int j=0; j < span; j++) {
    if (tableUpdateNeeded[j]) {
      final EntityKey key=EntityKeyBuilder.fromPersister(this,id,session);
      Tuple resultset=gridDialect.getTuple(key,this.getTupleContext());
      final boolean useVersion=j == 0 && isVersioned();
      resultset=createNewResultSetIfNull(key,resultset,id,session);
      final EntityMetamodel entityMetamodel=getEntityMetamodel();
      if (useVersion && entityMetamodel.getOptimisticLockStyle() == OptimisticLockStyle.VERSION) {
        if (checkVersion(propsToUpdate)) {
          checkVersionAndRaiseSOSE(id,oldVersion,session,resultset);
        }
      }
 else       if (isAllOrDirtyOptLocking() && oldFields != null) {
        boolean[] versionability=getPropertyVersionability();
        boolean[] includeOldField=entityMetamodel.getOptimisticLockStyle() == OptimisticLockStyle.ALL ? getPropertyUpdateability() : propsToUpdate;
        GridType[] types=gridPropertyTypes;
        for (int i=0; i < entityMetamodel.getPropertySpan(); i++) {
          boolean include=includeOldField[i] && isPropertyOfTable(i,j) && versionability[i];
          if (include) {
            final GridType type=types[i];
            boolean[] settable=type.toColumnNullness(oldFields[i],factory);
            final Object snapshotValue=type.nullSafeGet(resultset,getPropertyColumnNames(i),session,object);
            if (!type.isEqual(oldFields,snapshotValue,factory)) {
              raiseStaleObjectStateException(id);
            }
          }
        }
      }
      removeFromInverseAssociations(resultset,j,id,session);
      dehydrate(resultset,fields,propsToUpdate,j,id,session);
      if (isVersioned() && optimisticLockingAwareGridDialect != null) {
        Tuple oldVersionTuple=new Tuple();
        oldVersionTuple.put(getVersionColumnName(),oldVersion);
        boolean success=optimisticLockingAwareGridDialect.updateTuple(key,oldVersionTuple,resultset,getTupleContext());
        if (!success) {
          raiseStaleObjectStateException(id);
        }
      }
 else {
        gridDialect.insertOrUpdateTuple(key,resultset,getTupleContext());
      }
      addToInverseAssociations(resultset,j,id,session);
    }
  }
}

Fixed version (ground truth):
/** 
 * Update an object
 */
@Override public void update(final Serializable id,final Object[] fields,final int[] dirtyFields,final boolean hasDirtyCollection,final Object[] oldFields,final Object oldVersion,final Object object,final Object rowId,final SessionImplementor session) throws HibernateException {
  final boolean[] tableUpdateNeeded=getTableUpdateNeeded(dirtyFields,hasDirtyCollection);
  final int span=getTableSpan();
  final boolean[] propsToUpdate;
  EntityEntry entry=session.getPersistenceContext().getEntry(object);
  if (entry == null && !isMutable()) {
    throw new IllegalStateException("String_Node_Str");
  }
  if ((dirtyFields != null)) {
    propsToUpdate=getPropertiesToUpdate(dirtyFields,hasDirtyCollection);
  }
 else   if (!isModifiableEntity(entry)) {
    propsToUpdate=getPropertiesToUpdate((dirtyFields == null ? ArrayHelper.EMPTY_INT_ARRAY : dirtyFields),hasDirtyCollection);
  }
 else {
    propsToUpdate=getPropertyUpdateability(object);
  }
  final SessionFactoryImplementor factory=getFactory();
  if (log.isTraceEnabled()) {
    log.trace("String_Node_Str" + MessageHelper.infoString(this,id,factory));
    if (isVersioned()) {
      log.trace("String_Node_Str" + oldVersion + "String_Node_Str"+ fields[getVersionProperty()]);
    }
  }
  for (int j=0; j < span; j++) {
    if (tableUpdateNeeded[j]) {
      final EntityKey key=EntityKeyBuilder.fromPersister(this,id,session);
      Tuple resultset=gridDialect.getTuple(key,this.getTupleContext());
      final boolean useVersion=j == 0 && isVersioned();
      resultset=createNewResultSetIfNull(key,resultset,id,session);
      final EntityMetamodel entityMetamodel=getEntityMetamodel();
      if (useVersion && entityMetamodel.getOptimisticLockStyle() == OptimisticLockStyle.VERSION) {
        if (checkVersion(propsToUpdate)) {
          checkVersionAndRaiseSOSE(id,oldVersion,session,resultset);
        }
      }
 else       if (isAllOrDirtyOptLocking() && oldFields != null) {
        boolean[] versionability=getPropertyVersionability();
        boolean[] includeOldField=entityMetamodel.getOptimisticLockStyle() == OptimisticLockStyle.ALL ? getPropertyUpdateability() : propsToUpdate;
        GridType[] types=gridPropertyTypes;
        for (int i=0; i < entityMetamodel.getPropertySpan(); i++) {
          boolean include=includeOldField[i] && isPropertyOfTable(i,j) && versionability[i];
          if (include) {
            final GridType type=types[i];
            boolean[] settable=type.toColumnNullness(oldFields[i],factory);
            final Object snapshotValue=type.nullSafeGet(resultset,getPropertyColumnNames(i),session,object);
            if (!type.isEqual(oldFields[i],snapshotValue,factory)) {
              raiseStaleObjectStateException(id);
            }
          }
        }
      }
      removeFromInverseAssociations(resultset,j,id,session);
      dehydrate(resultset,fields,propsToUpdate,j,id,session);
      if (isVersioned() && optimisticLockingAwareGridDialect != null) {
        Tuple oldVersionTuple=new Tuple();
        oldVersionTuple.put(getVersionColumnName(),oldVersion);
        boolean success=optimisticLockingAwareGridDialect.updateTuple(key,oldVersionTuple,resultset,getTupleContext());
        if (!success) {
          raiseStaleObjectStateException(id);
        }
      }
 else {
        gridDialect.insertOrUpdateTuple(key,resultset,getTupleContext());
      }
      addToInverseAssociations(resultset,j,id,session);
    }
  }
}