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: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to