< prev index next >
src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java
Print this page
@ rev 1984 : 8213734: SAXParser.parse(File, ..) does not close resources when Exception occurs.
| Reviewed-by: lancea
~
*** 822,832 ****
//reader = new OneCharReader(reader);
}
// We've seen a new Reader.
// Push it on the stack so we can close it later.
! //fOwnReaders.add(reader);
// push entity on stack
if (fCurrentEntity != null) {
fEntityStack.push(fCurrentEntity);
}
--- 822,832 ----
//reader = new OneCharReader(reader);
}
// We've seen a new Reader.
// Push it on the stack so we can close it later.
! fReaderStack.push(reader);
// push entity on stack
if (fCurrentEntity != null) {
fEntityStack.push(fCurrentEntity);
}
*** 1345,1364 ****
public Entity.ScannedEntity getTopLevelEntity() {
return (Entity.ScannedEntity)
(fEntityStack.empty() ? null : fEntityStack.elementAt(0));
}
/**
* Close all opened InputStreams and Readers opened by this parser.
*/
public void closeReaders() {
! /** this call actually does nothing, readers are closed in the endEntity method
! * through the current entity.
! * The change seems to have happened during the jdk6 development with the
! * addition of StAX
! **/
}
public void endEntity() throws IOException, XNIException {
// call handler
--- 1345,1369 ----
public Entity.ScannedEntity getTopLevelEntity() {
return (Entity.ScannedEntity)
(fEntityStack.empty() ? null : fEntityStack.elementAt(0));
}
+ // A stack containing all the open readers
+ protected Stack<Reader> fReaderStack = new Stack<>();
/**
* Close all opened InputStreams and Readers opened by this parser.
*/
public void closeReaders() {
! // close all readers
! while (!fReaderStack.isEmpty()) {
! try {
! (fReaderStack.pop()).close();
! } catch (IOException e) {
! // ignore
! }
! }
}
public void endEntity() throws IOException, XNIException {
// call handler
*** 1388,1397 ****
--- 1393,1409 ----
}catch(IOException ex){
throw new XNIException(ex);
}
}
+ // REVISIT: We should never encounter underflow if the calls
+ // to startEntity and endEntity are balanced, but guard
+ // against the EmptyStackException for now. -- mrglavas
+ if (!fReaderStack.isEmpty()) {
+ fReaderStack.pop();
+ }
+
if (fEntityHandler != null) {
//so this is the last opened entity, signal it to current fEntityHandler using Augmentation
if(entity == null){
fEntityAugs.removeAllItems();
fEntityAugs.putItem(Constants.LAST_ENTITY, Boolean.TRUE);
< prev index next >