nus-yam/ex-repair huggingface dataset:
Program: 51581
Project: 51581
Buggy source:
public void getMemberRange(RolapLevel level,RolapMember startMember,RolapMember endMember,List list){
  for (int i=startMember.ordinal; i <= endMember.ordinal; i++) {
    if (members[i].getLevel() == endMember.getLevel()) {
      list.add(members[i]);
    }
  }
}

Fixed version (ground truth):
public void getMemberRange(RolapLevel level,RolapMember startMember,RolapMember endMember,List list){
  Util.assertPrecondition(startMember != null,"String_Node_Str");
  Util.assertPrecondition(endMember != null,"String_Node_Str");
  Util.assertPrecondition(startMember.getLevel() == endMember.getLevel(),"String_Node_Str");
  for (int i=startMember.ordinal; i <= endMember.ordinal; i++) {
    if (members[i].getLevel() == endMember.getLevel()) {
      list.add(members[i]);
    }
  }
}
Program: 51582
Project: 51582
Buggy source:
public RolapMember getLeadMember(RolapMember member,int n){
  int i=0;
  int increment=1;
  if (n < 0) {
    increment=-1;
    n=-n;
  }
  while (i < n) {
    member=memberReader.getLeadMember(member,increment);
    if (canSee(member)) {
      ++i;
    }
  }
  return member;
}

Fixed version (ground truth):
public RolapMember getLeadMember(RolapMember member,int n){
  int i=0;
  int increment=1;
  if (n < 0) {
    increment=-1;
    n=-n;
  }
  while (i < n) {
    member=memberReader.getLeadMember(member,increment);
    if (member.isNull())     return member;
    if (canSee(member)) {
      ++i;
    }
  }
  return member;
}
Program: 51583
Project: 51583
Buggy source:
/** 
 * Creates a   {@link MemberReader} with which to read a hierarchy.
 */
private MemberReader createMemberReader(RolapHierarchy hierarchy,MondrianDef.Hierarchy xmlHierarchy){
  if (xmlHierarchy.memberReaderClass != null) {
    Exception e2=null;
    try {
      Properties properties=null;
      Class clazz=Class.forName(xmlHierarchy.memberReaderClass);
      Constructor constructor=clazz.getConstructor(new Class[]{RolapHierarchy.class,Properties.class});
      Object o=constructor.newInstance(new Object[]{hierarchy,properties});
      if (o instanceof MemberReader) {
        return (MemberReader)o;
      }
 else       if (o instanceof MemberSource) {
        return new CacheMemberReader((MemberSource)o);
      }
 else {
        throw Util.getRes().newInternal("String_Node_Str" + clazz + "String_Node_Str"+ MemberSource.class);
      }
    }
 catch (    ClassNotFoundException e) {
      e2=e;
    }
catch (    NoSuchMethodException e) {
      e2=e;
    }
catch (    InstantiationException e) {
      e2=e;
    }
catch (    IllegalAccessException e) {
      e2=e;
    }
catch (    InvocationTargetException e) {
      e2=e;
    }
    throw Util.getRes().newInternal("String_Node_Str" + xmlHierarchy.memberReaderClass,e2);
  }
 else {
    SqlMemberSource source=new SqlMemberSource(hierarchy);
    int memberCount=source.getMemberCount();
    int largeDimensionThreshold=MondrianProperties.instance().getLargeDimensionThreshold();
    if (memberCount > largeDimensionThreshold) {
      return new SmartMemberReader(source);
    }
 else {
      return new CacheMemberReader(source);
    }
  }
}

Fixed version (ground truth):
/** 
 * Creates a   {@link MemberReader} with which to read a hierarchy.
 */
private MemberReader createMemberReader(RolapHierarchy hierarchy,MondrianDef.Hierarchy xmlHierarchy){
  if (xmlHierarchy.memberReaderClass != null) {
    Exception e2=null;
    try {
      Properties properties=null;
      Class clazz=Class.forName(xmlHierarchy.memberReaderClass);
      Constructor constructor=clazz.getConstructor(new Class[]{RolapHierarchy.class,Properties.class});
      Object o=constructor.newInstance(new Object[]{hierarchy,properties});
      if (o instanceof MemberReader) {
        return (MemberReader)o;
      }
 else       if (o instanceof MemberSource) {
        return new CacheMemberReader((MemberSource)o);
      }
 else {
        throw Util.getRes().newInternal("String_Node_Str" + clazz + "String_Node_Str"+ MemberSource.class);
      }
    }
 catch (    ClassNotFoundException e) {
      e2=e;
    }
catch (    NoSuchMethodException e) {
      e2=e;
    }
catch (    InstantiationException e) {
      e2=e;
    }
catch (    IllegalAccessException e) {
      e2=e;
    }
catch (    InvocationTargetException e) {
      e2=e;
    }
    throw Util.getRes().newInternal("String_Node_Str" + xmlHierarchy.memberReaderClass,e2);
  }
 else {
    SqlMemberSource source=new SqlMemberSource(hierarchy);
    return new SmartMemberReader(source);
  }
}
Program: 51584
Project: 51584
Buggy source:
public int getMemberCount(){
  return source.getMemberCount();
}

Fixed version (ground truth):
/** 
 * Returns the descendants of <code>member</code> at <code>level</code> whose ordinal is between <code>startOrdinal</code> and <code>endOrdinal</code>.
 */
public int getMemberCount(){
  return source.getMemberCount();
}
Program: 51585
Project: 51585
Buggy source:
/** 
 * Generates the SQL statement to access members of <code>level</code>. For example, <blockquote> <pre>SELECT "country", "state_province", "city" FROM "customer" GROUP BY "country", "state_province", "city", "init", "bar"</pre> </blockquote> accesses the "City" level of the "Customers" hierarchy. Note that:<ul> <li><code>"country", "state_province"</code> are the parent keys;</li> <li><code>"city"</code> is the level key;</li> <li><code>"init", "bar"</code> are member properties.</li> </ul>
 * @pre !level.isAll()
 */
String makeLevelSql(RolapLevel level,Connection jdbcConnection){
  Util.assertPrecondition(!level.isAll());
  SqlQuery sqlQuery=newQuery(jdbcConnection,"String_Node_Str" + level);
  RolapLevel[] levels=(RolapLevel[])hierarchy.getLevels();
  RolapLevel lastLevel=levels[levels.length - 1];
  final boolean needGroup=level != lastLevel;
  int levelDepth=level.getDepth();
  for (int i=0; i <= levelDepth; i++) {
    RolapLevel level2=levels[i];
    if (level2.isAll()) {
      continue;
    }
    hierarchy.addToFrom(sqlQuery,level2.keyExp,null);
    String q=level2.keyExp.getExpression(sqlQuery);
    sqlQuery.addSelect(q);
    if (needGroup) {
      sqlQuery.addGroupBy(q);
    }
    hierarchy.addToFrom(sqlQuery,level2.ordinalExp,null);
    sqlQuery.addOrderBy(level2.ordinalExp.getExpression(sqlQuery));
    for (int j=0; j < level2.properties.length; j++) {
      RolapProperty property=level2.properties[j];
      String q2=property.exp.getExpression(sqlQuery);
      sqlQuery.addSelect(q2);
      if (needGroup) {
        sqlQuery.addGroupBy(q2);
      }
    }
  }
  return sqlQuery.toString();
}

Fixed version (ground truth):
/** 
 * Generates the SQL statement to access members of <code>level</code>. For example, <blockquote> <pre>SELECT "country", "state_province", "city" FROM "customer" GROUP BY "country", "state_province", "city", "init", "bar"</pre> </blockquote> accesses the "City" level of the "Customers" hierarchy. Note that:<ul> <li><code>"country", "state_province"</code> are the parent keys;</li> <li><code>"city"</code> is the level key;</li> <li><code>"init", "bar"</code> are member properties.</li> </ul>
 * @pre !level.isAll()
 */
String makeLevelSql(RolapLevel level,Connection jdbcConnection){
  Util.assertPrecondition(!level.isAll());
  SqlQuery sqlQuery=newQuery(jdbcConnection,"String_Node_Str" + level);
  RolapLevel[] levels=(RolapLevel[])hierarchy.getLevels();
  int levelDepth=level.getDepth();
  for (int i=0; i <= levelDepth; i++) {
    RolapLevel level2=levels[i];
    if (level2.isAll()) {
      continue;
    }
    hierarchy.addToFrom(sqlQuery,level2.keyExp,null);
    String q=level2.keyExp.getExpression(sqlQuery);
    sqlQuery.addSelect(q);
    sqlQuery.addGroupBy(q);
    hierarchy.addToFrom(sqlQuery,level2.ordinalExp,null);
    sqlQuery.addOrderBy(level2.ordinalExp.getExpression(sqlQuery));
    for (int j=0; j < level2.properties.length; j++) {
      RolapProperty property=level2.properties[j];
      String q2=property.exp.getExpression(sqlQuery);
      sqlQuery.addSelect(q2);
      sqlQuery.addGroupBy(q2);
    }
  }
  return sqlQuery.toString();
}
Program: 51586
Project: 51586
Buggy source:
/** 
 * Drops constraints, where the list of values is close to the values which would be returned anyway.
 */
public synchronized Object[][] optimizeConstraints(Object[][] constraintses){
  Util.assertTrue(constraintses.length == columns.length);
  Object[][] newConstraintses=(Object[][])constraintses.clone();
  ConstraintComparator comparator=new ConstraintComparator(constraintses);
  Integer[] indexes=new Integer[columns.length];
  double cellCount=1.0;
  for (int i=0; i < columns.length; i++) {
    indexes[i]=new Integer(i);
    cellCount*=comparator.getCardinality(i);
  }
  Arrays.sort(indexes,comparator);
  double originalCellCount=cellCount, maxCellCount=originalCellCount * 2 + 10;
  if (oracle) {
    final int MAXLEN=1000;
    for (int i=0; i < newConstraintses.length; i++) {
      Object[] arr=newConstraintses[i];
      if (arr != null && arr.length > MAXLEN) {
        double bloat=comparator.getBloat(i);
        cellCount*=bloat;
        newConstraintses[i]=null;
      }
    }
  }
  for (int i=0; i < indexes.length; i++) {
    int j=indexes[i].intValue();
    double bloat=comparator.getBloat(j);
    cellCount*=bloat;
    if (cellCount < maxCellCount) {
      newConstraintses[j]=null;
    }
 else {
      break;
    }
  }
  return newConstraintses;
}

Fixed version (ground truth):
/** 
 * we do NOT optimize, we fetch exactly what we need - which performs better than counting the number of rows and fetching more cells than requested.
 */
public synchronized Object[][] optimizeConstraints(Object[][] constraintses){
  Util.assertTrue(constraintses.length == columns.length);
  Object[][] newConstraintses=(Object[][])constraintses.clone();
  if (oracle) {
    final int MAXLEN=1000;
    for (int i=0; i < newConstraintses.length; i++) {
      Object[] arr=newConstraintses[i];
      if (arr != null && arr.length > MAXLEN) {
        newConstraintses[i]=null;
      }
    }
  }
  return newConstraintses;
}
Program: 51587
Project: 51587
Buggy source:
public void putChildren(RolapMember member,ArrayList children){
  ChildrenList childrenList=new ChildrenList(this,member,children);
  CachePool.SoftCacheableReference ref=new CachePool.SoftCacheableReference(childrenList);
  final CachePool cachePool=CachePool.instance();
  if (cachePool.isRegistered(childrenList)) {
    if (RolapUtil.debugOut != null) {
      RolapUtil.debugOut.println("String_Node_Str" + childrenList + "String_Node_Str"+ "String_Node_Str");
    }
  }
 else {
synchronized (this) {
      CachePool.SoftCacheableReference oldRef=(CachePool.SoftCacheableReference)mapMemberToChildren.put(member,ref);
      if (oldRef != null) {
        ChildrenList old=(ChildrenList)oldRef.getCacheableOrFail();
        if (RolapUtil.debugOut != null) {
          RolapUtil.debugOut.println("String_Node_Str" + oldRef + "String_Node_Str"+ old);
        }
        mapMemberToChildren.put(member,oldRef);
        cachePool.deregister(old,false);
        mapMemberToChildren.put(member,ref);
      }
      cachePool.register(childrenList);
    }
  }
}

Fixed version (ground truth):
public synchronized void putChildren(RolapMember member,ArrayList children){
  ChildrenList childrenList=new ChildrenList(this,member,children);
  SoftCacheableReference ref=new SoftCacheableReference(childrenList);
  final CachePool cachePool=CachePool.instance();
synchronized (cachePool) {
    SoftCacheableReference oldRef=(SoftCacheableReference)mapMemberToChildren.put(member,ref);
    if (oldRef != null) {
      ChildrenList old=(ChildrenList)oldRef.getCacheable();
      if (RolapUtil.debugOut != null) {
        RolapUtil.debugOut.println("String_Node_Str" + oldRef + "String_Node_Str"+ old);
      }
      if (old != null)       cachePool.deregister(old,false);
    }
    cachePool.register(childrenList);
  }
}
Program: 51588
Project: 51588
Buggy source:
private synchronized void remove(ChildrenList childrenList){
  CachePool.SoftCacheableReference ref=(CachePool.SoftCacheableReference)mapMemberToChildren.remove(childrenList.member);
  if (ref == null || !ref.refersTo(childrenList)) {
    throw Util.newInternal("String_Node_Str" + childrenList + "String_Node_Str"+ ref+ "String_Node_Str");
  }
}

Fixed version (ground truth):
private void remove(ChildrenList childrenList){
  mapMemberToChildren.remove(childrenList.member);
}
Program: 51589
Project: 51589
Buggy source:
public RolapMember getLeadMember(RolapMember member,int n){
  if (n == 0) {
    return member;
  }
 else   if (false) {
    RolapMember parent=(RolapMember)member.getParentMember();
    CachePool.SoftCacheableReference refSiblings;
synchronized (this) {
      refSiblings=(CachePool.SoftCacheableReference)mapMemberToChildren.get(parent);
    }
    if (refSiblings != null) {
      ChildrenList siblings=(ChildrenList)refSiblings.getCacheableOrFail();
      int pos=siblings.list.indexOf(member);
      Util.assertTrue(pos >= 0);
      int siblingPos=pos + n;
      if (siblingPos >= 0 && siblingPos < siblings.list.size()) {
        return (RolapMember)siblings.list.get(pos + n);
      }
    }
    return source.getLeadMember(member,n);
  }
 else {
    SiblingIterator iter=new SiblingIterator(this,member);
    if (n > 0) {
      RolapMember sibling=null;
      while (n-- > 0) {
        if (!iter.hasNext()) {
          return (RolapMember)member.getHierarchy().getNullMember();
        }
        sibling=iter.nextMember();
      }
      return sibling;
    }
 else {
      n=-n;
      RolapMember sibling=null;
      while (n-- > 0) {
        if (!iter.hasPrevious()) {
          return (RolapMember)member.getHierarchy().getNullMember();
        }
        sibling=iter.previousMember();
      }
      return sibling;
    }
  }
}

Fixed version (ground truth):
public synchronized RolapMember getLeadMember(RolapMember member,int n){
  if (n == 0) {
    return member;
  }
 else {
    SiblingIterator iter=new SiblingIterator(this,member);
    if (n > 0) {
      RolapMember sibling=null;
      while (n-- > 0) {
        if (!iter.hasNext()) {
          return (RolapMember)member.getHierarchy().getNullMember();
        }
        sibling=iter.nextMember();
      }
      return sibling;
    }
 else {
      n=-n;
      RolapMember sibling=null;
      while (n-- > 0) {
        if (!iter.hasPrevious()) {
          return (RolapMember)member.getHierarchy().getNullMember();
        }
        sibling=iter.previousMember();
      }
      return sibling;
    }
  }
}
Program: 51590
Project: 51590
Buggy source:
public void getMemberChildren(List parentMembers,List children){
  ArrayList missed=new ArrayList();
  for (int i=0, n=parentMembers.size(); i < n; i++) {
    RolapMember parent=(RolapMember)parentMembers.get(i);
    CachePool.SoftCacheableReference ref=(CachePool.SoftCacheableReference)mapMemberToChildren.get(parent);
    if (ref == null) {
      missed.add(parent);
    }
 else {
      ChildrenList v=(ChildrenList)ref.getCacheable();
      if (v == null) {
        missed.add(parent);
      }
 else {
        children.addAll(v.list);
      }
    }
  }
  if (missed.size() > 0) {
    readMemberChildren(missed,children);
  }
}

Fixed version (ground truth):
public void getMemberChildren(List parentMembers,List children){
  ArrayList missed=new ArrayList();
  for (Iterator it=parentMembers.iterator(); it.hasNext(); ) {
    RolapMember parent=(RolapMember)it.next();
    SoftCacheableReference ref=(SoftCacheableReference)mapMemberToChildren.get(parent);
    if (ref == null) {
      missed.add(parent);
    }
 else {
      ChildrenList v=(ChildrenList)ref.getCacheable();
      if (v == null) {
        it.remove();
        missed.add(parent);
      }
 else {
        children.addAll(v.list);
      }
    }
  }
  if (missed.size() > 0) {
    readMemberChildren(missed,children);
  }
}
Program: 51591
Project: 51591
Buggy source:
protected synchronized void finalize(){
  CachePool.instance().deregister(this,true);
}

Fixed version (ground truth):
protected void finalize(){
  CachePool.instance().deregister(this,true);
}
Program: 51592
Project: 51592
Buggy source:
public RolapMember[] getMembers(){
  ArrayList v=new ArrayList();
  RolapLevel[] levels=(RolapLevel[])getHierarchy().getLevels();
  for (int i=0; i < levels.length; i++) {
    getMembersInLevel(v,levels[i],0,Integer.MAX_VALUE);
  }
  return RolapUtil.toArray(v);
}

Fixed version (ground truth):
public List getMembers(){
  return members;
}
Program: 51593
Project: 51593
Buggy source:
Aggregation(RolapStar star,RolapStar.Column[] columns){
  this.star=star;
  this.columns=columns;
  this.segmentRefs=new ArrayList();
}

Fixed version (ground truth):
Aggregation(RolapStar star,RolapStar.Column[] columns){
  this.star=star;
  this.columns=columns;
  this.segmentRefs=Collections.synchronizedList(new ArrayList());
}
Program: 51594
Project: 51594
Buggy source:
/** 
 * Loads a set of segments into this aggregation, one per measure, each constrained by the same set of column values, and each pinned once. For example, measures = {unit_sales, store_sales}, state = {CA, OR}, gender = unconstrained
 */
synchronized void load(RolapStar.Measure[] measures,Object[][] constraintses,Collection pinnedSegments){
  Segment[] segments=new Segment[measures.length];
  final CachePool cachePool=CachePool.instance();
  for (int i=0; i < measures.length; i++) {
    RolapStar.Measure measure=measures[i];
    Segment segment=new Segment(this,measure,constraintses);
    segments[i]=segment;
    CachePool.SoftCacheableReference ref=new CachePool.SoftCacheableReference(segment);
    this.segmentRefs.add(ref);
    final int pinCount=1;
    cachePool.register(segment,pinCount,pinnedSegments);
  }
  Segment.load(segments,pinnedSegments);
}

Fixed version (ground truth):
/** 
 * Loads a set of segments into this aggregation, one per measure, each constrained by the same set of column values, and each pinned once. For example, measures = {unit_sales, store_sales}, state = {CA, OR}, gender = unconstrained
 */
public synchronized void load(RolapStar.Measure[] measures,Object[][] constraintses,Collection pinnedSegments){
  Segment[] segments=new Segment[measures.length];
  final CachePool cachePool=CachePool.instance();
  for (int i=0; i < measures.length; i++) {
    RolapStar.Measure measure=measures[i];
    Segment segment=new Segment(this,measure,constraintses);
    segments[i]=segment;
    SoftCacheableReference ref=new SoftCacheableReference(segment);
    this.segmentRefs.add(ref);
    final int pinCount=1;
    cachePool.register(segment,pinCount,pinnedSegments);
  }
  Segment.load(segments,pinnedSegments);
}
Program: 51595
Project: 51595
Buggy source:
/** 
 * Retrieves the value identified by <code>keys</code>. <p>If <code>pinSet</code> is not null, pins the segment which holds it. <code>pinSet</code> ensures that a segment is only pinned once. Returns <code>null</code> if no segment contains the cell.
 */
synchronized Object get(RolapStar.Measure measure,Object[] keys,Collection pinSet){
  for (int i=0, count=segmentRefs.size(); i < count; i++) {
    CachePool.SoftCacheableReference ref=(CachePool.SoftCacheableReference)segmentRefs.get(i);
    Segment segment=(Segment)ref.getCacheable();
    if (segment == null) {
      continue;
    }
    if (segment.measure != measure) {
      continue;
    }
    if (segment.isReady()) {
      Object o=segment.get(keys);
      if (o != null) {
        if (pinSet != null) {
          CachePool.instance().pin(segment,pinSet);
        }
        return o;
      }
    }
 else {
      if (segment.wouldContain(keys)) {
        if (pinSet != null) {
          CachePool.instance().pin(segment,pinSet);
        }
        return null;
      }
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Retrieves the value identified by <code>keys</code>. <p>If <code>pinSet</code> is not null, pins the segment which holds it. <code>pinSet</code> ensures that a segment is only pinned once. Returns <code>null</code> if no segment contains the cell.
 */
public synchronized Object get(RolapStar.Measure measure,Object[] keys,Collection pinSet){
synchronized (CachePool.instance()) {
    for (Iterator it=segmentRefs.iterator(); it.hasNext(); ) {
      SoftCacheableReference ref=(SoftCacheableReference)it.next();
      Segment segment=(Segment)ref.getCacheable();
      if (segment == null) {
        it.remove();
        continue;
      }
      if (segment.measure != measure) {
        continue;
      }
      if (segment.isReady()) {
        Object o=segment.get(keys);
        if (o != null) {
          if (pinSet != null) {
            CachePool.instance().pin(segment,pinSet);
          }
          return o;
        }
      }
 else {
        if (segment.wouldContain(keys)) {
          if (pinSet != null) {
            CachePool.instance().pin(segment,pinSet);
          }
          return null;
        }
      }
    }
  }
  return null;
}
Program: 51596
Project: 51596
Buggy source:
/** 
 * Drops constraints, where the list of values is close to the values which would be returned anyway.
 */
Object[][] optimizeConstraints(Object[][] constraintses){
  Util.assertTrue(constraintses.length == columns.length);
  Object[][] newConstraintses=(Object[][])constraintses.clone();
  ConstraintComparator comparator=new ConstraintComparator(constraintses);
  Integer[] indexes=new Integer[columns.length];
  double cellCount=1.0;
  for (int i=0; i < columns.length; i++) {
    indexes[i]=new Integer(i);
    cellCount*=comparator.getCardinality(i);
  }
  Arrays.sort(indexes,comparator);
  double originalCellCount=cellCount, maxCellCount=originalCellCount * 2 + 10;
  for (int i=0; i < indexes.length; i++) {
    int j=indexes[i].intValue();
    double bloat=comparator.getBloat(j);
    cellCount*=bloat;
    if (cellCount < maxCellCount) {
      newConstraintses[j]=null;
    }
 else {
      break;
    }
  }
  return newConstraintses;
}

Fixed version (ground truth):
/** 
 * Drops constraints, where the list of values is close to the values which would be returned anyway.
 */
public synchronized Object[][] optimizeConstraints(Object[][] constraintses){
  Util.assertTrue(constraintses.length == columns.length);
  Object[][] newConstraintses=(Object[][])constraintses.clone();
  ConstraintComparator comparator=new ConstraintComparator(constraintses);
  Integer[] indexes=new Integer[columns.length];
  double cellCount=1.0;
  for (int i=0; i < columns.length; i++) {
    indexes[i]=new Integer(i);
    cellCount*=comparator.getCardinality(i);
  }
  Arrays.sort(indexes,comparator);
  double originalCellCount=cellCount, maxCellCount=originalCellCount * 2 + 10;
  for (int i=0; i < indexes.length; i++) {
    int j=indexes[i].intValue();
    double bloat=comparator.getBloat(j);
    cellCount*=bloat;
    if (cellCount < maxCellCount) {
      newConstraintses[j]=null;
    }
 else {
      break;
    }
  }
  return newConstraintses;
}
Program: 51597
Project: 51597
Buggy source:
synchronized void removeSegment(Segment segment){
  boolean existed=segmentRefs.remove(new CachePool.SoftCacheableReference(segment));
  Util.assertTrue(existed,"String_Node_Str");
}

Fixed version (ground truth):
/** 
 * must <em>not</em> be synchronized 
 */
void removeSegment(Segment segment){
  segmentRefs.remove(new SoftCacheableReference(segment));
}
Program: 51598
Project: 51598
Buggy source:
/** 
 * Flushes all unpinned objects in the cache. Objects which are still pinned are marked, so they will be removed immediately that they are unpinned.
 */
public synchronized void flush(){
  while (removeLast() != null) {
  }
  pinnedZombies.addAll(pinned);
}

Fixed version (ground truth):
/** 
 * Flushes all unpinned objects in the cache. Objects which are still pinned are marked, so they will be removed immediately that they are unpinned.
 * @deprecated this method may cause dead locks, use AggregationManager.flushCache() instead
 */
public synchronized void flush(){
  internalFlush();
}
Program: 51599
Project: 51599
Buggy source:
/** 
 * Returns or creates the singleton. 
 */
public static synchronized RolapAggregationManager instance(){
  if (instance == null) {
    instance=new AggregationManager();
  }
  return instance;
}

Fixed version (ground truth):
/** 
 * Returns or creates the singleton. 
 */
public static synchronized AggregationManager instance(){
  if (instance == null) {
    instance=new AggregationManager();
  }
  return instance;
}
Program: 51600
Project: 51600
Buggy source:
public void run(int i){
  for (int j=0; j < iterationCount; j++) {
    int queryIndex=(i * 2 + j) % queries.length;
    try {
      runQueryCheckResult(queries[queryIndex]);
      if (flush && i == 0) {
        CachePool.instance().flush();
      }
      executeCount[0]++;
    }
 catch (    Throwable e) {
      e.printStackTrace();
      throw Util.newInternal(e,"String_Node_Str" + i + "String_Node_Str"+ queryIndex);
    }
  }
}

Fixed version (ground truth):
public void run(int i){
  for (int j=0; j < iterationCount; j++) {
    int queryIndex=(i * 2 + j) % queries.length;
    try {
      runQueryCheckResult(queries[queryIndex]);
      if (flush && i == 0) {
        AggregationManager.instance().flushCachePool();
      }
      executeCount[0]++;
    }
 catch (    Throwable e) {
      e.printStackTrace();
      throw Util.newInternal(e,"String_Node_Str" + i + "String_Node_Str"+ queryIndex);
    }
  }
}
Program: 51601
Project: 51601
Buggy source:
private void runParallelQueries(final int threadCount,final int iterationCount,final boolean flush){
  int timeoutMs=threadCount * iterationCount * 10* 1000;
  final int[] executeCount=new int[]{0};
  final QueryAndResult[] queries=new QueryAndResult[sampleQueries.length + taglibQueries.length];
  System.arraycopy(sampleQueries,0,queries,0,sampleQueries.length);
  System.arraycopy(taglibQueries,0,queries,sampleQueries.length,taglibQueries.length);
  TestCaseForker threaded=new TestCaseForker(this,timeoutMs,threadCount,new ChooseRunnable(){
    public void run(    int i){
      for (int j=0; j < iterationCount; j++) {
        int queryIndex=(i * 2 + j) % queries.length;
        try {
          runQueryCheckResult(queries[queryIndex]);
          if (flush && i == 0) {
            CachePool.instance().flush();
          }
          executeCount[0]++;
        }
 catch (        Throwable e) {
          e.printStackTrace();
          throw Util.newInternal(e,"String_Node_Str" + i + "String_Node_Str"+ queryIndex);
        }
      }
    }
  }
);
  threaded.run();
  assertEquals(threadCount * iterationCount,executeCount[0]);
}

Fixed version (ground truth):
private void runParallelQueries(final int threadCount,final int iterationCount,final boolean flush){
  int timeoutMs=threadCount * iterationCount * 10* 1000;
  final int[] executeCount=new int[]{0};
  final QueryAndResult[] queries=new QueryAndResult[sampleQueries.length + taglibQueries.length];
  System.arraycopy(sampleQueries,0,queries,0,sampleQueries.length);
  System.arraycopy(taglibQueries,0,queries,sampleQueries.length,taglibQueries.length);
  TestCaseForker threaded=new TestCaseForker(this,timeoutMs,threadCount,new ChooseRunnable(){
    public void run(    int i){
      for (int j=0; j < iterationCount; j++) {
        int queryIndex=(i * 2 + j) % queries.length;
        try {
          runQueryCheckResult(queries[queryIndex]);
          if (flush && i == 0) {
            AggregationManager.instance().flushCachePool();
          }
          executeCount[0]++;
        }
 catch (        Throwable e) {
          e.printStackTrace();
          throw Util.newInternal(e,"String_Node_Str" + i + "String_Node_Str"+ queryIndex);
        }
      }
    }
  }
);
  threaded.run();
  assertEquals(threadCount * iterationCount,executeCount[0]);
}
Program: 51602
Project: 51602
Buggy source:
/** 
 * Query with distinct-count measure and no other measures gives  {@link ArrayIndexOutOfBoundsException}
 */
public void testBug804903(){
  CachePool.instance().flush();
  runQueryCheckResult("String_Node_Str" + nl + "String_Node_Str"+ nl+ "String_Node_Str"+ nl+ "String_Node_Str","String_Node_Str" + nl + "String_Node_Str"+ nl+ "String_Node_Str"+ nl+ "String_Node_Str"+ nl+ "String_Node_Str"+ nl+ "String_Node_Str"+ nl+ "String_Node_Str"+ nl);
}

Fixed version (ground truth):
/** 
 * Query with distinct-count measure and no other measures gives  {@link ArrayIndexOutOfBoundsException}
 */
public void testBug804903(){
  AggregationManager.instance().flushCachePool();
  runQueryCheckResult("String_Node_Str" + nl + "String_Node_Str"+ nl+ "String_Node_Str"+ nl+ "String_Node_Str","String_Node_Str" + nl + "String_Node_Str"+ nl+ "String_Node_Str"+ nl+ "String_Node_Str"+ nl+ "String_Node_Str"+ nl+ "String_Node_Str"+ nl+ "String_Node_Str"+ nl);
}
Program: 51605
Project: 51605
Buggy source:
static Double getDoubleArg(Evaluator evaluator,Exp[] args,int index){
  Object o=getScalarArg(evaluator,args,index);
  if (o instanceof Double) {
    return (Double)o;
  }
 else   if (o instanceof Number) {
    return new Double(((Number)o).doubleValue());
  }
 else   if (o instanceof Throwable) {
    return new Double(Double.NaN);
  }
 else   if (o == Util.nullValue) {
    return new Double(0);
  }
 else {
    throw Util.newInternal("String_Node_Str" + o + "String_Node_Str");
  }
}

Fixed version (ground truth):
static Double getDoubleArg(Evaluator evaluator,Exp[] args,int index,Double nullValue){
  Object o=getScalarArg(evaluator,args,index);
  if (o instanceof Double) {
    return (Double)o;
  }
 else   if (o instanceof Number) {
    return new Double(((Number)o).doubleValue());
  }
 else   if (o instanceof Throwable) {
    return new Double(Double.NaN);
  }
 else   if (o == null || o == Util.nullValue) {
    return nullValue;
  }
 else {
    throw Util.newInternal("String_Node_Str" + o + "String_Node_Str");
  }
}
Program: 51607
Project: 51607
Buggy source:
static Exp getArgNoEval(Exp[] args,int index){
  return args[index];
}

Fixed version (ground truth):
static Exp getArgNoEval(Exp[] args,int index,Exp defaultValue){
  if (index >= args.length)   return defaultValue;
  return args[index];
}
Program: 51608
Project: 51608
Buggy source:
/** 
 * Decides whether to use a sparse representation for this segment, using the formula described  {@link MondrianProperties#getSparseSegmentCountThreshold here}.
 * @param possibleCount Number of values in the space.
 * @param actualCount Actual number of values.
 * @return Whether to use a sparse representation.
 */
private static boolean useSparse(final double possibleCount,final double actualCount){
  final MondrianProperties properties=MondrianProperties.instance();
  double densityThreshold=properties.getSparseSegmentDensityThreshold();
  if (densityThreshold < 0) {
    densityThreshold=0;
  }
  if (densityThreshold > 1) {
    densityThreshold=1;
  }
  int countThreshold=properties.getSparseSegmentCountThreshold();
  if (countThreshold < 0) {
    countThreshold=0;
  }
  boolean sparse=(possibleCount - countThreshold) > (actualCount * densityThreshold);
  if (possibleCount < countThreshold) {
    Util.assertTrue(!sparse);
  }
  if (possibleCount == actualCount) {
    Util.assertTrue(!sparse);
  }
  return sparse;
}

Fixed version (ground truth):
/** 
 * Decides whether to use a sparse representation for this segment, using the formula described  {@link MondrianProperties#getSparseSegmentCountThreshold here}.
 * @param possibleCount Number of values in the space.
 * @param actualCount Actual number of values.
 * @return Whether to use a sparse representation.
 */
private static boolean useSparse(final double possibleCount,final double actualCount){
  final MondrianProperties properties=MondrianProperties.instance();
  double densityThreshold=properties.getSparseSegmentDensityThreshold();
  if (densityThreshold < 0) {
    densityThreshold=0;
  }
  if (densityThreshold > 1) {
    densityThreshold=1;
  }
  int countThreshold=properties.getSparseSegmentCountThreshold();
  if (countThreshold < 0) {
    countThreshold=0;
  }
  boolean sparse=(possibleCount - countThreshold) * densityThreshold > actualCount;
  if (possibleCount < countThreshold) {
    Util.assertTrue(!sparse);
  }
  if (possibleCount == actualCount) {
    Util.assertTrue(!sparse);
  }
  return sparse;
}
Program: 51611
Project: 51611
Buggy source:
public void resolveChild(Formula formula){
  stack.push(formula);
  try {
    formula.resolve(this);
  }
  finally {
    stack.pop();
  }
}

Fixed version (ground truth):
public void resolveChild(Formula formula){
  if (!resolvedNodes.add(formula)) {
    return;
  }
  stack.push(formula);
  try {
    formula.resolve(this);
  }
  finally {
    stack.pop();
  }
}
Program: 51612
Project: 51612
Buggy source:
/** 
 * <b>Note to developers</b>: Must be called from a synchronized context.
 */
private void flushIfNecessary(){
  while ((unpinnedCost + pinnedCost) > costLimit && !queue.isEmpty()) {
    removeLast();
  }
}

Fixed version (ground truth):
/** 
 * Removes unpinned items from the cache until the cost is below the limit. <p>This must <em>not</em> be called from a synchronized context. This is the locking strategy is to lock cacheables before licking the cachepool.
 */
private void flushIfNecessary(){
  Cacheable cacheable;
  while ((cacheable=getOneToFlush()) != null) {
    deregisterInternal(cacheable);
  }
}
Program: 51613
Project: 51613
Buggy source:
/** 
 * Records that an object has just been added to a cache, and pins it, in an atomic operation.
 */
public synchronized void register(Cacheable cacheable,int pinCount,Collection pinned){
  String id=cacheableId(cacheable);
  double cost=cacheable.getCost();
  if (mapCacheableIdToCost.put(id,new Double(cost)) != null) {
    throw Util.newInternal("String_Node_Str" + cacheable + "String_Node_Str");
  }
  cacheable.markAccessed(tick());
  queue.add(new SoftCacheableReference(cacheable));
  unpinnedCost+=cost;
  if (RolapUtil.debugOut != null) {
    RolapUtil.debugOut.println("String_Node_Str" + cacheable + "String_Node_Str"+ cost+ "String_Node_Str"+ size()+ "String_Node_Str"+ unpinnedCost);
  }
  while (pinCount-- > 0) {
    pin(cacheable,pinned);
  }
  flushIfNecessary();
}

Fixed version (ground truth):
/** 
 * Records that an object has just been added to a cache, and pins it, in an atomic operation.
 */
public void register(Cacheable cacheable,int pinCount,Collection pinned){
synchronized (this) {
    String id=cacheableId(cacheable);
    double cost=cacheable.getCost();
    if (mapCacheableIdToCost.put(id,new Double(cost)) != null) {
      throw Util.newInternal("String_Node_Str" + cacheable + "String_Node_Str");
    }
    cacheable.markAccessed(tick());
    queue.add(new SoftCacheableReference(cacheable));
    unpinnedCost+=cost;
    if (RolapUtil.debugOut != null) {
      RolapUtil.debugOut.println("String_Node_Str" + cacheable + "String_Node_Str"+ cost+ "String_Node_Str"+ size()+ "String_Node_Str"+ unpinnedCost);
    }
    while (pinCount-- > 0) {
      pin(cacheable,pinned);
    }
  }
  flushIfNecessary();
}
Program: 51614
Project: 51614
Buggy source:
public void putChildren(RolapMember member,ArrayList children){
  ChildrenList childrenList=new ChildrenList(this,member,children);
  CachePool.SoftCacheableReference ref=new CachePool.SoftCacheableReference(childrenList);
  final CachePool cachePool=CachePool.instance();
synchronized (cachePool) {
    if (cachePool.isRegistered(childrenList)) {
      if (RolapUtil.debugOut != null) {
        RolapUtil.debugOut.println("String_Node_Str" + childrenList + "String_Node_Str"+ "String_Node_Str");
      }
    }
 else {
synchronized (this) {
        CachePool.SoftCacheableReference oldRef=(CachePool.SoftCacheableReference)mapMemberToChildren.put(member,ref);
        if (oldRef != null) {
          ChildrenList old=(ChildrenList)oldRef.getCacheableOrFail();
          if (RolapUtil.debugOut != null) {
            RolapUtil.debugOut.println("String_Node_Str" + oldRef + "String_Node_Str"+ old);
          }
          mapMemberToChildren.put(member,oldRef);
          cachePool.deregister(old,false);
          mapMemberToChildren.put(member,ref);
        }
        cachePool.register(childrenList);
      }
    }
  }
}

Fixed version (ground truth):
public void putChildren(RolapMember member,ArrayList children){
  ChildrenList childrenList=new ChildrenList(this,member,children);
  CachePool.SoftCacheableReference ref=new CachePool.SoftCacheableReference(childrenList);
  final CachePool cachePool=CachePool.instance();
  if (cachePool.isRegistered(childrenList)) {
    if (RolapUtil.debugOut != null) {
      RolapUtil.debugOut.println("String_Node_Str" + childrenList + "String_Node_Str"+ "String_Node_Str");
    }
  }
 else {
synchronized (this) {
      CachePool.SoftCacheableReference oldRef=(CachePool.SoftCacheableReference)mapMemberToChildren.put(member,ref);
      if (oldRef != null) {
        ChildrenList old=(ChildrenList)oldRef.getCacheableOrFail();
        if (RolapUtil.debugOut != null) {
          RolapUtil.debugOut.println("String_Node_Str" + oldRef + "String_Node_Str"+ old);
        }
        mapMemberToChildren.put(member,oldRef);
        cachePool.deregister(old,false);
        mapMemberToChildren.put(member,ref);
      }
      cachePool.register(childrenList);
    }
  }
}
Program: 51615
Project: 51615
Buggy source:
public void run(){
  try {
    chooseRunnable.run(threadIndex);
  }
 catch (  Throwable e) {
    e.printStackTrace();
    failures.add(e);
  }
 finally {
synchronized (forker) {
      forker.notify();
    }
  }
}

Fixed version (ground truth):
public void run(){
  try {
    chooseRunnable.run(threadIndex);
  }
 catch (  Throwable e) {
    e.printStackTrace();
    failures.add(e);
  }
}
Program: 51616
Project: 51616
Buggy source:
private void executeStripe(int axis,RolapEvaluator evaluator){
  if (axis < 0) {
    RolapAxis _axis=(RolapAxis)slicerAxis;
    int count=_axis.positions.length;
    for (int i=0; i < count; i++) {
      RolapPosition position=(RolapPosition)_axis.positions[i];
      for (int j=0; j < position.members.length; j++) {
        evaluator.setContext(position.members[j]);
      }
      Object o;
      try {
        o=evaluator.evaluateCurrent();
      }
 catch (      MondrianEvaluationException e) {
        o=e;
      }
      if (o != null && o != RolapUtil.valueNotReadyException) {
        CellKey key=point.copy();
        cellValues.put(key,o);
        try {
          Util.discard(getCell(point.ordinals));
        }
 catch (        MondrianEvaluationException e) {
        }
catch (        Throwable e) {
          Util.discard(e);
        }
      }
    }
  }
 else {
    RolapAxis _axis=(RolapAxis)axes[axis];
    int count=_axis.positions.length;
    for (int i=0; i < count; i++) {
      point.ordinals[axis]=i;
      RolapPosition position=(RolapPosition)_axis.positions[i];
      for (int j=0; j < position.members.length; j++) {
        evaluator.setContext(position.members[j]);
      }
      executeStripe(axis - 1,evaluator);
    }
  }
}

Fixed version (ground truth):
private void executeStripe(int axis,RolapEvaluator evaluator){
  if (axis < 0) {
    RolapAxis _axis=(RolapAxis)slicerAxis;
    int count=_axis.positions.length;
    for (int i=0; i < count; i++) {
      RolapPosition position=(RolapPosition)_axis.positions[i];
      for (int j=0; j < position.members.length; j++) {
        evaluator.setContext(position.members[j]);
      }
      Object o;
      try {
        o=evaluator.evaluateCurrent();
      }
 catch (      MondrianEvaluationException e) {
        o=e;
      }
      if (o != null && o != RolapUtil.valueNotReadyException) {
        CellKey key=point.copy();
        cellValues.put(key,o);
        try {
          Cell cell=getCell(point.ordinals);
          Util.discard(cell.getFormattedValue());
        }
 catch (        MondrianEvaluationException e) {
        }
catch (        Throwable e) {
          Util.discard(e);
        }
      }
    }
  }
 else {
    RolapAxis _axis=(RolapAxis)axes[axis];
    int count=_axis.positions.length;
    for (int i=0; i < count; i++) {
      point.ordinals[axis]=i;
      RolapPosition position=(RolapPosition)_axis.positions[i];
      for (int j=0; j < position.members.length; j++) {
        evaluator.setContext(position.members[j]);
      }
      executeStripe(axis - 1,evaluator);
    }
  }
}
Program: 51618
Project: 51618
Buggy source:
static Member getMemberArg(Evaluator evaluator,Exp[] args,int index,boolean fail){
  if (index >= args.length) {
    if (fail) {
      throw Util.getRes().newInternal("String_Node_Str");
    }
 else {
      return null;
    }
  }
  Exp arg=args[index];
  Object o=arg.evaluate(evaluator);
  if (true) {
    return (Member)o;
  }
  if (o instanceof Member) {
    return (Member)o;
  }
 else   if (o instanceof Hierarchy) {
    return evaluator.getContext(((Hierarchy)o).getDimension());
  }
 else   if (o instanceof Dimension) {
    return evaluator.getContext((Dimension)o);
  }
 else {
    throw Util.getRes().newInternal("String_Node_Str" + o);
  }
}

Fixed version (ground truth):
static Member getMemberArg(Evaluator evaluator,Exp[] args,int index,boolean fail){
  if (index >= args.length) {
    if (fail) {
      throw Util.getRes().newInternal("String_Node_Str");
    }
 else {
      return null;
    }
  }
  Exp arg=args[index];
  Object o=arg.evaluate(evaluator);
  if (o instanceof Member) {
    return (Member)o;
  }
 else   if (o instanceof Hierarchy) {
    return evaluator.getContext(((Hierarchy)o).getDimension());
  }
 else   if (o instanceof Dimension) {
    return evaluator.getContext((Dimension)o);
  }
 else {
    throw Util.getRes().newInternal("String_Node_Str" + o);
  }
}
Program: 51620
Project: 51620
Buggy source:
static BigDecimal getDecimalArg(Evaluator evaluator,Exp[] args,int index){
  Object o=args[index].evaluateScalar(evaluator);
  if (o instanceof BigDecimal) {
    return (BigDecimal)o;
  }
 else   if (o instanceof BigInteger) {
    return new BigDecimal((BigInteger)o);
  }
 else   if (o instanceof Number) {
    return new BigDecimal(((Number)o).doubleValue());
  }
 else {
    throw Util.newInternal("String_Node_Str" + o + "String_Node_Str");
  }
}

Fixed version (ground truth):
static BigDecimal getDecimalArg(Evaluator evaluator,Exp[] args,int index){
  Object o=getScalarArg(evaluator,args,index);
  if (o instanceof BigDecimal) {
    return (BigDecimal)o;
  }
 else   if (o instanceof BigInteger) {
    return new BigDecimal((BigInteger)o);
  }
 else   if (o instanceof Number) {
    return new BigDecimal(((Number)o).doubleValue());
  }
 else {
    throw Util.newInternal("String_Node_Str" + o + "String_Node_Str");
  }
}
Program: 51621
Project: 51621
Buggy source:
static int getIntArg(Evaluator evaluator,Exp[] args,int index){
  Object o=args[index].evaluateScalar(evaluator);
  if (o instanceof Number) {
    return ((Number)o).intValue();
  }
 else {
    String s=o.toString();
    double d=Double.valueOf(s).doubleValue();
    return (int)d;
  }
}

Fixed version (ground truth):
static int getIntArg(Evaluator evaluator,Exp[] args,int index){
  Object o=getScalarArg(evaluator,args,index);
  if (o instanceof Number) {
    return ((Number)o).intValue();
  }
 else {
    String s=o.toString();
    double d=Double.valueOf(s).doubleValue();
    return (int)d;
  }
}
Program: 51622
Project: 51622
Buggy source:
static Double getDoubleArg(Evaluator evaluator,Exp[] args,int index){
  Object o=args[index].evaluateScalar(evaluator);
  if (o instanceof Double) {
    return (Double)o;
  }
 else   if (o instanceof Number) {
    return new Double(((Number)o).doubleValue());
  }
 else   if (o instanceof Throwable) {
    return new Double(Double.NaN);
  }
 else   if (o == Util.nullValue) {
    return new Double(0);
  }
 else {
    throw Util.newInternal("String_Node_Str" + o + "String_Node_Str");
  }
}

Fixed version (ground truth):
static Double getDoubleArg(Evaluator evaluator,Exp[] args,int index){
  Object o=getScalarArg(evaluator,args,index);
  if (o instanceof Double) {
    return (Double)o;
  }
 else   if (o instanceof Number) {
    return new Double(((Number)o).doubleValue());
  }
 else   if (o instanceof Throwable) {
    return new Double(Double.NaN);
  }
 else   if (o == Util.nullValue) {
    return new Double(0);
  }
 else {
    throw Util.newInternal("String_Node_Str" + o + "String_Node_Str");
  }
}
Program: 51623
Project: 51623
Buggy source:
public Object evaluate(Evaluator evaluator,Exp[] args){
  List list=null;
  for (int i=0; i < args.length; i++) {
    ExpBase arg=(ExpBase)args[i];
    Object o;
    if (arg instanceof Member) {
      o=arg;
    }
 else {
      Member[] members=arg.isConstantTuple();
      if (members != null) {
        o=members;
      }
 else {
        o=arg.evaluate(evaluator);
      }
    }
    if (o instanceof List) {
      List list2=(List)o;
      if (list == null) {
        list=list2;
      }
 else {
        for (int j=0, count=list2.size(); j < count; j++) {
          Object o2=list2.get(j);
          if (o2 instanceof Member && ((Member)o2).isNull()) {
            continue;
          }
          list.add(o2);
        }
      }
    }
 else {
      if (o instanceof Member && ((Member)o).isNull()) {
        continue;
      }
      if (list == null) {
        list=new ArrayList();
      }
      list.add(o);
    }
  }
  return list;
}

Fixed version (ground truth):
public Object evaluate(Evaluator evaluator,Exp[] args){
  List list=null;
  for (int i=0; i < args.length; i++) {
    ExpBase arg=(ExpBase)args[i];
    Object o;
    if (arg instanceof Member) {
      o=arg;
    }
 else {
      Member[] members=arg.isConstantTuple();
      if (members != null) {
        o=members;
      }
 else {
        o=arg.evaluate(evaluator);
      }
    }
    if (o instanceof List) {
      List list2=(List)o;
      if (list == null) {
        list=makeMutable(list2);
      }
 else {
        for (int j=0, count=list2.size(); j < count; j++) {
          Object o2=list2.get(j);
          if (o2 instanceof Member && ((Member)o2).isNull()) {
            continue;
          }
          list.add(o2);
        }
      }
    }
 else {
      if (o instanceof Member && ((Member)o).isNull()) {
        continue;
      }
      if (list == null) {
        list=new ArrayList();
      }
      list.add(o);
    }
  }
  return list;
}
Program: 51625
Project: 51625
Buggy source:
static int compareHierarchically(Member m1,Member m2,boolean post){
  if (m1.equals(m2)) {
    return 0;
  }
  while (true) {
    int levelDepth1=m1.getLevel().getDepth(), levelDepth2=m2.getLevel().getDepth();
    if (levelDepth1 < levelDepth2) {
      m2=m2.getParentMember();
      if (m1.equals(m2)) {
        return post ? 1 : -1;
      }
    }
 else     if (levelDepth1 > levelDepth2) {
      m1=m1.getParentMember();
      if (m1.equals(m2)) {
        return post ? -1 : 1;
      }
    }
 else {
      Member prev1=m1, prev2=m2;
      m1=m1.getParentMember();
      m2=m2.getParentMember();
      if (m1.equals(m2)) {
        return FunUtil.compareValues(prev1.getCaption(),prev2.getCaption());
      }
    }
  }
}

Fixed version (ground truth):
static int compareHierarchically(Member m1,Member m2,boolean post){
  if (equals(m1,m2)) {
    return 0;
  }
  while (true) {
    int levelDepth1=m1.getLevel().getDepth(), levelDepth2=m2.getLevel().getDepth();
    if (levelDepth1 < levelDepth2) {
      m2=m2.getParentMember();
      if (equals(m1,m2)) {
        return post ? 1 : -1;
      }
    }
 else     if (levelDepth1 > levelDepth2) {
      m1=m1.getParentMember();
      if (equals(m1,m2)) {
        return post ? -1 : 1;
      }
    }
 else {
      Member prev1=m1, prev2=m2;
      m1=m1.getParentMember();
      m2=m2.getParentMember();
      if (equals(m1,m2)) {
        return FunUtil.compareValues(prev1.getCaption(),prev2.getCaption());
      }
    }
  }
}