question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StringIndexOutOfBounds exceptions with relative server urls when loading from a file path that includes spaces

See original GitHub issue

Getting this error when parsing a file: java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 25

at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3319)
at java.base/java.lang.String.substring(String.java:1874)
at io.swagger.v3.parser.util.OpenAPIDeserializer.getServer(OpenAPIDeserializer.java:481)
at io.swagger.v3.parser.util.OpenAPIDeserializer.getServersList(OpenAPIDeserializer.java:435)
at io.swagger.v3.parser.util.OpenAPIDeserializer.parseRoot(OpenAPIDeserializer.java:192)
at io.swagger.v3.parser.util.OpenAPIDeserializer.deserialize(OpenAPIDeserializer.java:149)
at io.swagger.v3.parser.OpenAPIV3Parser.parseJsonNode(OpenAPIV3Parser.java:134)
at io.swagger.v3.parser.OpenAPIV3Parser.readContents(OpenAPIV3Parser.java:152)
at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:89)
at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16)

after debugging I noticed that the parser is failing to read

servers:
  - url: /just/an/example

but when removing the dash before the url, the parsing goes fine, so he servers part becomes:

servers:
   url: /just/an/example

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
HrFlorianHoffmanncommented, Mar 28, 2022

We worked around this issue with the following piece of code:

servers:
  - url: '{host}/my/path/v1'
    variables:
      host:
        default: ''

The empty dummy variable avoids that the statements value.indexOf("{") and value.indexOf("}") fail.

0reactions
HrFlorianHoffmanncommented, Mar 29, 2022

Tried to produce a pull request that provides a failing unit test for this issue, but failed.

I looked up the class OpenAPIDeserializerTest and added another unit test that supplies our exact yaml specification as a string to the OpenAPIV3Parser.readContents method. However, we didn’t get the expected exception.

I assume that the unit tests call the parser differently than the Maven plug-in. More precisely, I assume that the plugin calls the parser with a file location, such that the input parameter path of the method getServer is filled with a value. In the unit tests, this parameter is null, such that the entry condition path != null skips the affected code.

I tried to force the unit test to supply path with a value, by making the private method readContents in OpenAPIV3Parser public and calling it directly, but this didn’t work out, as the location/path variable has lots of other effects, and the code aborted with an unrelated other exception.

Setting up a reproducible sample needs more know-how about the parser’s details than I currently have.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Loading files in a Java ist not working when path contains any ...
I have an old API that I must feed with the file handles of some images, and I decided to load the images...
Read more >
Prevent inserted links with spaces from breaking
Prevent links that contain spaces from being truncated in email messages. ... If the first space is in the network path or location...
Read more >
Fix list for IBM WebSphere Application Server traditional V9
PH45080, Issue an error when certificate request file path contains spaces. PH45124, Add the WebSphere disabled algorithms to the configuration during ...
Read more >
WebLogic Server Known and Resolved Issues
xml file from Administration Console. This problem has been resolved by adding a check box named Archived Real Path Enabled on the Domain...
Read more >
Apache Tomcat 9 (9.0.70) - Changelog
Fix a potential StringIndexOutOfBoundsException exception when generating ... Report the paths relative to the server root for any resources with an error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found