Program: 24689
Project: 24689
Buggy source:
/** 
 * Does the work of locating and loading the source document. Handles fetching a file from a URL, lazy file, or a plain XML file on disk. Also fires up a text query if requested.
 * @param docReq        Tells which document to load, the query toapply, tec.
 * @param transformer   The XSLT transformer that will be used on thedocument.
 * @return              An XML Source object representing the loadeddocument.
 * @throws IOException  If a problem is encountered loading a file or URL
 * @throws SAXException If the document cannot be parsed as valid XML
 * @throws ParserConfigurationException Miscellaneous configurationproblems
 */
protected Source getSourceDoc(DocRequest docReq,Transformer transformer) throws IOException, SAXException, ParserConfigurationException, InvalidDocumentException {
  Templates preFilter=null;
  if (docReq.preFilter != null) {
    try {
      preFilter=stylesheetCache.find(docReq.preFilter);
    }
 catch (    IOException e) {
      throw e;
    }
catch (    SAXException e) {
      throw e;
    }
catch (    Exception e) {
      throw new RuntimeException(e);
    }
  }
  StructuredStore lazyStore=docLocator.getLazyStore(docReq.indexConfig,docReq.indexName,docReq.source,preFilter,docReq.removeDoctypeDecl);
  if (lazyStore == null) {
    if (docReq.query != null)     throw new UnsupportedQueryException();
    if (!docReq.source.startsWith("String_Node_Str")) {
      File srcFile=new File(docReq.source);
      if (!srcFile.isFile() || !srcFile.canRead())       throw new InvalidDocumentException();
    }
    XMLReader xmlReader=IndexUtil.createXMLReader();
    InputSource inSrc=docLocator.getInputSource(docReq.source,docReq.removeDoctypeDecl);
    return new SAXSource(xmlReader,inSrc);
  }
  Source sourceDoc=null;
  Controller controller=(Controller)transformer;
  Configuration config=controller.getConfiguration();
  if (docReq.query != null && docReq.query.query != null) {
    String docKey=IndexUtil.calcDocKey(new File(getRealPath("String_Node_Str")),new File(docReq.indexConfig),docReq.indexName,new File(docReq.source));
    SearchTree tree=new SearchTree(config,docKey,lazyStore);
    tree.search(getQueryProcessor(),docReq.query);
    sourceDoc=tree;
  }
 else {
    LazyTreeBuilder builder=new LazyTreeBuilder(config);
    builder.setNamePool(NamePool.getDefaultNamePool());
    sourceDoc=builder.load(lazyStore);
  }
  ((LazyDocument)sourceDoc).setDebug(true);
  Executable e=controller.getExecutable();
  KeyManager k=e.getKeyManager();
  if (!(k instanceof LazyKeyManager))   e.setKeyManager(new LazyKeyManager(controller.getConfiguration(),k));
  return sourceDoc;
}

Fixed version (ground truth):
/** 
 * Does the work of locating and loading the source document. Handles fetching a file from a URL, lazy file, or a plain XML file on disk. Also fires up a text query if requested.
 * @param docReq        Tells which document to load, the query toapply, tec.
 * @param transformer   The XSLT transformer that will be used on thedocument.
 * @return              An XML Source object representing the loadeddocument.
 * @throws IOException  If a problem is encountered loading a file or URL
 * @throws SAXException If the document cannot be parsed as valid XML
 * @throws ParserConfigurationException Miscellaneous configurationproblems
 */
protected Source getSourceDoc(DocRequest docReq,Transformer transformer) throws IOException, SAXException, ParserConfigurationException, InvalidDocumentException {
  Templates preFilter=null;
  if (docReq.preFilter != null) {
    try {
      preFilter=stylesheetCache.find(docReq.preFilter);
    }
 catch (    IOException e) {
      throw e;
    }
catch (    SAXException e) {
      throw e;
    }
catch (    Exception e) {
      throw new RuntimeException(e);
    }
  }
  StructuredStore lazyStore=docLocator.getLazyStore(docReq.indexConfig,docReq.indexName,docReq.source,preFilter,docReq.removeDoctypeDecl);
  if (lazyStore == null) {
    if (docReq.query != null)     throw new UnsupportedQueryException();
    if (!docReq.source.startsWith("String_Node_Str")) {
      File srcFile=new File(docReq.source);
      if (!srcFile.isFile() || !srcFile.canRead())       throw new InvalidDocumentException();
    }
    XMLReader xmlReader=IndexUtil.createXMLReader();
    InputSource inSrc=docLocator.getInputSource(docReq.source,docReq.removeDoctypeDecl);
    return new SAXSource(xmlReader,inSrc);
  }
  Source sourceDoc=null;
  Controller controller=(Controller)transformer;
  Configuration config=controller.getConfiguration();
  if (docReq.query != null && docReq.query.query != null) {
    String docKey=IndexUtil.calcDocKey(new File(getRealPath("String_Node_Str")),new File(docReq.indexConfig),docReq.indexName,new File(docReq.source));
    SearchTree tree=new SearchTree(config,docKey,lazyStore);
    tree.search(createQueryProcessor(),docReq.query);
    sourceDoc=tree;
  }
 else {
    LazyTreeBuilder builder=new LazyTreeBuilder(config);
    builder.setNamePool(NamePool.getDefaultNamePool());
    sourceDoc=builder.load(lazyStore);
  }
  ((LazyDocument)sourceDoc).setDebug(true);
  Executable e=controller.getExecutable();
  KeyManager k=e.getKeyManager();
  if (!(k instanceof LazyKeyManager))   e.setKeyManager(new LazyKeyManager(controller.getConfiguration(),k));
  return sourceDoc;
}