Skip to content

Commit 50e31e0

Browse files
Sergey TsypanovBrian Burkhalter
authored andcommitted
8305442: (bf) Direct and view implementations of CharBuffer.toString(int, int) do not need to catch SIOBE
Reviewed-by: alanb, bpb
1 parent 85e3974 commit 50e31e0

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

src/java.base/share/classes/java/nio/ByteBufferAs-X-Buffer.java.template

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -215,18 +215,14 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
215215

216216
public String toString(int start, int end) {
217217
Objects.checkFromToIndex(start, end, limit());
218-
try {
219-
int len = end - start;
220-
char[] ca = new char[len];
221-
CharBuffer cb = CharBuffer.wrap(ca);
222-
CharBuffer db = this.duplicate();
223-
db.position(start);
224-
db.limit(end);
225-
cb.put(db);
226-
return new String(ca);
227-
} catch (StringIndexOutOfBoundsException x) {
228-
throw new IndexOutOfBoundsException();
229-
}
218+
int len = end - start;
219+
char[] ca = new char[len];
220+
CharBuffer cb = CharBuffer.wrap(ca);
221+
CharBuffer db = this.duplicate();
222+
db.position(start);
223+
db.limit(end);
224+
cb.put(db);
225+
return new String(ca);
230226
}
231227

232228

src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -433,18 +433,14 @@ class Direct$Type$Buffer$RW$$BO$
433433

434434
public String toString(int start, int end) {
435435
Objects.checkFromToIndex(start, end, limit());
436-
try {
437-
int len = end - start;
438-
char[] ca = new char[len];
439-
CharBuffer cb = CharBuffer.wrap(ca);
440-
CharBuffer db = this.duplicate();
441-
db.position(start);
442-
db.limit(end);
443-
cb.put(db);
444-
return new String(ca);
445-
} catch (StringIndexOutOfBoundsException x) {
446-
throw new IndexOutOfBoundsException();
447-
}
436+
int len = end - start;
437+
char[] ca = new char[len];
438+
CharBuffer cb = CharBuffer.wrap(ca);
439+
CharBuffer db = this.duplicate();
440+
db.position(start);
441+
db.limit(end);
442+
cb.put(db);
443+
return new String(ca);
448444
}
449445

450446

0 commit comments

Comments
 (0)