From 8fcfddb2d202cdb61941efdb3fec5807fee98c33 Mon Sep 17 00:00:00 2001 From: Volkan Yazici Date: Thu, 15 May 2025 14:54:27 +0000 Subject: [PATCH] 8353197: Document preconditions for JavaLangAccess methods Reviewed-by: pminborg, liach --- .../classes/java/io/DataInputStream.java | 8 +- .../classes/java/io/ObjectInputStream.java | 4 +- .../share/classes/java/lang/System.java | 18 ++--- .../java/lang/invoke/StringConcatFactory.java | 4 +- .../share/classes/java/math/BigDecimal.java | 2 +- .../share/classes/java/nio/file/Files.java | 4 +- .../share/classes/java/util/HexFormat.java | 14 ++-- .../share/classes/java/util/UUID.java | 2 +- .../share/classes/java/util/zip/ZipCoder.java | 4 +- .../jdk/internal/access/JavaLangAccess.java | 81 ++++++++++++------- .../classfile/impl/AbstractPoolEntry.java | 4 +- .../classes/jdk/internal/math/ToDecimal.java | 10 +-- .../jdk/internal/util/ArraysSupport.java | 4 +- .../classes/jdk/internal/util/HexDigits.java | 10 +-- .../share/classes/sun/nio/cs/CESU_8.java | 8 +- .../share/classes/sun/nio/cs/DoubleByte.java | 12 ++- .../share/classes/sun/nio/cs/ISO_8859_1.java | 4 +- .../share/classes/sun/nio/cs/SingleByte.java | 8 +- .../share/classes/sun/nio/cs/US_ASCII.java | 6 +- .../share/classes/sun/nio/cs/UTF_8.java | 7 +- .../unix/classes/sun/nio/fs/UnixPath.java | 4 +- .../sun/nio/cs/ext/EUC_JP.java.template | 4 +- 22 files changed, 121 insertions(+), 101 deletions(-) diff --git a/src/java.base/share/classes/java/io/DataInputStream.java b/src/java.base/share/classes/java/io/DataInputStream.java index 59377aca429..fa6fecf83da 100644 --- a/src/java.base/share/classes/java/io/DataInputStream.java +++ b/src/java.base/share/classes/java/io/DataInputStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2025, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2024, Alibaba Group Holding Limited. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -595,11 +595,11 @@ loop: while (true) { int chararr_count=0; in.readFully(bytearr, 0, utflen); - int ascii = JLA.countPositives(bytearr, 0, utflen); + int ascii = JLA.uncheckedCountPositives(bytearr, 0, utflen); if (ascii == utflen) { String str; if (trusted) { - str = JLA.newStringNoRepl(bytearr, StandardCharsets.ISO_8859_1); + str = JLA.uncheckedNewStringNoRepl(bytearr, StandardCharsets.ISO_8859_1); } else { str = new String(bytearr, 0, utflen, StandardCharsets.ISO_8859_1); } @@ -621,7 +621,7 @@ loop: while (true) { } if (ascii != 0) { - JLA.inflateBytesToChars(bytearr, 0, chararr, 0, ascii); + JLA.uncheckedInflateBytesToChars(bytearr, 0, chararr, 0, ascii); count += ascii; chararr_count += ascii; } diff --git a/src/java.base/share/classes/java/io/ObjectInputStream.java b/src/java.base/share/classes/java/io/ObjectInputStream.java index daed5f3cce5..b9593fa2c2f 100644 --- a/src/java.base/share/classes/java/io/ObjectInputStream.java +++ b/src/java.base/share/classes/java/io/ObjectInputStream.java @@ -3536,7 +3536,7 @@ public class ObjectInputStream if (utflen > 0 && utflen < Integer.MAX_VALUE) { // Scan for leading ASCII chars int avail = end - pos; - int ascii = JLA.countPositives(buf, pos, Math.min(avail, (int)utflen)); + int ascii = JLA.uncheckedCountPositives(buf, pos, Math.min(avail, (int)utflen)); if (ascii == utflen) { // Complete match, consume the buf[pos ... pos + ascii] range and return. // Modified UTF-8 and ISO-8859-1 are both ASCII-compatible encodings bytes @@ -3549,7 +3549,7 @@ public class ObjectInputStream // Avoid allocating a StringBuilder if there's enough data in buf and // cbuf is large enough if (avail >= utflen && utflen <= CHAR_BUF_SIZE) { - JLA.inflateBytesToChars(buf, pos, cbuf, 0, ascii); + JLA.uncheckedInflateBytesToChars(buf, pos, cbuf, 0, ascii); pos += ascii; int cbufPos = readUTFSpan(ascii, utflen - ascii); return new String(cbuf, 0, cbufPos); diff --git a/src/java.base/share/classes/java/lang/System.java b/src/java.base/share/classes/java/lang/System.java index 42c60ad2162..882b5f6945f 100644 --- a/src/java.base/share/classes/java/lang/System.java +++ b/src/java.base/share/classes/java/lang/System.java @@ -2118,22 +2118,22 @@ public final class System { return ModuleLayer.layers(loader); } - public int countPositives(byte[] bytes, int offset, int length) { + public int uncheckedCountPositives(byte[] bytes, int offset, int length) { return StringCoding.countPositives(bytes, offset, length); } public int countNonZeroAscii(String s) { return StringCoding.countNonZeroAscii(s); } - public String newStringNoRepl(byte[] bytes, Charset cs) throws CharacterCodingException { + public String uncheckedNewStringNoRepl(byte[] bytes, Charset cs) throws CharacterCodingException { return String.newStringNoRepl(bytes, cs); } - public char getUTF16Char(byte[] bytes, int index) { + public char uncheckedGetUTF16Char(byte[] bytes, int index) { return StringUTF16.getChar(bytes, index); } - public void putCharUTF16(byte[] bytes, int index, int ch) { + public void uncheckedPutCharUTF16(byte[] bytes, int index, int ch) { StringUTF16.putChar(bytes, index, ch); } - public byte[] getBytesNoRepl(String s, Charset cs) throws CharacterCodingException { + public byte[] uncheckedGetBytesNoRepl(String s, Charset cs) throws CharacterCodingException { return String.getBytesNoRepl(s, cs); } @@ -2145,15 +2145,15 @@ public final class System { return String.getBytesUTF8NoRepl(s); } - public void inflateBytesToChars(byte[] src, int srcOff, char[] dst, int dstOff, int len) { + public void uncheckedInflateBytesToChars(byte[] src, int srcOff, char[] dst, int dstOff, int len) { StringLatin1.inflate(src, srcOff, dst, dstOff, len); } - public int decodeASCII(byte[] src, int srcOff, char[] dst, int dstOff, int len) { + public int uncheckedDecodeASCII(byte[] src, int srcOff, char[] dst, int dstOff, int len) { return String.decodeASCII(src, srcOff, dst, dstOff, len); } - public int encodeASCII(char[] src, int srcOff, byte[] dst, int dstOff, int len) { + public int uncheckedEncodeASCII(char[] src, int srcOff, byte[] dst, int dstOff, int len) { return StringCoding.implEncodeAsciiArray(src, srcOff, dst, dstOff, len); } @@ -2189,7 +2189,7 @@ public final class System { return StringConcatHelper.mix(lengthCoder, value); } - public Object stringConcat1(String[] constants) { + public Object uncheckedStringConcat1(String[] constants) { return new StringConcatHelper.Concat1(constants); } diff --git a/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java b/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java index 7e91057cbf4..ca296e21a26 100644 --- a/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java +++ b/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2024, Alibaba Group Holding Limited. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -1258,7 +1258,7 @@ public final class StringConcatFactory { // 1 argument use built-in method if (args.parameterCount() == 1) { - Object concat1 = JLA.stringConcat1(constants); + Object concat1 = JLA.uncheckedStringConcat1(constants); var handle = lookup.findVirtual(concat1.getClass(), METHOD_NAME, concatArgs); return handle.bindTo(concat1); } diff --git a/src/java.base/share/classes/java/math/BigDecimal.java b/src/java.base/share/classes/java/math/BigDecimal.java index dd6253a7132..4304c09630c 100644 --- a/src/java.base/share/classes/java/math/BigDecimal.java +++ b/src/java.base/share/classes/java/math/BigDecimal.java @@ -4142,7 +4142,7 @@ public class BigDecimal extends Number implements Comparable { buf[highIntSize] = '.'; DecimalDigits.putPairLatin1(buf, highIntSize + 1, lowInt); try { - return JLA.newStringNoRepl(buf, StandardCharsets.ISO_8859_1); + return JLA.uncheckedNewStringNoRepl(buf, StandardCharsets.ISO_8859_1); } catch (CharacterCodingException cce) { throw new AssertionError(cce); } diff --git a/src/java.base/share/classes/java/nio/file/Files.java b/src/java.base/share/classes/java/nio/file/Files.java index 2f83f79d4bd..f8278fa2642 100644 --- a/src/java.base/share/classes/java/nio/file/Files.java +++ b/src/java.base/share/classes/java/nio/file/Files.java @@ -3043,7 +3043,7 @@ public final class Files { byte[] ba = readAllBytes(path); if (path.getClass().getModule() != Object.class.getModule()) ba = ba.clone(); - return JLA.newStringNoRepl(ba, cs); + return JLA.uncheckedNewStringNoRepl(ba, cs); } /** @@ -3362,7 +3362,7 @@ public final class Files { Objects.requireNonNull(csq); Objects.requireNonNull(cs); - byte[] bytes = JLA.getBytesNoRepl(String.valueOf(csq), cs); + byte[] bytes = JLA.uncheckedGetBytesNoRepl(String.valueOf(csq), cs); if (path.getClass().getModule() != Object.class.getModule()) bytes = bytes.clone(); write(path, bytes, options); diff --git a/src/java.base/share/classes/java/util/HexFormat.java b/src/java.base/share/classes/java/util/HexFormat.java index cd6cf8af17d..99d047995fd 100644 --- a/src/java.base/share/classes/java/util/HexFormat.java +++ b/src/java.base/share/classes/java/util/HexFormat.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2024, Alibaba Group Holding Limited. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -462,7 +462,7 @@ public final class HexFormat { } try { // Return a new string using the bytes without making a copy - return jla.newStringNoRepl(rep, StandardCharsets.ISO_8859_1); + return jla.uncheckedNewStringNoRepl(rep, StandardCharsets.ISO_8859_1); } catch (CharacterCodingException cce) { throw new AssertionError(cce); } @@ -696,7 +696,7 @@ public final class HexFormat { rep[0] = (byte)toHighHexDigit(value); rep[1] = (byte)toLowHexDigit(value); try { - return jla.newStringNoRepl(rep, StandardCharsets.ISO_8859_1); + return jla.uncheckedNewStringNoRepl(rep, StandardCharsets.ISO_8859_1); } catch (CharacterCodingException cce) { throw new AssertionError(cce); } @@ -732,7 +732,7 @@ public final class HexFormat { rep[3] = (byte)toLowHexDigit((byte)value); try { - return jla.newStringNoRepl(rep, StandardCharsets.ISO_8859_1); + return jla.uncheckedNewStringNoRepl(rep, StandardCharsets.ISO_8859_1); } catch (CharacterCodingException cce) { throw new AssertionError(cce); } @@ -760,7 +760,7 @@ public final class HexFormat { rep[7] = (byte)toLowHexDigit((byte)value); try { - return jla.newStringNoRepl(rep, StandardCharsets.ISO_8859_1); + return jla.uncheckedNewStringNoRepl(rep, StandardCharsets.ISO_8859_1); } catch (CharacterCodingException cce) { throw new AssertionError(cce); } @@ -796,7 +796,7 @@ public final class HexFormat { rep[15] = (byte)toLowHexDigit((byte)value); try { - return jla.newStringNoRepl(rep, StandardCharsets.ISO_8859_1); + return jla.uncheckedNewStringNoRepl(rep, StandardCharsets.ISO_8859_1); } catch (CharacterCodingException cce) { throw new AssertionError(cce); } @@ -824,7 +824,7 @@ public final class HexFormat { value = value >>> 4; } try { - return jla.newStringNoRepl(rep, StandardCharsets.ISO_8859_1); + return jla.uncheckedNewStringNoRepl(rep, StandardCharsets.ISO_8859_1); } catch (CharacterCodingException cce) { throw new AssertionError(cce); } diff --git a/src/java.base/share/classes/java/util/UUID.java b/src/java.base/share/classes/java/util/UUID.java index db0dbe28802..08b9b87b7ca 100644 --- a/src/java.base/share/classes/java/util/UUID.java +++ b/src/java.base/share/classes/java/util/UUID.java @@ -481,7 +481,7 @@ public final class UUID implements java.io.Serializable, Comparable { HexDigits.put4(buf, 28, i3 >> 16); HexDigits.put4(buf, 32, i3); try { - return jla.newStringNoRepl(buf, StandardCharsets.ISO_8859_1); + return jla.uncheckedNewStringNoRepl(buf, StandardCharsets.ISO_8859_1); } catch (CharacterCodingException cce) { throw new AssertionError(cce); } diff --git a/src/java.base/share/classes/java/util/zip/ZipCoder.java b/src/java.base/share/classes/java/util/zip/ZipCoder.java index 2702b90f4f6..bbf1c10112a 100644 --- a/src/java.base/share/classes/java/util/zip/ZipCoder.java +++ b/src/java.base/share/classes/java/util/zip/ZipCoder.java @@ -266,7 +266,7 @@ class ZipCoder { return 0; } int end = off + len; - int asciiLen = JLA.countPositives(a, off, len); + int asciiLen = JLA.uncheckedCountPositives(a, off, len); if (asciiLen != len) { // Non-ASCII, fall back to decoding a String // We avoid using decoder() here since the UTF8ZipCoder is @@ -289,7 +289,7 @@ class ZipCoder { @Override byte compare(String str, byte[] b, int off, int len, boolean matchDirectory) { try { - byte[] encoded = JLA.getBytesNoRepl(str, UTF_8.INSTANCE); + byte[] encoded = JLA.uncheckedGetBytesNoRepl(str, UTF_8.INSTANCE); int mismatch = Arrays.mismatch(encoded, 0, encoded.length, b, off, off+len); if (mismatch == -1) { return EXACT_MATCH; diff --git a/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java b/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java index 20b6cd23682..1f60f85464b 100644 --- a/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java +++ b/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java @@ -302,8 +302,10 @@ public interface JavaLangAccess { /** * Count the number of leading positive bytes in the range. + *

+ * WARNING: This method does not perform any bound checks. */ - int countPositives(byte[] ba, int off, int len); + int uncheckedCountPositives(byte[] ba, int off, int len); /** * Count the number of leading non-zero ascii chars in the String. @@ -311,37 +313,40 @@ public interface JavaLangAccess { int countNonZeroAscii(String s); /** - * Constructs a new {@code String} by decoding the specified subarray of - * bytes using the specified {@linkplain java.nio.charset.Charset charset}. - * - * The caller of this method shall relinquish and transfer the ownership of - * the byte array to the callee since the later will not make a copy. + * Constructs a new {@code String} by decoding the specified byte array + * using the specified {@linkplain java.nio.charset.Charset charset}. + *

+ * WARNING: The caller of this method shall relinquish and transfer the + * ownership of the byte array to the callee, since the latter will not + * make a copy. * * @param bytes the byte array source * @param cs the Charset * @return the newly created string * @throws CharacterCodingException for malformed or unmappable bytes */ - String newStringNoRepl(byte[] bytes, Charset cs) throws CharacterCodingException; + String uncheckedNewStringNoRepl(byte[] bytes, Charset cs) throws CharacterCodingException; /** - * Encode the given string into a sequence of bytes using the specified Charset. - * - * This method avoids copying the String's internal representation if the input - * is ASCII. - * - * This method throws CharacterCodingException instead of replacing when - * malformed input or unmappable characters are encountered. + * Encode the given string into a sequence of bytes using the specified + * {@linkplain java.nio.charset.Charset charset}. + *

+ * WARNING: This method returns the {@code byte[]} backing the provided + * {@code String}, if the input is ASCII. Hence, the returned byte array + * must not be modified. + *

+ * This method throws {@code CharacterCodingException} instead of replacing + * when malformed input or unmappable characters are encountered. * * @param s the string to encode * @param cs the charset * @return the encoded bytes * @throws CharacterCodingException for malformed input or unmappable characters */ - byte[] getBytesNoRepl(String s, Charset cs) throws CharacterCodingException; + byte[] uncheckedGetBytesNoRepl(String s, Charset cs) throws CharacterCodingException; /** - * Returns a new string by decoding from the given utf8 bytes array. + * Returns a new string by decoding from the given UTF-8 bytes array. * * @param off the index of the first byte to decode * @param len the number of bytes to decode @@ -351,23 +356,27 @@ public interface JavaLangAccess { String newStringUTF8NoRepl(byte[] bytes, int off, int len); /** - * Get the char at index in a byte[] in internal UTF-16 representation, - * with no bounds checks. + * Get the {@code char} at {@code index} in a {@code byte[]} in internal + * UTF-16 representation. + *

+ * WARNING: This method does not perform any bound checks. * * @param bytes the UTF-16 encoded bytes * @param index of the char to retrieve, 0 <= index < (bytes.length >> 1) * @return the char value */ - char getUTF16Char(byte[] bytes, int index); + char uncheckedGetUTF16Char(byte[] bytes, int index); /** - * Put the char at index in a byte[] in internal UTF-16 representation, - * with no bounds checks. + * Put the {@code ch} at {@code index} in a {@code byte[]} in internal + * UTF-16 representation. + *

+ * WARNING: This method does not perform any bound checks. * * @param bytes the UTF-16 encoded bytes * @param index of the char to retrieve, 0 <= index < (bytes.length >> 1) */ - void putCharUTF16(byte[] bytes, int index, int ch); + void uncheckedPutCharUTF16(byte[] bytes, int index, int ch); /** * Encode the given string into a sequence of bytes using utf8. @@ -379,17 +388,22 @@ public interface JavaLangAccess { byte[] getBytesUTF8NoRepl(String s); /** - * Inflated copy from byte[] to char[], as defined by StringLatin1.inflate + * Inflated copy from {@code byte[]} to {@code char[]}, as defined by + * {@code StringLatin1.inflate}. + *

+ * WARNING: This method does not perform any bound checks. */ - void inflateBytesToChars(byte[] src, int srcOff, char[] dst, int dstOff, int len); + void uncheckedInflateBytesToChars(byte[] src, int srcOff, char[] dst, int dstOff, int len); /** * Decodes ASCII from the source byte array into the destination * char array. + *

+ * WARNING: This method does not perform any bound checks. * * @return the number of bytes successfully decoded, at most len */ - int decodeASCII(byte[] src, int srcOff, char[] dst, int dstOff, int len); + int uncheckedDecodeASCII(byte[] src, int srcOff, char[] dst, int dstOff, int len); /** * Returns the initial `System.in` to determine if it is replaced @@ -403,13 +417,15 @@ public interface JavaLangAccess { PrintStream initialSystemErr(); /** - * Encodes ASCII codepoints as possible from the source array into + * Encodes as many ASCII codepoints as possible from the source array into * the destination byte array, assuming that the encoding is ASCII - * compatible + * compatible. + *

+ * WARNING: This method does not perform any bound checks. * * @return the number of bytes successfully encoded, or 0 if none */ - int encodeASCII(char[] src, int srcOff, byte[] dst, int dstOff, int len); + int uncheckedEncodeASCII(char[] src, int srcOff, byte[] dst, int dstOff, int len); /** * Set the cause of Throwable @@ -442,7 +458,14 @@ public interface JavaLangAccess { */ long stringConcatMix(long lengthCoder, char value); - Object stringConcat1(String[] constants); + /** + * Creates helper for string concatenation. + *

+ * WARNING: The caller of this method shall relinquish and transfer the + * ownership of the string array to the callee, since the latter will not + * make a copy. + */ + Object uncheckedStringConcat1(String[] constants); /** * Get the string initial coder, When COMPACT_STRINGS is on, it returns 0, and when it is off, it returns 1. diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractPoolEntry.java b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractPoolEntry.java index 962a2057585..ab7f0847bbd 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractPoolEntry.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractPoolEntry.java @@ -218,7 +218,7 @@ public abstract sealed class AbstractPoolEntry { * two-times-three-byte format instead. */ private void inflate() { - int singleBytes = JLA.countPositives(rawBytes, offset, rawLen); + int singleBytes = JLA.uncheckedCountPositives(rawBytes, offset, rawLen); int hash = ArraysSupport.hashCodeOfUnsigned(rawBytes, offset, singleBytes, 0); if (singleBytes == rawLen) { this.contentHash = hash; @@ -233,7 +233,7 @@ public abstract sealed class AbstractPoolEntry { char[] chararr = new char[rawLen]; int chararr_count = singleBytes; // Inflate prefix of bytes to characters - JLA.inflateBytesToChars(rawBytes, offset, chararr, 0, singleBytes); + JLA.uncheckedInflateBytesToChars(rawBytes, offset, chararr, 0, singleBytes); int px = offset + singleBytes; int utfend = offset + rawLen; diff --git a/src/java.base/share/classes/jdk/internal/math/ToDecimal.java b/src/java.base/share/classes/jdk/internal/math/ToDecimal.java index 45d4da25323..22f9e5a338d 100644 --- a/src/java.base/share/classes/jdk/internal/math/ToDecimal.java +++ b/src/java.base/share/classes/jdk/internal/math/ToDecimal.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2024, Alibaba Group Holding Limited. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -58,7 +58,7 @@ abstract sealed class ToDecimal permits DoubleToDecimal, FloatToDecimal { if (latin1) { str[index] = (byte) c; } else { - JLA.putCharUTF16(str, index, (char) c); + JLA.uncheckedPutCharUTF16(str, index, (char) c); } return index + 1; } @@ -93,7 +93,7 @@ abstract sealed class ToDecimal permits DoubleToDecimal, FloatToDecimal { int y = y(m); for (int i = 0; i < 8; ++i) { int t = 10 * y; - JLA.putCharUTF16(str, index + i, '0' + (t >>> 28)); + JLA.uncheckedPutCharUTF16(str, index + i, '0' + (t >>> 28)); y = t & MASK_28; } } @@ -122,11 +122,11 @@ abstract sealed class ToDecimal permits DoubleToDecimal, FloatToDecimal { ++index; } } else { - while (JLA.getUTF16Char(str, index - 1) == '0') { + while (JLA.uncheckedGetUTF16Char(str, index - 1) == '0') { --index; } /* ... but do not remove the one directly to the right of '.' */ - if (JLA.getUTF16Char(str, index - 1) == '.') { + if (JLA.uncheckedGetUTF16Char(str, index - 1) == '.') { ++index; } } diff --git a/src/java.base/share/classes/jdk/internal/util/ArraysSupport.java b/src/java.base/share/classes/jdk/internal/util/ArraysSupport.java index 1a56c3c64fd..de7a5e44b91 100644 --- a/src/java.base/share/classes/jdk/internal/util/ArraysSupport.java +++ b/src/java.base/share/classes/jdk/internal/util/ArraysSupport.java @@ -298,7 +298,7 @@ public class ArraysSupport { public static int hashCodeOfUTF16(byte[] a, int fromIndex, int length, int initialValue) { return switch (length) { case 0 -> initialValue; - case 1 -> 31 * initialValue + JLA.getUTF16Char(a, fromIndex); + case 1 -> 31 * initialValue + JLA.uncheckedGetUTF16Char(a, fromIndex); default -> vectorizedHashCode(a, fromIndex, length, initialValue, T_CHAR); }; } @@ -420,7 +420,7 @@ public class ArraysSupport { private static int utf16hashCode(int result, byte[] value, int fromIndex, int length) { int end = fromIndex + length; for (int i = fromIndex; i < end; i++) { - result = 31 * result + JLA.getUTF16Char(value, i); + result = 31 * result + JLA.uncheckedGetUTF16Char(value, i); } return result; } diff --git a/src/java.base/share/classes/jdk/internal/util/HexDigits.java b/src/java.base/share/classes/jdk/internal/util/HexDigits.java index c08db4f5b48..e014c932f83 100644 --- a/src/java.base/share/classes/jdk/internal/util/HexDigits.java +++ b/src/java.base/share/classes/jdk/internal/util/HexDigits.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -168,16 +168,16 @@ public final class HexDigits { public static int getCharsUTF16(long value, int index, byte[] buffer) { while ((value & ~0xFF) != 0) { int pair = (int) DIGITS[((int) value) & 0xFF]; - JLA.putCharUTF16(buffer, --index, pair >> 8); - JLA.putCharUTF16(buffer, --index, pair & 0xFF); + JLA.uncheckedPutCharUTF16(buffer, --index, pair >> 8); + JLA.uncheckedPutCharUTF16(buffer, --index, pair & 0xFF); value >>>= 8; } int digits = DIGITS[(int) (value & 0xFF)]; - JLA.putCharUTF16(buffer, --index, (byte) (digits >> 8)); + JLA.uncheckedPutCharUTF16(buffer, --index, (byte) (digits >> 8)); if (0xF < value) { - JLA.putCharUTF16(buffer, --index, (byte) (digits & 0xFF)); + JLA.uncheckedPutCharUTF16(buffer, --index, (byte) (digits & 0xFF)); } return index; diff --git a/src/java.base/share/classes/sun/nio/cs/CESU_8.java b/src/java.base/share/classes/sun/nio/cs/CESU_8.java index f1fc69703c2..a6e233873a8 100644 --- a/src/java.base/share/classes/sun/nio/cs/CESU_8.java +++ b/src/java.base/share/classes/sun/nio/cs/CESU_8.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -196,7 +196,7 @@ class CESU_8 extends Unicode int dp = doff + dst.position(); int dl = doff + dst.limit(); - int n = JLA.decodeASCII(sa, sp, da, dp, Math.min(sl - sp, dl - dp)); + int n = JLA.uncheckedDecodeASCII(sa, sp, da, dp, Math.min(sl - sp, dl - dp)); sp += n; dp += n; @@ -446,7 +446,7 @@ class CESU_8 extends Unicode int dl = dst.arrayOffset() + dst.limit(); // Handle ASCII-only prefix - int n = JLA.encodeASCII(sa, sp, da, dp, Math.min(sl - sp, dl - dp)); + int n = JLA.uncheckedEncodeASCII(sa, sp, da, dp, Math.min(sl - sp, dl - dp)); sp += n; dp += n; @@ -551,7 +551,7 @@ class CESU_8 extends Unicode int dp = 0; // Handle ASCII-only prefix - int n = JLA.encodeASCII(sa, sp, da, dp, Math.min(len, da.length)); + int n = JLA.uncheckedEncodeASCII(sa, sp, da, dp, Math.min(len, da.length)); sp += n; dp += n; diff --git a/src/java.base/share/classes/sun/nio/cs/DoubleByte.java b/src/java.base/share/classes/sun/nio/cs/DoubleByte.java index 2978a6f5dec..c4c9856a60b 100644 --- a/src/java.base/share/classes/sun/nio/cs/DoubleByte.java +++ b/src/java.base/share/classes/sun/nio/cs/DoubleByte.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,9 +35,7 @@ import java.util.Arrays; import jdk.internal.access.JavaLangAccess; import jdk.internal.access.SharedSecrets; -import sun.nio.cs.Surrogate; -import sun.nio.cs.ArrayDecoder; -import sun.nio.cs.ArrayEncoder; + import static sun.nio.cs.CharsetMapping.*; /* @@ -170,7 +168,7 @@ public class DoubleByte { try { if (isASCIICompatible) { - int n = JLA.decodeASCII(sa, sp, da, dp, Math.min(dl - dp, sl - sp)); + int n = JLA.uncheckedDecodeASCII(sa, sp, da, dp, Math.min(dl - dp, sl - sp)); dp += n; sp += n; } @@ -602,7 +600,7 @@ public class DoubleByte { try { if (isASCIICompatible) { - int n = JLA.encodeASCII(sa, sp, da, dp, Math.min(dl - dp, sl - sp)); + int n = JLA.uncheckedEncodeASCII(sa, sp, da, dp, Math.min(dl - dp, sl - sp)); sp += n; dp += n; } @@ -688,7 +686,7 @@ public class DoubleByte { int dp = 0; int sl = sp + len; if (isASCIICompatible) { - int n = JLA.encodeASCII(src, sp, dst, dp, len); + int n = JLA.uncheckedEncodeASCII(src, sp, dst, dp, len); sp += n; dp += n; } diff --git a/src/java.base/share/classes/sun/nio/cs/ISO_8859_1.java b/src/java.base/share/classes/sun/nio/cs/ISO_8859_1.java index 3e86f104fac..241171d8deb 100644 --- a/src/java.base/share/classes/sun/nio/cs/ISO_8859_1.java +++ b/src/java.base/share/classes/sun/nio/cs/ISO_8859_1.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -87,7 +87,7 @@ public class ISO_8859_1 int dl = doff + dst.limit(); int decodeLen = Math.min(sl - sp, dl - dp); - JLA.inflateBytesToChars(sa, sp, da, dp, decodeLen); + JLA.uncheckedInflateBytesToChars(sa, sp, da, dp, decodeLen); sp += decodeLen; dp += decodeLen; src.position(sp - soff); diff --git a/src/java.base/share/classes/sun/nio/cs/SingleByte.java b/src/java.base/share/classes/sun/nio/cs/SingleByte.java index 748659b323f..fe66f3216a4 100644 --- a/src/java.base/share/classes/sun/nio/cs/SingleByte.java +++ b/src/java.base/share/classes/sun/nio/cs/SingleByte.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,7 +35,7 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; import java.nio.charset.CoderResult; -import java.util.Arrays; + import static sun.nio.cs.CharsetMapping.*; public class SingleByte @@ -95,7 +95,7 @@ public class SingleByte } if (isASCIICompatible) { - int n = JLA.decodeASCII(sa, sp, da, dp, Math.min(dl - dp, sl - sp)); + int n = JLA.uncheckedDecodeASCII(sa, sp, da, dp, Math.min(dl - dp, sl - sp)); sp += n; dp += n; } @@ -217,7 +217,7 @@ public class SingleByte int len = Math.min(dl - dp, sl - sp); if (isASCIICompatible) { - int n = JLA.encodeASCII(sa, sp, da, dp, len); + int n = JLA.uncheckedEncodeASCII(sa, sp, da, dp, len); sp += n; dp += n; len -= n; diff --git a/src/java.base/share/classes/sun/nio/cs/US_ASCII.java b/src/java.base/share/classes/sun/nio/cs/US_ASCII.java index 8ff79d497fb..627b1433d61 100644 --- a/src/java.base/share/classes/sun/nio/cs/US_ASCII.java +++ b/src/java.base/share/classes/sun/nio/cs/US_ASCII.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -83,7 +83,7 @@ public class US_ASCII int dl = doff + dst.limit(); // ASCII only loop - int n = JLA.decodeASCII(sa, sp, da, dp, Math.min(sl - sp, dl - dp)); + int n = JLA.uncheckedDecodeASCII(sa, sp, da, dp, Math.min(sl - sp, dl - dp)); sp += n; dp += n; src.position(sp - soff); @@ -159,7 +159,7 @@ public class US_ASCII assert (dp <= dl); dp = (dp <= dl ? dp : dl); - int n = JLA.encodeASCII(sa, sp, da, dp, Math.min(sl - sp, dl - dp)); + int n = JLA.uncheckedEncodeASCII(sa, sp, da, dp, Math.min(sl - sp, dl - dp)); sp += n; dp += n; diff --git a/src/java.base/share/classes/sun/nio/cs/UTF_8.java b/src/java.base/share/classes/sun/nio/cs/UTF_8.java index a27b4690f59..89a199db99b 100644 --- a/src/java.base/share/classes/sun/nio/cs/UTF_8.java +++ b/src/java.base/share/classes/sun/nio/cs/UTF_8.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,7 +35,6 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; import java.nio.charset.CoderResult; -import java.nio.charset.CodingErrorAction; /* Legal UTF-8 Byte Sequences * @@ -228,7 +227,7 @@ public final class UTF_8 extends Unicode { int dp = doff + dst.position(); int dl = doff + dst.limit(); - int n = JLA.decodeASCII(sa, sp, da, dp, Math.min(sl - sp, dl - dp)); + int n = JLA.uncheckedDecodeASCII(sa, sp, da, dp, Math.min(sl - sp, dl - dp)); sp += n; dp += n; @@ -453,7 +452,7 @@ public final class UTF_8 extends Unicode { int dl = dst.arrayOffset() + dst.limit(); // Handle ASCII-only prefix - int n = JLA.encodeASCII(sa, sp, da, dp, Math.min(sl - sp, dl - dp)); + int n = JLA.uncheckedEncodeASCII(sa, sp, da, dp, Math.min(sl - sp, dl - dp)); sp += n; dp += n; diff --git a/src/java.base/unix/classes/sun/nio/fs/UnixPath.java b/src/java.base/unix/classes/sun/nio/fs/UnixPath.java index e2f52e701cb..5dfc73f57aa 100644 --- a/src/java.base/unix/classes/sun/nio/fs/UnixPath.java +++ b/src/java.base/unix/classes/sun/nio/fs/UnixPath.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -126,7 +126,7 @@ class UnixPath implements Path { private static byte[] encode(UnixFileSystem fs, String input) { input = fs.normalizeNativePath(input); try { - return JLA.getBytesNoRepl(input, Util.jnuEncoding()); + return JLA.uncheckedGetBytesNoRepl(input, Util.jnuEncoding()); } catch (CharacterCodingException cce) { throw new InvalidPathException(input, "Malformed input or input contains unmappable characters"); diff --git a/src/jdk.charsets/share/classes/sun/nio/cs/ext/EUC_JP.java.template b/src/jdk.charsets/share/classes/sun/nio/cs/ext/EUC_JP.java.template index 56fd7741c5a..4fc0b2796ee 100644 --- a/src/jdk.charsets/share/classes/sun/nio/cs/ext/EUC_JP.java.template +++ b/src/jdk.charsets/share/classes/sun/nio/cs/ext/EUC_JP.java.template @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -309,7 +309,7 @@ public class EUC_JP try { if (enc0201.isASCIICompatible()) { - int n = JLA.encodeASCII(sa, sp, da, dp, Math.min(dl - dp, sl - sp)); + int n = JLA.uncheckedEncodeASCII(sa, sp, da, dp, Math.min(dl - dp, sl - sp)); sp += n; dp += n; }