You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2019/11/15 16:34:00 UTC
[jira] [Assigned] (GROOVY-8855) Calling Matcher.asBoolean() twice
returns different results
[ https://issues.apache.org/jira/browse/GROOVY-8855?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles reassigned GROOVY-8855:
-----------------------------------
Assignee: Eric Milles
> Calling Matcher.asBoolean() twice returns different results
> -----------------------------------------------------------
>
> Key: GROOVY-8855
> URL: https://issues.apache.org/jira/browse/GROOVY-8855
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 3.0.0-alpha-3, 2.5.3
> Reporter: Szymon Stępniak
> Assignee: Eric Milles
> Priority: Trivial
> Labels: breaking
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> There is one non-deterministic use case of using type coercion from {{java.util.regex.Matcher}} to a {{boolean}}. It was initially reported on Stack Overflow - https://stackoverflow.com/q/52930876/2194470
> And here is an example that shows the problem:
> {code:groovy}
> def pattern = /[a-z]+/
> def input = 'abc'
> def matcher = input =~ pattern
> println matcher as Boolean
> println matcher as Boolean
> {code}
> Output:
> {code:bash}
> true
> false
> {code}
> Solution:
> This problem can be solved by replacing {{matcher.find()}} with {{matcher.find(0)}}, so casting matcher to a boolean does not modify search index and always starts from the beginning.
> I will create a pull request in couple of minutes.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)