8299677: Formatter.format might take a long time to format an integer or floating-point

Reviewed-by: alanb, stsypanov, darcy
This commit is contained in:
Raffaello Giulietti 2023-01-12 19:21:09 +00:00
parent 7a85d95e82
commit 33412c102c
2 changed files with 317 additions and 5 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2023, 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
@ -4596,10 +4596,9 @@ public final class Formatter implements Closeable, Flushable {
}
// apply zero padding
if (width != -1 && Flags.contains(f, Flags.ZERO_PAD)) {
for (int k = sb.length(); k < width; k++) {
sb.insert(begin, zero);
}
if (width > sb.length() && Flags.contains(f, Flags.ZERO_PAD)) {
String zeros = String.valueOf(zero).repeat(width - sb.length());
sb.insert(begin, zeros);
}
return sb;