You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Hammer (JIRA)" <ji...@apache.org> on 2017/05/24 07:52:04 UTC
[jira] [Commented] (GROOVY-8200) Shorthand |= results in NPE
[ https://issues.apache.org/jira/browse/GROOVY-8200?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16022473#comment-16022473 ]
Daniel Hammer commented on GROOVY-8200:
---------------------------------------
@[~blackdrag], I'm sorry but it seems my explanation wasn't clear enough.
{quote}... Similar for the logic and binary and.{quote}
By executing the attached examples you'l be able to confirm that {{x |= null}} throws NPE and {{x &= null}} adheres to Groovy truth.
That's an inconsistency regarding null-handling in the |= shorthand notation and violates the [principle of least astonishment|https://en.wikipedia.org/wiki/Principle_of_least_astonishment].
> Shorthand |= results in NPE
> ---------------------------
>
> Key: GROOVY-8200
> URL: https://issues.apache.org/jira/browse/GROOVY-8200
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.3.11
> Environment: Groovy Version: 2.3.11 JVM: 1.7.0_80 Vendor: Oracle Corporation OS: Linux
> java version "1.7.0_80"
> Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
> Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
> Reporter: Daniel Hammer
> Assignee: Jochen Theodorou
> Attachments: shorthand_and.groovy, shorthand_or_symptom.groovy
>
>
> I've stumbled across some curious behaviour for the shorthand assignment operator in Groovy v2.3.11 (symptom also present in Groovy v2.4.9).
> The following [boolean or logic|^shorthand_or_symptom.groovy], unexpectedly throws {{NullPointerException}}.
> {code}boolean x = null
> // short hand unrolled: x = null || x
> x |= null // -> unexpected NullPointerException
> assert !x{code}
> The same approach for [boolean and logic|^shorthand_and.groovy], performs as expected.
> {code}boolean x = null
> // short hand unrolled: x = null && x
> x &= null
> assert !x{code}
> It's possible to work around the issue with explicit cast.
> {code}x |= null as boolean{code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)