Skip to content

Commit

Permalink
Explain OutOfMemory error if it occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
mernst authored Jan 2, 2025
1 parent 4b2f77c commit 6a3895a
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,19 @@ public static String asFormat(String format, ConversionCategory... cc)
* @throws IllegalFormatException if the format string is invalid
*/
public static void tryFormatSatisfiability(String format) throws IllegalFormatException {
@SuppressWarnings({
"unused", // called for side effect, to see if it throws an exception
"nullness:argument", // it's not documented, but String.format permits
// a null array, which it treats as matching any format string (null is supplied to each
// format specifier).
"formatter:format.string", // this is a test of format string validity
})
String unused = String.format(format, (Object[]) null);
try {
@SuppressWarnings({
"unused", // called for side effect, to see if it throws an exception
"nullness:argument", // it's not documented, but String.format permits
// a null array, which it treats as matching any format string (null is supplied to each
// format specifier).
"formatter:format.string", // this is a test of format string validity
})
String unused = String.format(format, (Object[]) null);
} catch (OutOfMemoryError e) {
throw new Error(
"OOM while calling String.format on (length " + format.length() + "): " + format);
}
}

/**
Expand Down

0 comments on commit 6a3895a

Please sign in to comment.