Skip to content

Commit 6a3895a

Browse files
authored
Explain OutOfMemory error if it occurs
1 parent 4b2f77c commit 6a3895a

File tree

1 file changed

+13
-8
lines changed
  • checker-util/src/main/java/org/checkerframework/checker/formatter/util

1 file changed

+13
-8
lines changed

checker-util/src/main/java/org/checkerframework/checker/formatter/util/FormatUtil.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,19 @@ public static String asFormat(String format, ConversionCategory... cc)
9393
* @throws IllegalFormatException if the format string is invalid
9494
*/
9595
public static void tryFormatSatisfiability(String format) throws IllegalFormatException {
96-
@SuppressWarnings({
97-
"unused", // called for side effect, to see if it throws an exception
98-
"nullness:argument", // it's not documented, but String.format permits
99-
// a null array, which it treats as matching any format string (null is supplied to each
100-
// format specifier).
101-
"formatter:format.string", // this is a test of format string validity
102-
})
103-
String unused = String.format(format, (Object[]) null);
96+
try {
97+
@SuppressWarnings({
98+
"unused", // called for side effect, to see if it throws an exception
99+
"nullness:argument", // it's not documented, but String.format permits
100+
// a null array, which it treats as matching any format string (null is supplied to each
101+
// format specifier).
102+
"formatter:format.string", // this is a test of format string validity
103+
})
104+
String unused = String.format(format, (Object[]) null);
105+
} catch (OutOfMemoryError e) {
106+
throw new Error(
107+
"OOM while calling String.format on (length " + format.length() + "): " + format);
108+
}
104109
}
105110

106111
/**

0 commit comments

Comments
 (0)