[
https://issues.apache.org/jira/browse/GROOVY-10535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17531288#comment-17531288
]
Eric Milles edited comment on GROOVY-10535 at 5/3/22 4:45 PM:
--------------------------------------------------------------
[~paulk] [~daniel_sun] Can something be added to
https://groovy-lang.org/indy.html to explain the caching strategy of indy mode
and the various system properties that influence it? I don't fully understand
the cache scheme and my intuition says that the Selector logic that constructs
method handles should be run for each new set of arguments if the handle
depends on the characteristics of the argument type(s).
was (Author: emilles):
[~paulk] [~daniel_sun] Can something be added to
https://groovy-lang.org/indy.html to explain the caching strategy of indy mode
and the various system properties that influence it? I don't fully understand
the cache scheme and my intuition says that the Selector logic that constructs
method handles should be run for each new set of arguments.
> IF condition on empty Collection has different behavior than null Collection
> ----------------------------------------------------------------------------
>
> Key: GROOVY-10535
> URL: https://issues.apache.org/jira/browse/GROOVY-10535
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 3.0.10
> Environment: Groovy 3.0.10/OpenJDK 17.0.2 - Ubuntu 21.10
> Reporter: Rodolfo Yanke
> Assignee: Eric Milles
> Priority: Major
> Fix For: 5.0.0-alpha-1, 4.0.3
>
>
> I believe this code should print "something" but doesn't work:
> {code:java}
> @CompileStatic
> class NotWorkingExample {
> static void main(String[] args) {
> Collection<String> values = null
> for (i in 0..<200_000) {
> printSomethingIfNotEmpty(values)
> }
> //never printed but it should
> values = ['A']
> printSomethingIfNotEmpty(values)
> }
> static printSomethingIfNotEmpty(Collection<String> values) {
> if(values) {
> println 'something'
> }
> }
> }
> {code}
> This one does print "something" because we pass an empty collection []
> instead of null:
> {code:java}
> @CompileStatic
> class ItWorks {
> static void main(String[] args) {
> Collection<String> values = []
> for (i in 0..<200_000) {
> printSomethingIfNotEmpty(values)
> }
> //it works because [] was passed in the previous 200k calls
> values = ['A']
> printSomethingIfNotEmpty(values)
> }
> static printSomethingIfNotEmpty(Collection<String> values) {
> if(values) {
> println 'something'
> }
> }
> }{code}
> Some optimization is done differently when the condition is skipped too many
> times. Both classes should output "something" on the last method call.
> Thank you for the support.
--
This message was sent by Atlassian Jira
(v8.20.7#820007)