You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by bu...@apache.org on 2003/08/13 16:39:03 UTC
DO NOT REPLY [Bug 22381] New: -
When an exception occurs during parsing with SAX, the file reference is not released
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22381>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22381
When an exception occurs during parsing with SAX, the file reference is not released
Summary: When an exception occurs during parsing with SAX, the
file reference is not released
Product: Xerces2-J
Version: 2.4.0
Platform: All
OS/Version: All
Status: NEW
Severity: Major
Priority: Other
Component: SAX
AssignedTo: xerces-j-dev@xml.apache.org
ReportedBy: routar@ideorlando.org
I posted this to the user list and got a workaround but I still think it is a
bug. Basically I have a content handler that throws an exception when it
encounters the start element of an XML file, this is done to abort processing.
After the exception is thrown I then try to access the file for a delete
operation and the delete always fails. So it looks like SAXParser is not
closing streams when an exception occurs.
Code is as follows:
Content Handler:
public class TestContentHandler extends DefaultHandler {
/**
* Called by the SAX parser at the start of an element.
* @param uri of the element
* @param localName of the element
* @param qName of the element
* @param attributes of the element
* @throws SAXException if a error occurs during parsing
* @build 8
*/
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
throw new SAXException("Test");
}
}
Code:
File in = new File(path);
try {
String uri = "file:" + in.getAbsolutePath();
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader reader = sp.getXMLReader();
reader.setContentHandler(new TestContentHandler());
reader.parse(uri);
}
catch (Exception e) {
System.out.println(in.delete());
//assertTrue (e.toString(), false);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org