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
It was a bit hard to write a good title, I'll try my best to explain the issue.
I noticed that RandomizerProxy.invoke threw a IllegalAccessException when I passed a Supplier as a lambda to EnhancedRandomBuilder.randomize. I'm not completely sure but I think the java compiler desugars lambdas to anonymous inner classes which in turn are transformed into package private inner classes. If you change RandomizerProxyTest.theRandomizerProxyShouldBehaveLikeTheSupplier to use a lambda the test will pass. I think this is because RandomizerProxyTest and RandomizerProxy are both in the same package, if you move RandomizerProxyTest to another package the exception I was talking about earlier is thrown and the test fails.
You could just pass Randomizer instead of Supplier and everything would be fine but I like the semantics of the latter when I want to return something that isn't actually random and if you already support Supplier then you might as well support them as lambdas as well.
I hope you understood my explanation, it's a bit hard and confusing to explain. I have a solution for this problem and I'm ready to make a PR if you want. I think it will be easier to understand if you read my PR.
Thanks for this great library by the way, I use it all the time.
The text was updated successfully, but these errors were encountered:
io.github.benas.randombeans.api.ObjectGenerationException: Unable to generate a random instance of type class java.lang.String
at io.github.benas.randombeans.EnhancedRandomImpl.doPopulateBean(EnhancedRandomImpl.java:128)
at io.github.benas.randombeans.EnhancedRandomImpl.nextObject(EnhancedRandomImpl.java:77)
at com.test.RandomizerProxyTest.test(RandomizerProxyTest.java:41)
Caused by: java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy4.getRandomValue(Unknown Source)
at io.github.benas.randombeans.EnhancedRandomImpl.doPopulateBean(EnhancedRandomImpl.java:99)
... 25 more
Caused by: java.lang.IllegalAccessException: Class io.github.benas.randombeans.RandomizerProxy can not access a member of class com.test.RandomizerProxyTest$$Lambda$1/1100439041 with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
That is correct, with the exception that your first snippet actually works as long as it's located in the same package as RandomizerProxy. I'll create a PR once I'm home from work.
Hi
It was a bit hard to write a good title, I'll try my best to explain the issue.
I noticed that RandomizerProxy.invoke threw a IllegalAccessException when I passed a Supplier as a lambda to EnhancedRandomBuilder.randomize. I'm not completely sure but I think the java compiler desugars lambdas to anonymous inner classes which in turn are transformed into package private inner classes. If you change RandomizerProxyTest.theRandomizerProxyShouldBehaveLikeTheSupplier to use a lambda the test will pass. I think this is because RandomizerProxyTest and RandomizerProxy are both in the same package, if you move RandomizerProxyTest to another package the exception I was talking about earlier is thrown and the test fails.
You could just pass Randomizer instead of Supplier and everything would be fine but I like the semantics of the latter when I want to return something that isn't actually random and if you already support Supplier then you might as well support them as lambdas as well.
I hope you understood my explanation, it's a bit hard and confusing to explain. I have a solution for this problem and I'm ready to make a PR if you want. I think it will be easier to understand if you read my PR.
Thanks for this great library by the way, I use it all the time.
The text was updated successfully, but these errors were encountered: