Program: 146724
Project: 146724
Buggy source:
/** 
 * translate an xpath path reference into a TreeReference TreeReferences only support a subset of true xpath paths; restrictions are: simple child name tests 'child::name', '.', and '..' allowed only no predicates all '..' steps must come before anything else
 */
public TreeReference getReference(boolean allowPredicates) throws XPathUnsupportedException {
  TreeReference ref=new TreeReference();
  boolean parentsAllowed;
switch (init_context) {
case XPathPathExpr.INIT_CONTEXT_ROOT:
    ref.setRefLevel(TreeReference.REF_ABSOLUTE);
  parentsAllowed=false;
break;
case XPathPathExpr.INIT_CONTEXT_RELATIVE:
ref.setRefLevel(0);
parentsAllowed=true;
break;
case XPathPathExpr.INIT_CONTEXT_EXPR:
if (this.filtExpr.x != null && this.filtExpr.x instanceof XPathFuncExpr) {
XPathFuncExpr func=(XPathFuncExpr)(this.filtExpr.x);
if (func.id.toString().equals("String_Node_Str")) {
ref.setRefLevel(TreeReference.REF_ABSOLUTE);
parentsAllowed=false;
if (func.args.length != 1) {
throw new XPathUnsupportedException("String_Node_Str" + func.args.length + "String_Node_Str");
}
if (!(func.args[0] instanceof XPathStringLiteral)) {
throw new XPathUnsupportedException("String_Node_Str");
}
XPathStringLiteral strLit=(XPathStringLiteral)(func.args[0]);
ref.setInstanceName(strLit.s);
}
 else if (func.id.toString().equals("String_Node_Str")) {
parentsAllowed=true;
ref.setContext(TreeReference.CONTEXT_ORIGINAL);
}
 else {
throw new XPathUnsupportedException("String_Node_Str");
}
}
 else {
throw new XPathUnsupportedException("String_Node_Str");
}
break;
default :
throw new XPathUnsupportedException("String_Node_Str");
}
for (int i=0; i < steps.length; i++) {
XPathStep step=steps[i];
if (step.axis == XPathStep.AXIS_SELF) {
if (step.test != XPathStep.TEST_TYPE_NODE) {
throw new XPathUnsupportedException("String_Node_Str");
}
}
 else if (step.axis == XPathStep.AXIS_PARENT) {
if (!parentsAllowed || step.test != XPathStep.TEST_TYPE_NODE) {
throw new XPathUnsupportedException("String_Node_Str");
}
 else {
ref.incrementRefLevel();
}
}
 else if (step.axis == XPathStep.AXIS_ATTRIBUTE) {
if (step.test == XPathStep.TEST_NAME) {
ref.add(step.name.toString(),TreeReference.INDEX_ATTRIBUTE);
parentsAllowed=false;
}
 else {
throw new XPathUnsupportedException("String_Node_Str");
}
}
 else if (step.axis == XPathStep.AXIS_CHILD) {
if (step.test == XPathStep.TEST_NAME) {
ref.add(step.name.toString(),TreeReference.INDEX_UNBOUND);
parentsAllowed=false;
}
 else if (step.test == XPathStep.TEST_NAME_WILDCARD) {
ref.add(TreeReference.NAME_WILDCARD,TreeReference.INDEX_UNBOUND);
parentsAllowed=false;
}
 else {
throw new XPathUnsupportedException("String_Node_Str");
}
}
 else {
throw new XPathUnsupportedException("String_Node_Str");
}
if (step.predicates.length > 0) {
int refLevel=ref.getRefLevel();
Vector<XPathExpression> v=new Vector<XPathExpression>();
for (int j=0; j < step.predicates.length; j++) {
v.addElement(step.predicates[j]);
}
ref.addPredicate(i,v);
}
}
return ref;
}

Fixed version (ground truth):
/** 
 * Translate an xpath path reference into a TreeReference TreeReferences only support a subset of xpath paths: - only simple child name tests 'child::name', '.', and '..' allowed. - '../' steps must come before anything else
 * @param allowPredicates Is deprecated! Don't use this.
 * @return a reference built from this path expression
 */
public TreeReference getReference(boolean allowPredicates) throws XPathUnsupportedException {
  TreeReference ref=new TreeReference();
  boolean parentsAllowed;
switch (init_context) {
case XPathPathExpr.INIT_CONTEXT_ROOT:
    ref.setRefLevel(TreeReference.REF_ABSOLUTE);
  parentsAllowed=false;
break;
case XPathPathExpr.INIT_CONTEXT_RELATIVE:
ref.setRefLevel(0);
parentsAllowed=true;
break;
case XPathPathExpr.INIT_CONTEXT_EXPR:
if (this.filtExpr.x != null && this.filtExpr.x instanceof XPathFuncExpr) {
XPathFuncExpr func=(XPathFuncExpr)(this.filtExpr.x);
if (func.id.toString().equals("String_Node_Str")) {
ref.setRefLevel(TreeReference.REF_ABSOLUTE);
parentsAllowed=false;
if (func.args.length != 1) {
throw new XPathUnsupportedException("String_Node_Str" + func.args.length + "String_Node_Str");
}
if (!(func.args[0] instanceof XPathStringLiteral)) {
throw new XPathUnsupportedException("String_Node_Str");
}
XPathStringLiteral strLit=(XPathStringLiteral)(func.args[0]);
ref.setInstanceName(strLit.s);
}
 else if (func.id.toString().equals("String_Node_Str")) {
parentsAllowed=true;
ref.setContext(TreeReference.CONTEXT_ORIGINAL);
}
 else {
throw new XPathUnsupportedException("String_Node_Str");
}
}
 else {
throw new XPathUnsupportedException("String_Node_Str");
}
break;
default :
throw new XPathUnsupportedException("String_Node_Str");
}
final String otherStepMessage="String_Node_Str";
for (XPathStep step : steps) {
if (step.axis == XPathStep.AXIS_SELF) {
if (step.test != XPathStep.TEST_TYPE_NODE) {
throw new XPathUnsupportedException(otherStepMessage);
}
}
 else if (step.axis == XPathStep.AXIS_PARENT) {
if (!parentsAllowed || step.test != XPathStep.TEST_TYPE_NODE) {
throw new XPathUnsupportedException(otherStepMessage);
}
 else {
ref.incrementRefLevel();
}
}
 else if (step.axis == XPathStep.AXIS_ATTRIBUTE) {
if (step.test == XPathStep.TEST_NAME) {
ref.add(step.name.toString(),TreeReference.INDEX_ATTRIBUTE);
parentsAllowed=false;
}
 else {
throw new XPathUnsupportedException("String_Node_Str");
}
}
 else if (step.axis == XPathStep.AXIS_CHILD) {
if (step.test == XPathStep.TEST_NAME) {
ref.add(step.name.toString(),TreeReference.INDEX_UNBOUND);
parentsAllowed=false;
}
 else if (step.test == XPathStep.TEST_NAME_WILDCARD) {
ref.add(TreeReference.NAME_WILDCARD,TreeReference.INDEX_UNBOUND);
parentsAllowed=false;
}
 else {
throw new XPathUnsupportedException(otherStepMessage);
}
}
 else {
throw new XPathUnsupportedException(otherStepMessage);
}
if (step.predicates.length > 0) {
int refLevel=ref.getRefLevel();
Vector<XPathExpression> v=new Vector<XPathExpression>();
for (int j=0; j < step.predicates.length; j++) {
v.addElement(step.predicates[j]);
}
ref.addPredicate(ref.size() - 1,v);
}
}
return ref;
}