StringIndexOutOfBounds exceptions with relative server urls when loading from a file path that includes spaces
See original GitHub issueGetting 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:
- Created 2 years ago
- Reactions:1
- Comments:11 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We worked around this issue with the following piece of code:
The empty dummy variable avoids that the statements
value.indexOf("{")
andvalue.indexOf("}")
fail.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 theOpenAPIV3Parser.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 methodgetServer
is filled with a value. In the unit tests, this parameter isnull
, such that the entry conditionpath != null
skips the affected code.I tried to force the unit test to supply
path
with a value, by making the private methodreadContents
inOpenAPIV3Parser
public and calling it directly, but this didn’t work out, as thelocation
/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.