Program: 51171
Project: 51171
Buggy source:
/** 
 * Resolves a name such as '[Products]&#46;[Product Department]&#46;[Produce]' by resolving the components ('Products', and so forth) one at a time.
 * @param schemaReader Schema reader, supplies access-control context
 * @param parent Parent element to search in
 * @param names Exploded compound name, such as {"Products","Product Department", "Produce"}
 * @param failIfNotFound If the element is not found, determines whetherto return null or throw an error
 * @param category Type of returned element, a {@link Category} value;{@link Category#Unknown} if it doesn't matter.
 * @pre parent != null
 * @post !(failIfNotFound && return == null)
 * @see #parseIdentifier(String)
 */
public static OlapElement lookupCompound(SchemaReader schemaReader,OlapElement parent,List<Id.Segment> names,boolean failIfNotFound,int category,MatchType matchType){
  Util.assertPrecondition(parent != null,"String_Node_Str");
  if (LOGGER.isDebugEnabled()) {
    StringBuilder buf=new StringBuilder(64);
    buf.append("String_Node_Str");
    buf.append("String_Node_Str");
    buf.append(parent.getName());
    buf.append("String_Node_Str");
    buf.append(Category.instance.getName(category));
    buf.append("String_Node_Str");
    quoteMdxIdentifier(names,buf);
    LOGGER.debug(buf.toString());
  }
switch (category) {
case Category.Member:
case Category.Unknown:
    Member member=schemaReader.getCalculatedMember(names);
  if (member != null) {
    return member;
  }
}
switch (category) {
case Category.Set:
case Category.Unknown:
NamedSet namedSet=schemaReader.getNamedSet(names);
if (namedSet != null) {
return namedSet;
}
}
for (int i=0; i < names.size(); i++) {
Id.Segment name=names.get(i);
OlapElement child=schemaReader.getElementChild(parent,name,matchType);
if (child != null && matchType != MatchType.EXACT && !Util.equalName(child.getName(),name.name)) {
Util.assertPrecondition(child instanceof Member);
Member bestChild=(Member)child;
for (int j=i + 1; j < names.size(); j++) {
List<Member> childrenList=schemaReader.getMemberChildren(bestChild);
FunUtil.hierarchize(childrenList,false);
if (matchType == MatchType.AFTER) {
  bestChild=childrenList.get(0);
}
 else {
  bestChild=childrenList.get(childrenList.size() - 1);
}
if (bestChild == null) {
  child=null;
  break;
}
}
parent=bestChild;
break;
}
if (child == null) {
if (LOGGER.isDebugEnabled()) {
StringBuilder buf=new StringBuilder(64);
buf.append("String_Node_Str");
buf.append("String_Node_Str");
buf.append(parent.getName());
buf.append("String_Node_Str");
buf.append(name);
LOGGER.debug(buf.toString());
}
if (!failIfNotFound) {
return null;
}
 else if (category == Category.Member) {
throw MondrianResource.instance().MemberNotFound.ex(quoteMdxIdentifier(names));
}
 else {
throw MondrianResource.instance().MdxChildObjectNotFound.ex(name.name,parent.getQualifiedName());
}
}
parent=child;
}
if (LOGGER.isDebugEnabled()) {
StringBuilder buf=new StringBuilder(64);
buf.append("String_Node_Str");
buf.append("String_Node_Str");
buf.append(parent.getName());
buf.append("String_Node_Str");
buf.append(parent.getClass().getName());
LOGGER.debug(buf.toString());
}
switch (category) {
case Category.Dimension:
if (parent instanceof Dimension) {
return parent;
}
 else if (parent instanceof Hierarchy) {
return parent.getDimension();
}
 else if (failIfNotFound) {
throw Util.newError("String_Node_Str" + implode(names) + "String_Node_Str");
}
 else {
return null;
}
case Category.Hierarchy:
if (parent instanceof Hierarchy) {
return parent;
}
 else if (parent instanceof Dimension) {
return parent.getHierarchy();
}
 else if (failIfNotFound) {
throw Util.newError("String_Node_Str" + implode(names) + "String_Node_Str");
}
 else {
return null;
}
case Category.Level:
if (parent instanceof Level) {
return parent;
}
 else if (failIfNotFound) {
throw Util.newError("String_Node_Str" + implode(names) + "String_Node_Str");
}
 else {
return null;
}
case Category.Member:
if (parent instanceof Member) {
return parent;
}
 else if (failIfNotFound) {
throw MondrianResource.instance().MdxCantFindMember.ex(implode(names));
}
 else {
return null;
}
case Category.Unknown:
assertPostcondition(parent != null,"String_Node_Str");
return parent;
default :
throw newInternal("String_Node_Str" + category);
}
}

Fixed version (ground truth):
/** 
 * Resolves a name such as '[Products]&#46;[Product Department]&#46;[Produce]' by resolving the components ('Products', and so forth) one at a time.
 * @param schemaReader Schema reader, supplies access-control context
 * @param parent Parent element to search in
 * @param names Exploded compound name, such as {"Products","Product Department", "Produce"}
 * @param failIfNotFound If the element is not found, determines whetherto return null or throw an error
 * @param category Type of returned element, a {@link Category} value;{@link Category#Unknown} if it doesn't matter.
 * @pre parent != null
 * @post !(failIfNotFound && return == null)
 * @see #parseIdentifier(String)
 */
public static OlapElement lookupCompound(SchemaReader schemaReader,OlapElement parent,List<Id.Segment> names,boolean failIfNotFound,int category,MatchType matchType){
  Util.assertPrecondition(parent != null,"String_Node_Str");
  if (LOGGER.isDebugEnabled()) {
    StringBuilder buf=new StringBuilder(64);
    buf.append("String_Node_Str");
    buf.append("String_Node_Str");
    buf.append(parent.getName());
    buf.append("String_Node_Str");
    buf.append(Category.instance.getName(category));
    buf.append("String_Node_Str");
    quoteMdxIdentifier(names,buf);
    LOGGER.debug(buf.toString());
  }
switch (category) {
case Category.Member:
case Category.Unknown:
    Member member=schemaReader.getCalculatedMember(names);
  if (member != null) {
    return member;
  }
}
switch (category) {
case Category.Set:
case Category.Unknown:
NamedSet namedSet=schemaReader.getNamedSet(names);
if (namedSet != null) {
return namedSet;
}
}
for (int i=0; i < names.size(); i++) {
Id.Segment name=names.get(i);
OlapElement child=schemaReader.getElementChild(parent,name,matchType);
if (child != null && !matchType.isExact() && !Util.equalName(child.getName(),name.name)) {
Util.assertPrecondition(child instanceof Member);
Member bestChild=(Member)child;
for (int j=i + 1; j < names.size(); j++) {
List<Member> childrenList=schemaReader.getMemberChildren(bestChild);
FunUtil.hierarchize(childrenList,false);
if (matchType == MatchType.AFTER) {
  bestChild=childrenList.get(0);
}
 else {
  bestChild=childrenList.get(childrenList.size() - 1);
}
if (bestChild == null) {
  child=null;
  break;
}
}
parent=bestChild;
break;
}
if (child == null) {
if (LOGGER.isDebugEnabled()) {
StringBuilder buf=new StringBuilder(64);
buf.append("String_Node_Str");
buf.append("String_Node_Str");
buf.append(parent.getName());
buf.append("String_Node_Str");
buf.append(name);
LOGGER.debug(buf.toString());
}
if (!failIfNotFound) {
return null;
}
 else if (category == Category.Member) {
throw MondrianResource.instance().MemberNotFound.ex(quoteMdxIdentifier(names));
}
 else {
throw MondrianResource.instance().MdxChildObjectNotFound.ex(name.name,parent.getQualifiedName());
}
}
parent=child;
}
if (LOGGER.isDebugEnabled()) {
StringBuilder buf=new StringBuilder(64);
buf.append("String_Node_Str");
buf.append("String_Node_Str");
buf.append(parent.getName());
buf.append("String_Node_Str");
buf.append(parent.getClass().getName());
LOGGER.debug(buf.toString());
}
switch (category) {
case Category.Dimension:
if (parent instanceof Dimension) {
return parent;
}
 else if (parent instanceof Hierarchy) {
return parent.getDimension();
}
 else if (failIfNotFound) {
throw Util.newError("String_Node_Str" + implode(names) + "String_Node_Str");
}
 else {
return null;
}
case Category.Hierarchy:
if (parent instanceof Hierarchy) {
return parent;
}
 else if (parent instanceof Dimension) {
return parent.getHierarchy();
}
 else if (failIfNotFound) {
throw Util.newError("String_Node_Str" + implode(names) + "String_Node_Str");
}
 else {
return null;
}
case Category.Level:
if (parent instanceof Level) {
return parent;
}
 else if (failIfNotFound) {
throw Util.newError("String_Node_Str" + implode(names) + "String_Node_Str");
}
 else {
return null;
}
case Category.Member:
if (parent instanceof Member) {
return parent;
}
 else if (failIfNotFound) {
throw MondrianResource.instance().MdxCantFindMember.ex(implode(names));
}
 else {
return null;
}
case Category.Unknown:
assertPostcondition(parent != null,"String_Node_Str");
return parent;
default :
throw newInternal("String_Node_Str" + category);
}
}