Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MissingFormatWidthException when using Statistics #72

gtrefs opened this issue Oct 30, 2019 · 3 comments


Copy link

@gtrefs gtrefs commented Oct 30, 2019

Testing Problem

The following code leads to a MissingFormatWidthException:

package de.gtrefs.pbt.chapter3

import de.gtrefs.pbt.chapter3.LibraryTest.Direction.*
import net.jqwik.api.Arbitraries.of
import net.jqwik.api.Arbitraries.oneOf
import net.jqwik.api.ForAll
import net.jqwik.api.Property
import net.jqwik.api.Provide
import net.jqwik.api.Statistics

class LibraryTest {
    @Property fun testSomeLibraryMethod(@ForAll("path") path: List<Direction>) {

    fun path() = oneOf(of(LEFT, RIGHT, UP, DOWN)).list()

    enum class Direction {



java.util.MissingFormatWidthException: %02$d

	at java.base/java.util.Formatter$FormatSpecifier.checkNumeric(
	at java.base/java.util.Formatter$FormatSpecifier.checkInteger(
	at java.base/java.util.Formatter$FormatSpecifier.<init>(
	at java.base/java.util.Formatter.parse(
	at java.base/java.util.Formatter.format(
	at java.base/java.util.Formatter.format(
	at java.base/java.lang.String.format(
	at net.jqwik.engine.execution.CheckedProperty.check(
	at net.jqwik.engine.execution.PropertyMethodExecutor.executeProperty(
	at net.jqwik.engine.execution.PropertyMethodExecutor.executeMethod(
	at net.jqwik.engine.execution.PropertyMethodExecutor.lambda$executePropertyMethod$1(
	at net.jqwik.api.lifecycle.AroundPropertyHook.lambda$static$0(
	at net.jqwik.api.lifecycle.AroundPropertyHook.lambda$null$1(
	at net.jqwik.engine.execution.lifecycle.AutoCloseableHook.aroundProperty(
	at net.jqwik.api.lifecycle.AroundPropertyHook.lambda$around$2(
	at net.jqwik.engine.execution.PropertyMethodExecutor.executePropertyMethod(
	at net.jqwik.engine.execution.PropertyMethodExecutor.execute(
	at net.jqwik.engine.execution.PropertyTaskCreator.executeTestMethod(
	at net.jqwik.engine.execution.PropertyTaskCreator.lambda$createTask$0(
	at net.jqwik.engine.execution.pipeline.ExecutionTask$1.execute(
	at net.jqwik.engine.execution.pipeline.ExecutionPipeline.runToTermination(
	at net.jqwik.engine.execution.JqwikExecutor.execute(
	at net.jqwik.engine.JqwikTestEngine.executeTests(
	at net.jqwik.engine.JqwikTestEngine.execute(
	at org.junit.platform.launcher.core.DefaultLauncher.execute(
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(
	at org.junit.platform.launcher.core.DefaultLauncher.execute(
	at org.junit.platform.launcher.core.DefaultLauncher.execute(
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(
	at com.intellij.rt.execution.junit.JUnitStarter.main(

Suggested Solution

I did not do a proper investigation but my guess is, that the computation of decimal in method createReportEntry in class StatisticsControllerImpl results in a 0, when the counts map has less than 10 entries.

@jlink jlink added the bug label Oct 31, 2019

This comment has been minimized.

Copy link

@jlink jlink commented Oct 31, 2019

It's a bug that I'll fix.

Two remarks anyway.

  1. Your provider method can be simplified to (Java code):

     Arbitrary<List<Direction>> path(){
     	return of(Direction.class).list();
  2. The way you do it you collect statistics on the actual path contents per path size. If you just want statistics on the path size, something like that will suffice:

    Statistics.label("path size").collect(path.size());

    And then the bug will not show up either :-)


This comment has been minimized.

Copy link

@jlink jlink commented Oct 31, 2019

Fix available in 1.2.2-SNAPSHOT

@jlink jlink closed this Oct 31, 2019

This comment has been minimized.

Copy link
Contributor Author

@gtrefs gtrefs commented Nov 1, 2019

Thanks for the remarks, I will improve the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.