8212694: Using Raw String Literals with align() and Integer.MIN_VALUE causes out of memory error
Reviewed-by: smarks, sherman
This commit is contained in:
parent
6a045adbed
commit
7a9db013b7
@ -2967,7 +2967,9 @@ public final class String
|
||||
.mapToInt(String::indexOfNonWhitespace)
|
||||
.min()
|
||||
.orElse(0);
|
||||
return indent(n - outdent, true);
|
||||
// overflow-conscious code
|
||||
int indent = n - outdent;
|
||||
return indent(indent > n ? Integer.MIN_VALUE : indent, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,6 +53,7 @@ public class AlignIndent {
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -154,6 +155,18 @@ public class AlignIndent {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* JDK-8212694: Using Raw String Literals with align() and Integer.MIN_VALUE causes out of memory error
|
||||
*/
|
||||
static void test4() {
|
||||
try {
|
||||
String str = "\n A\n".align(Integer.MIN_VALUE);
|
||||
} catch (OutOfMemoryError ex) {
|
||||
System.err.println("align(Integer.MIN_VALUE) not clipping indentation");
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
public static int indexOfNonWhitespace(String s) {
|
||||
int left = 0;
|
||||
while (left < s.length()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user