Skip to content

Commit

Permalink
devonfw#1696: fixed JaxbDeserializer
Browse files Browse the repository at this point in the history
replaced try-with-resource InputStream with URL
added missing exception
  • Loading branch information
jan-vcapgemini committed Aug 10, 2023
1 parent bdaae62 commit 7f0dbe9
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -69,12 +69,10 @@ <R, E extends ConfigurationVersionEnum> R deserialize(Path file, Class<R> 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);
Expand All @@ -90,7 +88,7 @@ <R, E extends ConfigurationVersionEnum> R deserialize(Path file, Class<R> 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
Expand Down

0 comments on commit 7f0dbe9

Please sign in to comment.