Skip to content

Commit

Permalink
Endpoint /versions made more robust
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
z-sztrom committed Oct 22, 2024
1 parent 243dd06 commit 9544561
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.github.eiffel-community</groupId>
<artifactId>eiffel-remrem-parent</artifactId>
<version>2.0.12</version>
<version>2.0.13</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,15 @@ public Map<String, Map<String, String>> getMessagingVersions() {
*/
public Map<String, String> 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();
Expand Down

0 comments on commit 9544561

Please sign in to comment.