RFR: 8366765: [REDO] Rename JavaLangAccess::*NoRepl methods
Volkan Yazici
vyazici at openjdk.org
Thu Sep 4 07:55:50 UTC 2025
On Thu, 4 Sep 2025 07:19:39 GMT, Alan Bateman <alanb at openjdk.org> wrote:
> Can you confirm that the only change from before is the update to src/java.base/share/classes/jdk/internal/foreign/StringSupport.java to deal with the "new" usage there?
@AlanBateman, this PR has *one additional change* to deal with the "new" usage in `StringSupport`:
1. f3e7c130391 Revert the revert
2. 3ea1d5ea009 Deal with `StringSupport`
3. b48def1a22d Further simplify sneaky-throws in `String` (via @dfuch)
The diff compared to JDK-8356439 (#26413 eea50fbc) is as follows:
git diff eea50fbc...b48def1a -- $(git diff --name-only upstream/master | xargs echo)
diff --git a/src/java.base/share/classes/java/lang/String.java b/src/java.base/share/classes/java/lang/String.java
index 8acb8d8514b..54f74266c08 100644
--- a/src/java.base/share/classes/java/lang/String.java
+++ b/src/java.base/share/classes/java/lang/String.java
@@ -1348,7 +1348,7 @@ private static int malformed4(byte[] src, int sp) {
* having to declare the exception
*/
@SuppressWarnings("unchecked")
- private static <E extends Exception> E malformedInputException(int offset, int length) throws E {
+ private static <E extends Exception> E malformedInputException(int offset, int length) {
MalformedInputException mie = new MalformedInputException(length);
String msg = "malformed input offset : " + offset + ", length : " + length;
mie.initCause(new IllegalArgumentException(msg));
@@ -1359,7 +1359,7 @@ private static <E extends Exception> E malformedInputException(int offset, int l
* {@return a new {@link MalformedInputException} for the given malformed
* ASCII string}
*/
- private static MalformedInputException malformedASCII(byte[] val) throws MalformedInputException {
+ private static MalformedInputException malformedASCII(byte[] val) {
int dp = StringCoding.countPositives(val, 0, val.length);
return malformedInputException(dp, 1);
}
@@ -1371,7 +1371,7 @@ private static MalformedInputException malformedASCII(byte[] val) throws Malform
* having to declare the exception
*/
@SuppressWarnings("unchecked")
- private static <E extends Exception> E unmappableCharacterException(int offset) throws E {
+ private static <E extends Exception> E unmappableCharacterException(int offset) {
UnmappableCharacterException uce = new UnmappableCharacterException(1);
String msg = "malformed input offset : " + offset + ", length : 1";
uce.initCause(new IllegalArgumentException(msg, uce));
@@ -1382,7 +1382,7 @@ private static <E extends Exception> E unmappableCharacterException(int offset)
* {@return a new {@link UnmappableCharacterException} for the given
* malformed ASCII string}
*/
- private static UnmappableCharacterException unmappableASCII(byte[] val) throws UnmappableCharacterException {
+ private static UnmappableCharacterException unmappableASCII(byte[] val) {
int dp = StringCoding.countPositives(val, 0, val.length);
return unmappableCharacterException(dp);
}
diff --git a/src/java.base/share/classes/jdk/internal/foreign/StringSupport.java b/src/java.base/share/classes/jdk/internal/foreign/StringSupport.java
index 2f842810aa7..bb6cb2d3915 100644
--- a/src/java.base/share/classes/jdk/internal/foreign/StringSupport.java
+++ b/src/java.base/share/classes/jdk/internal/foreign/StringSupport.java
@@ -73,7 +73,7 @@ private static String readByte(AbstractMemorySegmentImpl segment, long offset, C
final byte[] bytes = new byte[len];
MemorySegment.copy(segment, JAVA_BYTE, offset, bytes, 0, len);
try {
- return JAVA_LANG_ACCESS.uncheckedNewStringNoRepl(bytes, charset);
+ return JAVA_LANG_ACCESS.uncheckedNewStringOrThrow(bytes, charset);
} catch (CharacterCodingException _) {
// use replacement characters for malformed input
return new String(bytes, charset);
@@ -92,7 +92,7 @@ private static String readShort(AbstractMemorySegmentImpl segment, long offset,
byte[] bytes = new byte[len];
MemorySegment.copy(segment, JAVA_BYTE, offset, bytes, 0, len);
try {
- return JAVA_LANG_ACCESS.uncheckedNewStringNoRepl(bytes, charset);
+ return JAVA_LANG_ACCESS.uncheckedNewStringOrThrow(bytes, charset);
} catch (CharacterCodingException _) {
// use replacement characters for malformed input
return new String(bytes, charset);
@@ -111,7 +111,7 @@ private static String readInt(AbstractMemorySegmentImpl segment, long offset, Ch
byte[] bytes = new byte[len];
MemorySegment.copy(segment, JAVA_BYTE, offset, bytes, 0, len);
try {
- return JAVA_LANG_ACCESS.uncheckedNewStringNoRepl(bytes, charset);
+ return JAVA_LANG_ACCESS.uncheckedNewStringOrThrow(bytes, charset);
} catch (CharacterCodingException _) {
// use replacement characters for malformed input
return new String(bytes, charset);
-------------
PR Comment: https://git.openjdk.org/jdk/pull/27084#issuecomment-3252376320
More information about the security-dev
mailing list