sandip-db commented on code in PR #44287:
URL: https://github.com/apache/spark/pull/44287#discussion_r1421887605
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParser.scala:
##########
@@ -591,17 +593,24 @@ class XmlTokenizer(
* @return whether it reads successfully
*/
def next(): Option[String] = {
- if (readUntilStartElement()) {
- try {
+ try {
+ if (readUntilStartElement()) {
buffer.append(currentStartTag)
// Don't check whether the end element was found. Even if not, return
everything
// that was read, which will invariably cause a parse error later
readUntilEndElement(currentStartTag.endsWith(">"))
- return Some(buffer.toString())
- } finally {
+ val str = buffer.toString()
buffer = new StringBuilder()
+ return Some(str)
}
+ } catch {
+ case e: Throwable =>
+ reader.close()
+ reader = null
+ throw e
}
+ reader.close()
+ reader = null
Review Comment:
`finally` will close the reader after the first return. It needs to be
closed when there are no more records left.
Setting to null is just JVM GC hint. Not absolutely necessary.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]