You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found a little bug when I use your wonderful tool on a large String.
I am using version 3.7.0.
This is an extract of my class:
@Size(max=2147483647)
public String getName() {
return name;
}
The impacted line is:
int length = minLength + random.nextInt(maxLength - minLength + 1);
the calculated length is: -2147483648 but the length MUST be positive !
This is the stack trace I've got:
Exception in thread "main" io.github.benas.randombeans.api.ObjectGenerationException: Unable to generate a random instance of type class a.b.Person
at io.github.benas.randombeans.EnhancedRandomImpl.doPopulateBean(EnhancedRandomImpl.java:124)
at io.github.benas.randombeans.EnhancedRandomImpl.nextObject(EnhancedRandomImpl.java:77)
at ave.bertrand.MainClass.main(MainClass.java:18)
Caused by: java.lang.IllegalArgumentException: bound must be positive
at java.util.Random.nextInt(Random.java:388)
at io.github.benas.randombeans.randomizers.text.StringRandomizer.getRandomValue(StringRandomizer.java:256)
at io.github.benas.randombeans.randomizers.text.StringRandomizer.getRandomValue(StringRandomizer.java:36)
at io.github.benas.randombeans.FieldPopulator.populateField(FieldPopulator.java:78)
at io.github.benas.randombeans.EnhancedRandomImpl.populateField(EnhancedRandomImpl.java:158)
at io.github.benas.randombeans.EnhancedRandomImpl.populateFields(EnhancedRandomImpl.java:149)
at io.github.benas.randombeans.EnhancedRandomImpl.doPopulateBean(EnhancedRandomImpl.java:120)
... 2 more
The text was updated successfully, but these errors were encountered:
2147483647 is actually the value of Integer.MAX_VALUE, so @Size(max=2147483647) is equivalent to @Size. This is perfectly valid value to be specified as a user, and the issue happens because Integer.MAX_VALUE + 1 == Integer.MIN_VALUE (explained in details on SO here).
The +1 in the formula was introduced in 587e600 to fix the case where the generated String can never have the max length.
I fixed the issue and now the random String length is correctly calculated. However, when the random String length is too high, a OOM might happen and random beans can do nothing to prevent it (see #289).
The fix has been deployed to maven central in 3.8.0-SNAPSHOT. I'm closing this issue for now. @AVE-cesar It would be great if you give the fix a try (see here on how to use the snapshot version). Please add a comment here if you find any issue.
I've found a little bug when I use your wonderful tool on a large String.
I am using version 3.7.0.
This is an extract of my class:
The impacted line is:
the calculated length is: -2147483648 but the length MUST be positive !
This is the stack trace I've got:
The text was updated successfully, but these errors were encountered: