Program: 5836
Project: 5836
Buggy source:
/** 
 * @private Internal implementation of entity reset
 */
@SuppressWarnings("String_Node_Str") public void resetEntity(MergeContext mergeContext,Object entity,Identifiable parent,Set<Object> cache){
  if (entity instanceof Lazyable && !((Lazyable)entity).isInitialized())   return;
  if (cache.contains(entity))   return;
  cache.add(entity);
  Map<String,Object> save=savedProperties.get(entity);
  EntityDescriptor desc=PersistenceManager.getEntityDescriptor(entity);
  Map<String,Object> pval=dataManager.getPropertyValues(entity,false,false);
  for (  String p : pval.keySet()) {
    if (p.equals(desc.getVersionPropertyName()))     continue;
    List<Object> removed=null;
    Object val=dataManager.getProperty(entity,p);
    if (val instanceof List<?> && !(val instanceof LazyableCollection && !((LazyableCollection)val).isInitialized())) {
      List<Object> list=(List<Object>)val;
      List<Change> savedArray=save != null ? (List<Change>)save.get(p) : null;
      if (savedArray != null) {
        for (int a=savedArray.size() - 1; a >= 0; a--) {
          if (a >= savedArray.size()) {
            log.debug("String_Node_Str",list);
            break;
          }
          Change ce=savedArray.get(a);
          if (ce.getKind() == ChangeKind.ADD) {
            if (removed == null)             removed=new ArrayList<Object>();
            for (int z=0; z < ce.getItems().length; z++) {
              if (ce.getLocation() < list.size())               removed.add(list.remove(ce.getLocation()));
 else               log.debug("String_Node_Str",list,ce.getLocation());
            }
          }
 else           if (ce.getKind() == ChangeKind.REMOVE) {
            for (int z=0; z < ce.getItems().length; z++) {
              if (ce.getLocation() + z <= list.size())               list.add(ce.getLocation() + z,ce.getItems()[z]);
 else               log.debug("String_Node_Str",list,ce.getLocation() + z);
            }
          }
 else           if (ce.getKind() == ChangeKind.REPLACE) {
            if (removed == null)             removed=new ArrayList<Object>();
            for (int z=0; z < ce.getItems().length; z++) {
              if (ce.getLocation() + z < list.size())               removed.add(list.set(ce.getLocation() + z,((Object[])ce.getItems()[z])[0]));
 else               log.debug("String_Node_Str",list,ce.getLocation() + z);
            }
          }
        }
        markNotDirty(val,parent);
      }
      for (      Object o : list) {
        if (o instanceof Identifiable)         resetEntity(mergeContext,o,(Identifiable)o,cache);
      }
      if (removed != null) {
        for (        Object o : removed) {
          if (o instanceof Identifiable)           resetEntity(mergeContext,o,(Identifiable)o,cache);
        }
      }
    }
 else     if (val instanceof Map<?,?> && !(val instanceof LazyableCollection && !((LazyableCollection)val).isInitialized())) {
      Map<Object,Object> map=(Map<Object,Object>)val;
      List<Change> savedArray=save != null ? (List<Change>)save.get(p) : null;
      if (savedArray != null) {
        for (int a=savedArray.size() - 1; a >= 0; a--) {
          Change ce=savedArray.get(a);
          if (ce.getKind() == ChangeKind.ADD) {
            if (removed == null)             removed=new ArrayList<Object>();
            for (int z=0; z < ce.getItems().length; z++) {
              removed.add(map.remove(((Object[])ce.getItems()[z])[0]));
              removed.add(((Object[])ce.getItems()[z])[0]);
            }
          }
 else           if (ce.getKind() == ChangeKind.REMOVE) {
            for (int z=0; z < ce.getItems().length; z++)             map.put(((Object[])ce.getItems()[z])[0],((Object[])ce.getItems()[z])[1]);
          }
 else           if (ce.getKind() == ChangeKind.REPLACE) {
            if (removed == null)             removed=new ArrayList<Object>();
            for (int z=0; z < ce.getItems().length; z++) {
              removed.add(map.put(((Object[])ce.getItems()[z])[0],((Object[])ce.getItems()[z])[1]));
            }
          }
        }
        markNotDirty(val,parent);
      }
      for (      Entry<Object,Object> me : map.entrySet()) {
        if (me.getKey() instanceof Identifiable)         resetEntity(mergeContext,me.getKey(),(Identifiable)me.getKey(),cache);
        if (me.getValue() instanceof Identifiable)         resetEntity(mergeContext,me.getValue(),(Identifiable)me.getValue(),cache);
      }
      if (removed != null) {
        for (        Object o : removed) {
          if (o instanceof Identifiable)           resetEntity(mergeContext,o,(Identifiable)o,cache);
        }
      }
    }
 else     if (save != null && (ObjectUtil.isSimple(val) || ObjectUtil.isSimple(save.get(p)))) {
      if (save.containsKey(p))       dataManager.setInternalProperty(entity,p,save.get(p));
    }
 else     if (save != null && (val instanceof Enum || save.get(p) instanceof Enum || val instanceof Value|| save.get(p) instanceof Value)) {
      if (save.containsKey(p))       dataManager.setInternalProperty(entity,p,save.get(p));
    }
 else     if (save != null && save.containsKey(p)) {
      if (!PersistenceManager.objectEquals(dataManager,val,save.get(p)))       dataManager.setInternalProperty(entity,p,save.get(p));
    }
 else     if (val instanceof Identifiable)     resetEntity(mergeContext,val,(Identifiable)val,cache);
 else     if (val != null && parent != null)     resetEntity(mergeContext,val,parent,cache);
  }
  markNotDirty(entity,null);
}

Fixed version (ground truth):
/** 
 * @private Internal implementation of entity reset
 */
@SuppressWarnings("String_Node_Str") public void resetEntity(MergeContext mergeContext,Object entity,Identifiable parent,Set<Object> cache){
  if (entity instanceof Lazyable && !((Lazyable)entity).isInitialized())   return;
  if (cache.contains(entity))   return;
  cache.add(entity);
  Map<String,Object> save=savedProperties.get(entity);
  EntityDescriptor desc=PersistenceManager.getEntityDescriptor(entity);
  Map<String,Object> pval=dataManager.getPropertyValues(entity,false,false);
  for (  String p : pval.keySet()) {
    if (p.equals(desc.getVersionPropertyName()))     continue;
    List<Object> removed=null;
    Object val=dataManager.getProperty(entity,p);
    if (val instanceof List<?> && !(val instanceof LazyableCollection && !((LazyableCollection)val).isInitialized())) {
      List<Object> list=(List<Object>)val;
      List<Change> savedArray=save != null ? (List<Change>)save.get(p) : null;
      if (savedArray != null) {
        for (int a=savedArray.size() - 1; a >= 0; a--) {
          if (a >= savedArray.size()) {
            log.debug("String_Node_Str",list);
            break;
          }
          Change ce=savedArray.get(a);
          if (ce.getKind() == ChangeKind.ADD) {
            if (removed == null)             removed=new ArrayList<Object>();
            for (int z=0; z < ce.getItems().length; z++) {
              if (ce.getLocation() < list.size())               removed.add(list.remove(ce.getLocation()));
 else               log.debug("String_Node_Str",list,ce.getLocation());
            }
          }
 else           if (ce.getKind() == ChangeKind.REMOVE) {
            for (int z=0; z < ce.getItems().length; z++) {
              if (ce.getLocation() + z <= list.size())               list.add(ce.getLocation() + z,ce.getItems()[z]);
 else               log.debug("String_Node_Str",list,ce.getLocation() + z);
            }
          }
 else           if (ce.getKind() == ChangeKind.REPLACE) {
            if (removed == null)             removed=new ArrayList<Object>();
            for (int z=0; z < ce.getItems().length; z++) {
              if (ce.getLocation() + z < list.size())               removed.add(list.set(ce.getLocation() + z,((Object[])ce.getItems()[z])[0]));
 else               log.debug("String_Node_Str",list,ce.getLocation() + z);
            }
          }
        }
        markNotDirty(val,parent);
      }
      for (      Object o : list) {
        if (o instanceof Identifiable)         resetEntity(mergeContext,o,(Identifiable)o,cache);
      }
      if (removed != null) {
        for (        Object o : removed) {
          if (o instanceof Identifiable)           resetEntity(mergeContext,o,(Identifiable)o,cache);
        }
      }
    }
 else     if (val instanceof Map<?,?> && !(val instanceof LazyableCollection && !((LazyableCollection)val).isInitialized())) {
      Map<Object,Object> map=(Map<Object,Object>)val;
      List<Change> savedArray=save != null ? (List<Change>)save.get(p) : null;
      if (savedArray != null) {
        for (int a=savedArray.size() - 1; a >= 0; a--) {
          Change ce=savedArray.get(a);
          if (ce.getKind() == ChangeKind.ADD) {
            if (removed == null)             removed=new ArrayList<Object>();
            for (int z=0; z < ce.getItems().length; z++) {
              removed.add(map.remove(((Object[])ce.getItems()[z])[0]));
              removed.add(((Object[])ce.getItems()[z])[0]);
            }
          }
 else           if (ce.getKind() == ChangeKind.REMOVE) {
            for (int z=0; z < ce.getItems().length; z++)             map.put(((Object[])ce.getItems()[z])[0],((Object[])ce.getItems()[z])[1]);
          }
 else           if (ce.getKind() == ChangeKind.REPLACE) {
            if (removed == null)             removed=new ArrayList<Object>();
            for (int z=0; z < ce.getItems().length; z++) {
              removed.add(map.put(((Object[])ce.getItems()[z])[0],((Object[])ce.getItems()[z])[1]));
            }
          }
        }
        markNotDirty(val,parent);
      }
      for (      Entry<Object,Object> me : map.entrySet()) {
        if (me.getKey() instanceof Identifiable)         resetEntity(mergeContext,me.getKey(),(Identifiable)me.getKey(),cache);
        if (me.getValue() instanceof Identifiable)         resetEntity(mergeContext,me.getValue(),(Identifiable)me.getValue(),cache);
      }
      if (removed != null) {
        for (        Object o : removed) {
          if (o instanceof Identifiable)           resetEntity(mergeContext,o,(Identifiable)o,cache);
        }
      }
    }
 else     if (save != null && (ObjectUtil.isSimple(val) || ObjectUtil.isSimple(save.get(p)))) {
      if (save.containsKey(p))       dataManager.setInternalProperty(entity,p,save.get(p));
    }
 else     if (save != null && (val instanceof Enum || save.get(p) instanceof Enum || val instanceof Value|| save.get(p) instanceof Value)) {
      if (save.containsKey(p))       dataManager.setInternalProperty(entity,p,save.get(p));
    }
 else     if (save != null && save.containsKey(p)) {
      if (!PersistenceManager.objectEquals(dataManager,val,save.get(p)))       dataManager.setInternalProperty(entity,p,save.get(p));
    }
 else     if (val instanceof Identifiable)     resetEntity(mergeContext,val,(Identifiable)val,cache);
 else     if (val != null && parent != null && !ObjectUtil.isSimple(val))     resetEntity(mergeContext,val,parent,cache);
  }
  markNotDirty(entity,null);
}