From 7f0dbe908a05661734a7c0a22e69c868e6f01d51 Mon Sep 17 00:00:00 2001 From: jan-vcapgemini Date: Thu, 10 Aug 2023 12:27:58 +0200 Subject: [PATCH] #1696: fixed JaxbDeserializer replaced try-with-resource InputStream with URL added missing exception --- .../cobigen/impl/config/reader/JaxbDeserializer.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/JaxbDeserializer.java b/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/JaxbDeserializer.java index 41b415e64..849c72755 100644 --- a/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/JaxbDeserializer.java +++ b/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/config/reader/JaxbDeserializer.java @@ -4,11 +4,11 @@ import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; +import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import javax.xml.XMLConstants; -import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; @@ -69,12 +69,10 @@ R deserialize(Path file, Class deseri SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); E latestConfigurationVersion = versionEnum.cast(versionEnum.getDeclaredMethod("getLatest").invoke(null)); - try ( - InputStream schemaStream = getClass() - .getResourceAsStream("/schema/" + latestConfigurationVersion + "/" + rootNodeName + ".xsd"); - InputStream configInputStream = Files.newInputStream(file)) { + URL schemaStream = getClass().getResource("/schema/" + latestConfigurationVersion + "/" + rootNodeName + ".xsd"); + try (InputStream configInputStream = Files.newInputStream(file)) { - Schema schema = schemaFactory.newSchema(new StreamSource(schemaStream)); + Schema schema = schemaFactory.newSchema(schemaStream); unmarschaller.setSchema(schema); rootNode = unmarschaller.unmarshal(configInputStream); return deserializeTo.cast(rootNode); @@ -90,7 +88,7 @@ R deserialize(Path file, Class deseri "Could not parse configuration file:\n" + message, e); } catch (SAXException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { // Should never occur. Programming error. - throw new IllegalStateException("Could not parse configuration schema. Please state this as a bug."); + throw new IllegalStateException("Could not parse configuration schema. Please state this as a bug.", e); } catch (NumberFormatException e) { // The version number is currently the only xml value which will be parsed to a number data type // So provide help