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

The JqwikJavaArbitraryResolver cannot generate empty strings if there is a constraint on the string #1088

Open
ghost opened this issue Nov 14, 2024 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@ghost
Copy link

ghost commented Nov 14, 2024

Describe the bug

When setting a constraint for a String, the arbitrary returned by the JqwikJavaArbitraryResolver will never generate an empty string, although the constraint may allow it.

With the following class, the string field will never get a string with length = 0, although I would expect it

class Example(
    @field:Size(min=0, max=100)
    val stringField: String
)

And with the following, it will throw net.jqwik.api.TooManyFilterMissesException

class Example(
    @field:Size(min=0, max=0)
    val stringField: String
)

I think that the problem can be in the filter at the end, that prevents empty strings to be generated.
https://github.com/naver/fixture-monkey/blob/1.1.1/fixture-monkey-api/src/main/java/com/navercorp/fixturemonkey/api/jqwik/JqwikJavaArbitraryResolver.java#L117

Your environment

  • version of Fixture Monkey: 1.1.1
  • version of Java: 21.0.2
  • version of Kotlin: 2.0.21

Steps to reproduce

https://github.com/jagilpe/fixture-monkey-bug/blob/main/src/test/kotlin/FixtureMonkeyBugTest.kt#L25

Expected behaviour

The test should be green

Actual behaviour

The test ends with:

Given type class com.gilpereda.examples.FixtureMonkeyBugTest$Example could not be generated. Check the ArbitraryIntrospector used or the APIs used in the ArbitraryBuilder.
java.lang.IllegalArgumentException: Given type class com.gilpereda.examples.FixtureMonkeyBugTest$Example could not be generated. Check the ArbitraryIntrospector used or the APIs used in the ArbitraryBuilder.
	at com.navercorp.fixturemonkey.resolver.ResolvedCombinableArbitrary.combined(ResolvedCombinableArbitrary.java:89)
	at com.navercorp.fixturemonkey.builder.DefaultArbitraryBuilder.sample(DefaultArbitraryBuilder.java:486)
	at com.navercorp.fixturemonkey.FixtureMonkey.lambda$giveMe$3(FixtureMonkey.java:163)
	at java.base/java.util.stream.StreamSpliterators$InfiniteSupplyingSpliterator$OfRef.tryAdvance(StreamSpliterators.java:1367)
	at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
	at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at com.navercorp.fixturemonkey.FixtureMonkey.giveMe(FixtureMonkey.java:171)
	at com.navercorp.fixturemonkey.FixtureMonkey.giveMeOne(FixtureMonkey.java:179)
	at com.gilpereda.examples.FixtureMonkeyBugTest.should generate an empty string(FixtureMonkeyBugTest.kt:32)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: com.navercorp.fixturemonkey.api.exception.RetryableFilterMissException: net.jqwik.api.TooManyFilterMissesException: Filtering [net.jqwik.engine.properties.arbitraries.randomized.ContainerGenerator@1abebef3] missed more than 10000 times.
	at com.navercorp.fixturemonkey.api.arbitrary.FilteredCombinableArbitrary.newRetryableFilterMissException(FilteredCombinableArbitrary.java:211)
	at com.navercorp.fixturemonkey.api.arbitrary.FilteredCombinableArbitrary.combined(FilteredCombinableArbitrary.java:104)
	at com.navercorp.fixturemonkey.api.arbitrary.ObjectCombinableArbitrary.lambda$combined$0(ObjectCombinableArbitrary.java:51)
	at java.base/java.util.HashMap.forEach(HashMap.java:1429)
	at com.navercorp.fixturemonkey.api.arbitrary.ObjectCombinableArbitrary.combined(ObjectCombinableArbitrary.java:50)
	at com.navercorp.fixturemonkey.api.arbitrary.NullInjectCombinableArbitrary.combined(NullInjectCombinableArbitrary.java:46)
	at com.navercorp.fixturemonkey.api.arbitrary.TraceableCombinableArbitrary.combined(TraceableCombinableArbitrary.java:42)
	at com.navercorp.fixturemonkey.api.arbitrary.FilteredCombinableArbitrary.combined(FilteredCombinableArbitrary.java:73)
	at com.navercorp.fixturemonkey.resolver.ResolvedCombinableArbitrary.combined(ResolvedCombinableArbitrary.java:77)
	... 16 more
Caused by: net.jqwik.api.TooManyFilterMissesException: Filtering [net.jqwik.engine.properties.arbitraries.randomized.ContainerGenerator@1abebef3] missed more than 10000 times.
	at net.jqwik.engine.properties.arbitraries.randomized.FilteredGenerator.nextUntilAccepted(FilteredGenerator.java:38)
	at net.jqwik.engine.properties.arbitraries.randomized.FilteredGenerator.next(FilteredGenerator.java:22)
	at net.jqwik.engine.facades.SampleStreamFacade.lambda$sampleStream$2(SampleStreamFacade.java:68)
	at net.jqwik.engine.execution.lifecycle.CurrentTestDescriptor.runWithDescriptor(CurrentTestDescriptor.java:17)
	at net.jqwik.engine.facades.SampleStreamFacade.runInDescriptor(SampleStreamFacade.java:60)
	at net.jqwik.engine.facades.SampleStreamFacade.lambda$wrapInDescriptor$1(SampleStreamFacade.java:55)
	at java.base/java.util.stream.StreamSpliterators$InfiniteSupplyingSpliterator$OfRef.tryAdvance(StreamSpliterators.java:1367)
	at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
	at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
	at net.jqwik.api.Arbitrary.sample(Arbitrary.java:423)
	at com.navercorp.fixturemonkey.api.jqwik.ArbitraryUtils.lambda$toCombinableArbitrary$0(ArbitraryUtils.java:38)
	at com.navercorp.fixturemonkey.api.lazy.UnSafeLazyArbitraryImpl.getValue(UnSafeLazyArbitraryImpl.java:53)
	at com.navercorp.fixturemonkey.api.arbitrary.LazyCombinableArbitrary.combined(LazyCombinableArbitrary.java:40)
	at com.navercorp.fixturemonkey.api.arbitrary.NullInjectCombinableArbitrary.combined(NullInjectCombinableArbitrary.java:46)
	at com.navercorp.fixturemonkey.api.arbitrary.TraceableCombinableArbitrary.combined(TraceableCombinableArbitrary.java:42)
	at com.navercorp.fixturemonkey.api.arbitrary.FilteredCombinableArbitrary.combined(FilteredCombinableArbitrary.java:73)
@ghost ghost added the bug Something isn't working label Nov 14, 2024
@seongahjo seongahjo added this to the 1.1.3 milestone Nov 15, 2024
@seongahjo
Copy link
Contributor

@jagilpe
Hello, thank you for reporting an issue.

It is fixed in 1.1.3, please check it out!

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant