Skip to content

MissingFormatWidthException when using Statistics #72

@gtrefs

Description

@gtrefs

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>) {
        Statistics.label(path.size.toString()).collect(path)
    }

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

    enum class Direction {
        LEFT, RIGHT, UP, DOWN
    }

}

Stacktrace


java.util.MissingFormatWidthException: %02$d

	at java.base/java.util.Formatter$FormatSpecifier.checkNumeric(Formatter.java:3176)
	at java.base/java.util.Formatter$FormatSpecifier.checkInteger(Formatter.java:3136)
	at java.base/java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2874)
	at java.base/java.util.Formatter.parse(Formatter.java:2713)
	at java.base/java.util.Formatter.format(Formatter.java:2655)
	at java.base/java.util.Formatter.format(Formatter.java:2609)
	at java.base/java.lang.String.format(String.java:2897)
	at net.jqwik.engine.properties.StatisticsCollectorImpl.formatEntry(StatisticsCollectorImpl.java:88)
	at net.jqwik.engine.properties.StatisticsCollectorImpl.createReportEntry(StatisticsCollectorImpl.java:80)
	at net.jqwik.engine.properties.StatisticsCollectorImpl.report(StatisticsCollectorImpl.java:33)
	at net.jqwik.engine.properties.GenericProperty.reportStatistics(GenericProperty.java:45)
	at net.jqwik.engine.properties.GenericProperty.check(GenericProperty.java:40)
	at net.jqwik.engine.execution.CheckedProperty.check(CheckedProperty.java:39)
	at net.jqwik.engine.execution.PropertyMethodExecutor.executeProperty(PropertyMethodExecutor.java:134)
	at net.jqwik.engine.execution.PropertyMethodExecutor.executeMethod(PropertyMethodExecutor.java:122)
	at net.jqwik.engine.execution.PropertyMethodExecutor.lambda$executePropertyMethod$1(PropertyMethodExecutor.java:102)
	at net.jqwik.api.lifecycle.AroundPropertyHook.lambda$static$0(AroundPropertyHook.java:17)
	at net.jqwik.api.lifecycle.AroundPropertyHook.lambda$null$1(AroundPropertyHook.java:32)
	at net.jqwik.engine.execution.lifecycle.AutoCloseableHook.aroundProperty(AutoCloseableHook.java:15)
	at net.jqwik.api.lifecycle.AroundPropertyHook.lambda$around$2(AroundPropertyHook.java:37)
	at net.jqwik.engine.execution.PropertyMethodExecutor.executePropertyMethod(PropertyMethodExecutor.java:100)
	at net.jqwik.engine.execution.PropertyMethodExecutor.execute(PropertyMethodExecutor.java:46)
	at net.jqwik.engine.execution.PropertyTaskCreator.executeTestMethod(PropertyTaskCreator.java:79)
	at net.jqwik.engine.execution.PropertyTaskCreator.lambda$createTask$0(PropertyTaskCreator.java:38)
	at net.jqwik.engine.execution.pipeline.ExecutionTask$1.execute(ExecutionTask.java:24)
	at net.jqwik.engine.execution.pipeline.ExecutionPipeline.runToTermination(ExecutionPipeline.java:81)
	at net.jqwik.engine.execution.JqwikExecutor.execute(JqwikExecutor.java:46)
	at net.jqwik.engine.JqwikTestEngine.executeTests(JqwikTestEngine.java:68)
	at net.jqwik.engine.JqwikTestEngine.execute(JqwikTestEngine.java:57)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:74)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)


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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions