[
https://issues.apache.org/jira/browse/GROOVY-8200?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16031729#comment-16031729
]
ASF GitHub Bot commented on GROOVY-8200:
----------------------------------------
GitHub user noamt opened a pull request:
https://github.com/apache/groovy/pull/555
GROOVY-8200 - Shorthand |= results in NPE
Fixing the NPE with an explicit test and assignment of the right-hand
boolean operator.
Assigning a primitive boolean variable with null, like `boolean x = null`,
will end up as `false`.
I think it only makes sense to apply the same behavior to the right hand
operator.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/noamt/groovy GroovyGROOVY-8200
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/groovy/pull/555.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 #555
----
commit 11a0b159d8d04f3c1e518613566a1b459ecda44d
Author: noamt <[email protected]>
Date: 2017-05-31T18:57:04Z
GROOVY-8200 - Shorthand |= results in NPE:
Fixing the NPE with an explicit test and assignment of the right-hand
boolean operator.
Assigning a primitive boolean variable with null, like `boolean x = null`,
will end up as `false`.
I think it only makes sense to apply the same behavior to the right hand
operator.
----
> 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,
> shorthand_xor_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)