groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8855) Calling Matcher.asBoolean() twice returns different results
Date Tue, 23 Oct 2018 11:23:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8855?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16660456#comment-16660456
] 

ASF GitHub Bot commented on GROOVY-8855:
----------------------------------------

GitHub user wololock opened a pull request:

    https://github.com/apache/groovy/pull/815

    GROOVY-8855: Matcher.asBoolean() does not rely on matchers internal search index anymore

    Fixes https://issues.apache.org/jira/browse/GROOVY-8855

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/wololock/groovy GROOVY-8855

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/815.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #815
    
----
commit 86af86e0739e00374cd691df7c21ac7d9e3fe835
Author: Szymon Stepniak <szymon.stepniak@...>
Date:   2018-10-23T11:21:22Z

    GROOVY-8855: Matcher.asBoolean() does not rely on matchers internal search index anymore

----


> 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
>            Priority: Trivial
>
> 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
(v7.6.3#76005)

Mime
View raw message