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

Trying to randomize an empty Enum fails with an IllegalArgumentException #393

Closed
LeJeanbono opened this issue Feb 28, 2020 · 1 comment
Closed
Labels
Milestone

Comments

@LeJeanbono
Copy link
Contributor

Hi,
I have to randomize an object with an empty enum :

public enum MyEnum {
}

Can we consider getRandomValue of EnumRandomizer return null if enumConstants.size() equal zero?

Actually it throw

Caused by: java.lang.IllegalArgumentException: bound must be positive
	at java.base/java.util.Random.nextInt(Random.java:388)
	at org.jeasy.random.randomizers.misc.EnumRandomizer.getRandomValue(EnumRandomizer.java:120)
	at org.jeasy.random.EasyRandom.randomize(EasyRandom.java:179)

Can make a PR.

@fmbenhassine
Copy link
Member

Good catch, even though I don't see the added value of an empty enum. But still, Easy Random should not crash with an IAE.

Can make a PR.

You are welcome!

@fmbenhassine fmbenhassine added this to the 4.2.0 milestone Mar 4, 2020
@fmbenhassine fmbenhassine changed the title Empty Enum Trying to randomize an empty Enum fails with an IllegalArgumentException Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants