RFR: 8268698: Use Objects.check{Index, FromToIndex, FromIndexSize} where possible [v6]
Yi Yang
yyang at openjdk.java.net
Tue Jun 22 02:39:04 UTC 2021
On Mon, 21 Jun 2021 20:49:56 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:
>> Yi Yang has updated the pull request incrementally with one additional commit since the last revision:
>>
>> more replacement 2
>
> src/java.base/share/classes/jdk/internal/util/Preconditions.java line 78:
>
>> 76: = Preconditions.outOfBoundsExceptionFormatter(new StringIndexOutOfBoundsExceptionProducer());
>> 77:
>> 78: public static final BiFunction<String, List<Number>, StringIndexOutOfBoundsException> AIOOBE_FORMATTER
>
> Using incorrect exception type. Suggest you embed as inner class rather than separate declaration, since they are only used in one place.
Fixed.
FYI: Current exception message looks like this:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: Range [3, 1) out of bounds for length 6
at CheckIndex$StringIndexOutOfBoundsExceptionProducer.apply(CheckIndex.java:77)
at CheckIndex$StringIndexOutOfBoundsExceptionProducer.apply(CheckIndex.java:72)
at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:159)
at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:156)
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:62)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckFromToIndex(Preconditions.java:76)
at java.base/jdk.internal.util.Preconditions.checkFromToIndex(Preconditions.java:295)
at CheckIndex.main(CheckIndex.java:110)
I think now it expresses more exception information than before(and more consistent).
-------------
PR: https://git.openjdk.java.net/jdk/pull/4507
More information about the serviceability-dev
mailing list