adoptium / adoptium/bumblebench
FormatFlagsConversionMismatchException when benchmark class name is exactly 5 characters long
- Dominant language
- Java
- Stars
- 27
- Forks
- 32
- PR merge metrics
- No merged PRs in 30d
Description
When running a microbenchmark with a benchmark class name of 5 characters, the following runtime exception occurs:
```
Exception in thread "main" java.lang.RuntimeException: java.util.FormatFlagsConversionMismatchException: Conversion = s, Flags = 0
at net.adoptopenjdk.bumblebench.core.Launcher.runBumbleMainOn(Launcher.java:64)
at net.adoptopenjdk.bumblebench.core.Launcher.main(Launcher.java:55)
Caused by: java.util.FormatFlagsConversionMismatchException: Conversion = s, Flags = 0
at java.base/java.util.Formatter$FormatSpecifier.failMismatch(Formatter.java:4511)
at java.base/java.util.Formatter$FormatSpecifier.checkBadFlags(Formatter.java:3276)
at java.base/java.util.Formatter$FormatSpecifier.checkGeneral(Formatter.java:3235)
at java.base/java.util.Formatter$FormatSpecifier.(Formatter.java:2999)
at java.base/java.util.Formatter.parse(Formatter.java:2849)
at java.base/java.util.Formatter.format(Formatter.java:2774)
at java.base/java.util.Formatter.format(Formatter.java:2728)
at java.base/java.lang.String.format(String.java:5162)
at net.adoptopenjdk.bumblebench.core.BumbleBench.run(BumbleBench.java:266)
at net.adoptopenjdk.bumblebench.core.MicroBench.run(MicroBench.java:107)
at net.adoptopenjdk.bumblebench.core.BumbleBench.bumbleMain(BumbleBench.java:287)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:586)
at net.adoptopenjdk.bumblebench.core.Launcher.runBumbleMainOn(Launcher.java:61)
... 1 more
```
This exception occurs in [`BumbleBench.run()`](https://github.com/adoptium/bumblebench/blob/master/net/adoptopenjdk/bumblebench/core/BumbleBench.java#L266-L272), where the lines reporting the score and uncertainty at the end of the run are constructed and printed.
In order to ensure an aesthetic alignment of the two lines, a number of spaces are sometimes added to the beginning of the second line, as in this example:
```
TrigBench score: 24703088.000000 (24.70M 1702.2%)
uncertainty: 1.9%
```
However, the line of code which produces the correct number of spaces assumes that the name of the benchmark is at least 6 characters:
```java
String spaces = String.format("%" + (_name.length()-5) + "s", "");
```
Since `%0s` is not a valid string format specifier, if the class name is 5 characters long, we get a crash. Although obviously less significant, if the class name is 4 characters or less, we don't get a crash, but we also don't get the alignment that this code intends to produce. For example, here is the output for a benchmark with a 4 character name, `Test`:
```
Test score: 7955413.000000 (7.955M 1588.9%)
uncertainty: 1.1%
```
The following simple benchmark can reproduce this crash:
```java
// Clone.java
package net.adoptopenjdk.bumblebench.stringcoding;
import net.adoptopenjdk.bumblebench.core.MicroBench;
public final class Clone extends MicroBench {
protected long doBatch(long numIterations) throws InterruptedException {
for (long i = 0; i < numIterations; i++) {}
return numIterations;
}
}
```
Contributor guide
Research direction
Start in net/adoptopenjdk/bumblebench/core/BumbleBench.java at run(), around lines 266–272, and reproduce the issue with the provided Clone benchmark. Verify the score and uncertainty lines for benchmark names of five, four, and fewer characters; done means no formatting exception and the intended alignment is preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- performance, testing, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100