From 19e7c91379fbcd79b48353c845aed1d344c8229e Mon Sep 17 00:00:00 2001 From: RealTake Date: Sat, 22 Nov 2025 21:29:43 +0900 Subject: [PATCH] refactor(StaxStreamXMLReader): remove duplicate ifs --- .../util/xml/StaxStreamXMLReader.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java b/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java index b4e214087184..8c7a9ddccde0 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java +++ b/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java @@ -28,6 +28,7 @@ import org.xml.sax.SAXException; import org.xml.sax.ext.Locator2; import org.xml.sax.helpers.AttributesImpl; +import org.xml.sax.ext.LexicalHandler; import org.springframework.util.StringUtils; @@ -227,22 +228,21 @@ private void handleComment() throws SAXException { } private void handleDtd() throws SAXException { - if (getLexicalHandler() != null) { - Location location = this.reader.getLocation(); - getLexicalHandler().startDTD(null, location.getPublicId(), location.getSystemId()); - } - if (getLexicalHandler() != null) { - getLexicalHandler().endDTD(); - } + LexicalHandler lexical = getLexicalHandler(); + if (lexical == null) return; + + Location loc = this.reader.getLocation(); + lexical.startDTD(null, loc.getPublicId(), loc.getSystemId()); + lexical.endDTD(); } private void handleEntityReference() throws SAXException { - if (getLexicalHandler() != null) { - getLexicalHandler().startEntity(this.reader.getLocalName()); - } - if (getLexicalHandler() != null) { - getLexicalHandler().endEntity(this.reader.getLocalName()); - } + LexicalHandler lexical = getLexicalHandler(); + if (lexical == null) return; + + String name = this.reader.getLocalName(); + lexical.startEntity(name); + lexical.endEntity(name); } private void handleEndDocument() throws SAXException { @@ -289,4 +289,4 @@ private Attributes getAttributes() { return attributes; } -} +} \ No newline at end of file