--- old/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java 2019-09-27 10:29:19.508677916 +0200 +++ new/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java 2019-09-27 10:29:19.413677576 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -824,7 +824,7 @@ // We've seen a new Reader. // Push it on the stack so we can close it later. - //fOwnReaders.add(reader); + fReaderStack.push(reader); // push entity on stack if (fCurrentEntity != null) { @@ -1347,16 +1347,21 @@ (fEntityStack.empty() ? null : fEntityStack.elementAt(0)); } + // A stack containing all the open readers + protected Stack fReaderStack = new Stack<>(); /** * 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 - **/ + // close all readers + while (!fReaderStack.isEmpty()) { + try { + (fReaderStack.pop()).close(); + } catch (IOException e) { + // ignore + } + } } public void endEntity() throws IOException, XNIException { @@ -1390,6 +1395,13 @@ } } + // 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){