Program: 28617
Project: 28617
Buggy source:
/** 
 * PROPFIND Method.
 */
protected void doPropfind(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
  if (!listings) {
    StringBuilder methodsAllowed=determineMethodsAllowed(resources,req);
    resp.addHeader("String_Node_Str",methodsAllowed.toString());
    resp.sendError(WebdavStatus.SC_METHOD_NOT_ALLOWED);
    return;
  }
  String path=getRelativePath(req);
  if (path.endsWith("String_Node_Str"))   path=path.substring(0,path.length() - 1);
  if (path.toUpperCase(Locale.ENGLISH).startsWith("String_Node_Str") || path.toUpperCase(Locale.ENGLISH).startsWith("String_Node_Str")) {
    resp.sendError(WebdavStatus.SC_FORBIDDEN);
    return;
  }
  Vector<String> properties=null;
  int depth=INFINITY;
  int type=FIND_ALL_PROP;
  String depthStr=req.getHeader("String_Node_Str");
  if (depthStr == null) {
    depth=INFINITY;
  }
 else {
    if ("String_Node_Str".equals(depthStr)) {
      depth=0;
    }
 else     if ("String_Node_Str".equals(depthStr)) {
      depth=1;
    }
 else     if ("String_Node_Str".equals(depthStr)) {
      depth=INFINITY;
    }
  }
  Node propNode=null;
  if (req.getInputStream().available() > 0) {
    DocumentBuilder documentBuilder=getDocumentBuilder();
    try {
      Document document=documentBuilder.parse(new InputSource(req.getInputStream()));
      Element rootElement=document.getDocumentElement();
      NodeList childList=rootElement.getChildNodes();
      for (int i=0; i < childList.getLength(); i++) {
        Node currentNode=childList.item(i);
switch (currentNode.getNodeType()) {
case Node.TEXT_NODE:
          break;
case Node.ELEMENT_NODE:
        if (currentNode.getNodeName().endsWith("String_Node_Str")) {
          type=FIND_BY_PROPERTY;
          propNode=currentNode;
        }
      if (currentNode.getNodeName().endsWith("String_Node_Str")) {
        type=FIND_PROPERTY_NAMES;
      }
    if (currentNode.getNodeName().endsWith("String_Node_Str")) {
      type=FIND_ALL_PROP;
    }
  break;
default :
break;
}
}
}
 catch (SAXException e) {
}
catch (IOException e) {
}
}
if (type == FIND_BY_PROPERTY) {
properties=new Vector<String>();
NodeList childList=propNode.getChildNodes();
for (int i=0; i < childList.getLength(); i++) {
Node currentNode=childList.item(i);
switch (currentNode.getNodeType()) {
case Node.TEXT_NODE:
break;
case Node.ELEMENT_NODE:
String nodeName=currentNode.getNodeName();
String propertyName=null;
if (nodeName.indexOf(':') != -1) {
propertyName=nodeName.substring(nodeName.indexOf(':') + 1);
}
 else {
propertyName=nodeName;
}
properties.addElement(propertyName);
break;
default :
break;
}
}
}
boolean exists=true;
Object object=null;
try {
object=resources.lookup(path);
}
 catch (NamingException e) {
exists=false;
int slash=path.lastIndexOf('/');
if (slash != -1) {
String parentPath=path.substring(0,slash);
Vector<String> currentLockNullResources=lockNullResources.get(parentPath);
if (currentLockNullResources != null) {
Enumeration<String> lockNullResourcesList=currentLockNullResources.elements();
while (lockNullResourcesList.hasMoreElements()) {
String lockNullPath=lockNullResourcesList.nextElement();
if (lockNullPath.equals(path)) {
resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
resp.setContentType("String_Node_Str");
XMLWriter generatedXML=new XMLWriter(resp.getWriter());
generatedXML.writeXMLHeader();
generatedXML.writeElement(null,"String_Node_Str" + generateNamespaceDeclarations(),XMLWriter.OPENING);
parseLockNullProperties(req,generatedXML,lockNullPath,type,properties);
generatedXML.writeElement(null,"String_Node_Str",XMLWriter.CLOSING);
generatedXML.sendData();
return;
}
}
}
}
}
if (!exists) {
HtmlEntityEncoder htmlEntityEncoder=new HtmlEntityEncoder();
resp.sendError(HttpServletResponse.SC_NOT_FOUND,htmlEntityEncoder.encode(path));
return;
}
resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
resp.setContentType("String_Node_Str");
XMLWriter generatedXML=new XMLWriter(resp.getWriter());
generatedXML.writeXMLHeader();
generatedXML.writeElement(null,"String_Node_Str" + generateNamespaceDeclarations(),XMLWriter.OPENING);
if (depth == 0) {
parseProperties(req,generatedXML,path,type,properties);
}
 else {
Stack<String> stack=new Stack<String>();
stack.push(path);
Stack<String> stackBelow=new Stack<String>();
while (!stack.isEmpty() && depth >= 0) {
String currentPath=stack.pop();
parseProperties(req,generatedXML,currentPath,type,properties);
try {
object=resources.lookup(currentPath);
}
 catch (NamingException e) {
continue;
}
if (object instanceof DirContext && depth > 0) {
try {
NamingEnumeration<NameClassPair> enumeration=resources.list(currentPath);
while (enumeration.hasMoreElements()) {
NameClassPair ncPair=enumeration.nextElement();
String newPath=currentPath;
if (!newPath.endsWith("String_Node_Str")) newPath+="String_Node_Str";
newPath+=ncPair.getName();
stackBelow.push(newPath);
}
}
 catch (NamingException e) {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,path);
return;
}
String lockPath=currentPath;
if (lockPath.endsWith("String_Node_Str")) lockPath=lockPath.substring(0,lockPath.length() - 1);
Vector<String> currentLockNullResources=lockNullResources.get(lockPath);
if (currentLockNullResources != null) {
Enumeration<String> lockNullResourcesList=currentLockNullResources.elements();
while (lockNullResourcesList.hasMoreElements()) {
String lockNullPath=lockNullResourcesList.nextElement();
parseLockNullProperties(req,generatedXML,lockNullPath,type,properties);
}
}
}
if (stack.isEmpty()) {
depth--;
stack=stackBelow;
stackBelow=new Stack<String>();
}
generatedXML.sendData();
}
}
generatedXML.writeElement(null,"String_Node_Str",XMLWriter.CLOSING);
generatedXML.sendData();
}

Fixed version (ground truth):
/** 
 * PROPFIND Method.
 */
protected void doPropfind(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
  if (!listings) {
    StringBuilder methodsAllowed=determineMethodsAllowed(resources,req);
    resp.addHeader("String_Node_Str",methodsAllowed.toString());
    resp.sendError(WebdavStatus.SC_METHOD_NOT_ALLOWED);
    return;
  }
  String path=getRelativePath(req);
  if (path.endsWith("String_Node_Str"))   path=path.substring(0,path.length() - 1);
  if (path.toUpperCase(Locale.ENGLISH).startsWith("String_Node_Str") || path.toUpperCase(Locale.ENGLISH).startsWith("String_Node_Str")) {
    resp.sendError(WebdavStatus.SC_FORBIDDEN);
    return;
  }
  Vector<String> properties=null;
  int depth=INFINITY;
  int type=FIND_ALL_PROP;
  String depthStr=req.getHeader("String_Node_Str");
  if (depthStr == null) {
    depth=INFINITY;
  }
 else {
    if ("String_Node_Str".equals(depthStr)) {
      depth=0;
    }
 else     if ("String_Node_Str".equals(depthStr)) {
      depth=1;
    }
 else     if ("String_Node_Str".equals(depthStr)) {
      depth=INFINITY;
    }
  }
  Node propNode=null;
  if (req.getInputStream().available() > 0) {
    DocumentBuilder documentBuilder=getDocumentBuilder();
    try {
      Document document=documentBuilder.parse(new InputSource(req.getInputStream()));
      Element rootElement=document.getDocumentElement();
      NodeList childList=rootElement.getChildNodes();
      for (int i=0; i < childList.getLength(); i++) {
        Node currentNode=childList.item(i);
switch (currentNode.getNodeType()) {
case Node.TEXT_NODE:
          break;
case Node.ELEMENT_NODE:
        if (currentNode.getNodeName().endsWith("String_Node_Str")) {
          type=FIND_BY_PROPERTY;
          propNode=currentNode;
        }
      if (currentNode.getNodeName().endsWith("String_Node_Str")) {
        type=FIND_PROPERTY_NAMES;
      }
    if (currentNode.getNodeName().endsWith("String_Node_Str")) {
      type=FIND_ALL_PROP;
    }
  break;
default :
break;
}
}
}
 catch (SAXException e) {
}
catch (IOException e) {
}
}
if (type == FIND_BY_PROPERTY) {
properties=new Vector<String>();
NodeList childList=propNode.getChildNodes();
for (int i=0; i < childList.getLength(); i++) {
Node currentNode=childList.item(i);
switch (currentNode.getNodeType()) {
case Node.TEXT_NODE:
break;
case Node.ELEMENT_NODE:
String nodeName=currentNode.getNodeName();
String propertyName=null;
if (nodeName.indexOf(':') != -1) {
propertyName=nodeName.substring(nodeName.indexOf(':') + 1);
}
 else {
propertyName=nodeName;
}
properties.addElement(propertyName);
break;
default :
break;
}
}
}
boolean exists=true;
Object object=null;
try {
object=resources.lookup(path);
}
 catch (NamingException e) {
exists=false;
int slash=path.lastIndexOf('/');
if (slash != -1) {
String parentPath=path.substring(0,slash);
Vector<String> currentLockNullResources=lockNullResources.get(parentPath);
if (currentLockNullResources != null) {
Enumeration<String> lockNullResourcesList=currentLockNullResources.elements();
while (lockNullResourcesList.hasMoreElements()) {
String lockNullPath=lockNullResourcesList.nextElement();
if (lockNullPath.equals(path)) {
resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
resp.setContentType("String_Node_Str");
XMLWriter generatedXML=new XMLWriter(resp.getWriter());
generatedXML.writeXMLHeader();
generatedXML.writeElement(null,"String_Node_Str" + generateNamespaceDeclarations(),XMLWriter.OPENING);
parseLockNullProperties(req,generatedXML,lockNullPath,type,properties);
generatedXML.writeElement(null,"String_Node_Str",XMLWriter.CLOSING);
generatedXML.sendData();
return;
}
}
}
}
}
if (!exists) {
resp.sendError(HttpServletResponse.SC_NOT_FOUND,path);
return;
}
resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
resp.setContentType("String_Node_Str");
XMLWriter generatedXML=new XMLWriter(resp.getWriter());
generatedXML.writeXMLHeader();
generatedXML.writeElement(null,"String_Node_Str" + generateNamespaceDeclarations(),XMLWriter.OPENING);
if (depth == 0) {
parseProperties(req,generatedXML,path,type,properties);
}
 else {
Stack<String> stack=new Stack<String>();
stack.push(path);
Stack<String> stackBelow=new Stack<String>();
while (!stack.isEmpty() && depth >= 0) {
String currentPath=stack.pop();
parseProperties(req,generatedXML,currentPath,type,properties);
try {
object=resources.lookup(currentPath);
}
 catch (NamingException e) {
continue;
}
if (object instanceof DirContext && depth > 0) {
try {
NamingEnumeration<NameClassPair> enumeration=resources.list(currentPath);
while (enumeration.hasMoreElements()) {
NameClassPair ncPair=enumeration.nextElement();
String newPath=currentPath;
if (!newPath.endsWith("String_Node_Str")) newPath+="String_Node_Str";
newPath+=ncPair.getName();
stackBelow.push(newPath);
}
}
 catch (NamingException e) {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,path);
return;
}
String lockPath=currentPath;
if (lockPath.endsWith("String_Node_Str")) lockPath=lockPath.substring(0,lockPath.length() - 1);
Vector<String> currentLockNullResources=lockNullResources.get(lockPath);
if (currentLockNullResources != null) {
Enumeration<String> lockNullResourcesList=currentLockNullResources.elements();
while (lockNullResourcesList.hasMoreElements()) {
String lockNullPath=lockNullResourcesList.nextElement();
parseLockNullProperties(req,generatedXML,lockNullPath,type,properties);
}
}
}
if (stack.isEmpty()) {
depth--;
stack=stackBelow;
stackBelow=new Stack<String>();
}
generatedXML.sendData();
}
}
generatedXML.writeElement(null,"String_Node_Str",XMLWriter.CLOSING);
generatedXML.sendData();
}