You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2019/12/09 21:37:02 UTC

[jira] [Closed] (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 ]

Paul King closed GROOVY-8855.
-----------------------------

> 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
>             Fix For: 3.0.0-rc-2
>
>          Time Spent: 40m
>  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)