From 95445616af11147b0e243234cb6b824842b55626 Mon Sep 17 00:00:00 2001 From: Roman Szturc Date: Tue, 22 Oct 2024 13:32:54 +0200 Subject: [PATCH] Endpoint /versions made more robust The following error was reported 2024-08-27 12:50:55.025 ERROR 31489 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 81] with root cause java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 81 at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4604) ~[na:na] at java.base/java.lang.String.substring(String.java:2707) ~[na:na] at com.ericsson.eiffel.remrem.generate.controller.VersionService.getServiceVersion(VersionService.java:113) ~[classes/:na] at com.ericsson.eiffel.remrem.generate.controller.VersionService.getMessagingVersions(VersionService.java:95) ~[classes/:na] at com.ericsson.eiffel.remrem.generate.controller.RemremGenerateController.getVersions(RemremGenerateController.java:410) ~[classes/:na] This fix handles -1 result of lastIndexOf properly, so no exception is thrown. --- CHANGELOG.md | 3 +++ pom.xml | 2 +- .../remrem/generate/controller/VersionService.java | 10 +++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e5e758..6dd9910 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.1.12 +- Endpoint /versions made more robust. + ## 2.1.11 - Made changes to /message_protocols end-point to work for old REMRem-Semantics library. diff --git a/pom.xml b/pom.xml index 5c7fca5..2e4fcac 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.eiffel-community eiffel-remrem-parent - 2.0.12 + 2.0.13 diff --git a/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/VersionService.java b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/VersionService.java index 7617d32..64a839d 100644 --- a/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/VersionService.java +++ b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/VersionService.java @@ -110,7 +110,15 @@ public Map> getMessagingVersions() { */ public Map getServiceVersion() { String resourcesPath = this.getClass().getClassLoader().getResource("").getPath(); - String manifestPath = resourcesPath.substring(0, resourcesPath.lastIndexOf(WEB_INF)).concat(META_INF_MANIFEST_MF); + int indexWebInf = resourcesPath.lastIndexOf(WEB_INF); + if (indexWebInf == -1) { + // "WEB-INF" was not found in the path, strange... + log.error("Cannot find '" + WEB_INF + "' in the path '" + resourcesPath + + "'. Not loaded from a WAR file?"); + return serviceVersion; + } + + String manifestPath = resourcesPath.substring(0, indexWebInf).concat(META_INF_MANIFEST_MF); try { Manifest manifest = new Manifest(new FileInputStream(manifestPath)); Attributes mainAttribs = manifest.getMainAttributes();