8298033: Character.codePoint{At|Before}(char[], int, int) doesn't do JavaDoc-specified check

Reviewed-by: rriggs
This commit is contained in:
Sergey Tsypanov 2022-12-08 10:21:56 +00:00 committed by Julian Waters
parent 297bf6a596
commit b9346e149e
2 changed files with 6 additions and 7 deletions

View file

@ -39,7 +39,6 @@ import java.util.Optional;
import static java.lang.constant.ConstantDescs.BSM_EXPLICIT_CAST; import static java.lang.constant.ConstantDescs.BSM_EXPLICIT_CAST;
import static java.lang.constant.ConstantDescs.CD_char; import static java.lang.constant.ConstantDescs.CD_char;
import static java.lang.constant.ConstantDescs.CD_int;
import static java.lang.constant.ConstantDescs.DEFAULT_NAME; import static java.lang.constant.ConstantDescs.DEFAULT_NAME;
/** /**
@ -9375,7 +9374,7 @@ class Character implements java.io.Serializable, Comparable<Character>, Constabl
* @since 1.5 * @since 1.5
*/ */
public static int codePointAt(char[] a, int index, int limit) { public static int codePointAt(char[] a, int index, int limit) {
if (index >= limit || limit < 0 || limit > a.length) { if (index >= limit || index < 0 || limit > a.length) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
return codePointAtImpl(a, index, limit); return codePointAtImpl(a, index, limit);
@ -9478,7 +9477,7 @@ class Character implements java.io.Serializable, Comparable<Character>, Constabl
* @since 1.5 * @since 1.5
*/ */
public static int codePointBefore(char[] a, int index, int start) { public static int codePointBefore(char[] a, int index, int start) {
if (index <= start || start < 0 || start >= a.length) { if (index <= start || start < 0 || index > a.length) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
return codePointBeforeImpl(a, index, start); return codePointBeforeImpl(a, index, start);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2018, 2022 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 4533872 4985214 4985217 4993841 5017268 5017280 * @bug 4533872 4985214 4985217 4993841 5017268 5017280 8298033
* @summary Unit tests for supplementary character support (JSR-204) * @summary Unit tests for supplementary character support (JSR-204)
* @compile Supplementary.java * @compile Supplementary.java
* @run main/timeout=600 Supplementary * @run main/timeout=600 Supplementary
@ -797,12 +797,12 @@ public class Supplementary {
} }
private static void callCodePoint(boolean isAt, char[] a, int index, int limit, private static void callCodePoint(boolean isAt, char[] a, int index, int limit,
Class expectedException) { Class<? extends Exception> expectedException) {
try { try {
int c = isAt ? Character.codePointAt(a, index, limit) int c = isAt ? Character.codePointAt(a, index, limit)
: Character.codePointBefore(a, index, limit); : Character.codePointBefore(a, index, limit);
} catch (Exception e) { } catch (Exception e) {
if (expectedException.isInstance(e)) { if (expectedException == e.getClass()) {
return; return;
} }
throw new RuntimeException("Unspecified exception", e); throw new RuntimeException("Unspecified exception", e);