RFR: 8293499: Provide jmod --compress option [v4]
Jaikiran Pai
jpai at openjdk.org
Tue Sep 13 09:58:35 UTC 2022
On Tue, 13 Sep 2022 09:28:07 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
>> src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java line 1196:
>>
>>> 1194: }
>>> 1195: try {
>>> 1196: int level = Integer.parseInt(value.substring(idx + 1));
>>
>> If I'm reading this code correctly, then this call to `substring` can potentially end in a `IndexOutOfBoundsException` if the value is `zip-`. Perhaps add a check above to verify that `idx != value.length()`?
>
> `String.substring` does the right thing when `idx == length()` -- it returns the empty string, which would fail to parse. Anyway, I added the test for "zip-" to verify this.
You are right indeed. All these days I had in my mind that the `String.subString` will throw the `IndexOutOfBoundsException` if the passed integer isn't a valid "index". I had that perception due to the javadoc which says:
The substring begins with the character at the specified index
I hadn't paid attention to the later part of that same javadoc which says, along with an example, that the returned value is an empty string if the index == length() and will only throw `IndexOutOfBoundsException` if the passed value is greater than `length()`.
So what you have here is fine, of course. Thank you for updating the test.
-------------
PR: https://git.openjdk.org/jdk/pull/10213
More information about the core-libs-dev
mailing list