jomarko commented on code in PR #6254:
URL:
https://github.com/apache/incubator-kie-drools/pull/6254#discussion_r1957924383
##########
drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/util/ScenarioSimulationXMLPersistence.java:
##########
@@ -179,18 +177,17 @@ public String migrateIfNecessary(String rawXml) throws
Exception {
.append(CURRENT_VERSION).toString());
}
migrator = migrator.andThen(getMigrationStrategy().end());
- Document document = DOMParserUtil.getDocument(rawXml);
migrator.accept(document);
return DOMParserUtil.getString(document);
}
- public String extractVersion(String rawXml) {
- Matcher m = p.matcher(rawXml);
-
- if (m.find()) {
- return m.group(1);
+ public String extractVersion(Document document) {
+ try {
+ return
document.getElementsByTagName(SCENARIO_SIMULATION_MODEL_NODE)
+
.item(0).getAttributes().getNamedItem(VERSION_ATTRIBUTE).getTextContent();
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Impossible to extract version
from the file", e);
}
Review Comment:
My only point is only about catching an exception and immediately throwing
new one. I believe we could use this approach to avoid `try` `catch` approach.
https://medium.com/@gurkanucar/how-to-prevent-null-pointer-exceptions-in-java-8d7c894c9bb4
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]