From 9344b2526bd7d038f346178cd46e8247fa6272ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=90=A6=E6=B6=9B?= Date: Wed, 8 Mar 2023 16:12:28 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90fix=20sonar=E3=80=91XmlUtils=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jero/modules/cas/util/XmlUtils.java | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/cas/util/XmlUtils.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/cas/util/XmlUtils.java index 4b17bfdf..3778a0c9 100644 --- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/cas/util/XmlUtils.java +++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/cas/util/XmlUtils.java @@ -1,19 +1,8 @@ package com.jero.modules.cas.util; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import javax.xml.XMLConstants; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; +import com.jero.common.exception.JeroBootException; +import lombok.extern.slf4j.Slf4j; import org.w3c.dom.Document; import org.xml.sax.Attributes; import org.xml.sax.InputSource; @@ -21,7 +10,13 @@ import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; -import lombok.extern.slf4j.Slf4j; +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import java.io.StringReader; +import java.util.*; /** * 解析cas,ST验证后的xml @@ -53,7 +48,7 @@ public final class XmlUtils { try { return factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml))); } catch (Exception e) { - throw new RuntimeException("XML parsing error: " + e); + throw new JeroBootException("XML parsing error: " + e); } } @@ -70,7 +65,7 @@ public final class XmlUtils { reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); return reader; } catch (final Exception e) { - throw new RuntimeException("Unable to create XMLReader", e); + throw new JeroBootException("Unable to create XMLReader", e); } } @@ -126,7 +121,7 @@ public final class XmlUtils { reader.parse(new InputSource(new StringReader(xmlAsString))); } catch (final Exception e) { log.error(e.getMessage(), e); - return null; + return Collections.emptyList(); } return elements;