Skip to content

Commit 1f21da7

Browse files
committed
8351462: Improve robustness of String concatenation
Reviewed-by: liach, pminborg, rriggs
1 parent 567c688 commit 1f21da7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/java.base/share/classes/java/lang/StringConcatHelper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2024, Alibaba Group Holding Limited. All Rights Reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -52,6 +52,9 @@ static abstract class StringConcatBase {
5252
byte coder = String.LATIN1;
5353
for (String c : constants) {
5454
length += c.length();
55+
if (length < 0) {
56+
throw new OutOfMemoryError("Total length of constants is out of range");
57+
}
5558
coder |= c.coder();
5659
}
5760
this.constants = constants;

0 commit comments

Comments
 (0)