From 0b4a5b000f28a860b30c049e7212f2b7f39a502a Mon Sep 17 00:00:00 2001 From: Beny Date: Tue, 6 Oct 2020 00:28:45 +0200 Subject: [PATCH] Better error handling in figureData parser --- .../users/clothingvalidation/Figuredata.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/users/clothingvalidation/Figuredata.java b/src/main/java/com/eu/habbo/habbohotel/users/clothingvalidation/Figuredata.java index 11eadc9f..c68eedc5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/clothingvalidation/Figuredata.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/clothingvalidation/Figuredata.java @@ -29,7 +29,7 @@ public class Figuredata { * @throws IOException * @throws SAXException */ - public void parseXML(String uri) throws ParserConfigurationException, IOException, SAXException { + public void parseXML(String uri) throws Exception, ParserConfigurationException, IOException, SAXException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringElementContentWhitespace(true); @@ -37,6 +37,15 @@ public class Figuredata { Document document = builder.parse(uri); Element rootElement = document.getDocumentElement(); + + if(!rootElement.getTagName().equalsIgnoreCase("figuredata")) { + throw new Exception("The passed file is not in figuredata format. Received " + document.toString()); + } + + if(document.getElementsByTagName("colors") == null || document.getElementsByTagName("sets") == null) { + throw new Exception("The passed file is not in figuredata format. Received " + document.toString()); + } + NodeList palettesList = document.getElementsByTagName("colors").item(0).getChildNodes(); NodeList settypesList = document.getElementsByTagName("sets").item(0).getChildNodes();