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 2018/04/18 09:53:00 UTC
[jira] [Updated] (GROOVY-8472) Final variable analysis doesn't
account for early exit
[ https://issues.apache.org/jira/browse/GROOVY-8472?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King updated GROOVY-8472:
------------------------------
Description:
An example with early return from a method:
{code}
def method(String foo) {
final str
try {
str = foo.trim()
}
catch(e) {
println e
return null
}
int exitCode = str.isInteger() ? str.toInteger() : null
exitCode
//str.isInteger() ? str.toInteger() : null // this doesn't trigger the error
}
println method(null)
{code}
And a slight rearrangement of above:
{code}
def method(String foo) {
def str
try {
return foo.trim()
}
catch(e) {
str = '-1'
}
int exitCode = str.toInteger() // The variable [str] may be uninitialized
exitCode
}
println method(null)
{code}
Another example with a while loop:
{code}
int index
def result = -1
int val = 2
while(true) {
try {
index = 12/val--
}
catch(e) {
break
}
println index // okay
result = index // The variable [index] may be uninitialized
}
println result // should be found but isn't if -1 above is commented out
{code}
was:
An example with early return from a method:
{code}
def method(String foo) {
def str
try {
str = foo.trim()
}
catch(e) {
println e
return null
}
int exitCode = str.isInteger() ? str.toInteger() : null
exitCode
//str.isInteger() ? str.toInteger() : null // this doesn't trigger the error
}
println method(null)
{code}
And a slight rearrangement of above:
{code}
def method(String foo) {
def str
try {
return foo.trim()
}
catch(e) {
str = '-1'
}
int exitCode = str.toInteger() // The variable [str] may be uninitialized
exitCode
}
println method(null)
{code}
Another example with a while loop:
{code}
int index
def result = -1
int val = 2
while(true) {
try {
index = 12/val--
}
catch(e) {
break
}
println index // okay
result = index // The variable [index] may be uninitialized
}
println result // should be found but isn't if -1 above is commented out
{code}
> Final variable analysis doesn't account for early exit
> ------------------------------------------------------
>
> Key: GROOVY-8472
> URL: https://issues.apache.org/jira/browse/GROOVY-8472
> Project: Groovy
> Issue Type: Improvement
> Reporter: Paul King
> Priority: Major
>
> An example with early return from a method:
> {code}
> def method(String foo) {
> final str
> try {
> str = foo.trim()
> }
> catch(e) {
> println e
> return null
> }
> int exitCode = str.isInteger() ? str.toInteger() : null
> exitCode
> //str.isInteger() ? str.toInteger() : null // this doesn't trigger the error
> }
> println method(null)
> {code}
> And a slight rearrangement of above:
> {code}
> def method(String foo) {
> def str
> try {
> return foo.trim()
> }
> catch(e) {
> str = '-1'
> }
> int exitCode = str.toInteger() // The variable [str] may be uninitialized
> exitCode
> }
> println method(null)
> {code}
> Another example with a while loop:
> {code}
> int index
> def result = -1
> int val = 2
> while(true) {
> try {
> index = 12/val--
> }
> catch(e) {
> break
> }
> println index // okay
> result = index // The variable [index] may be uninitialized
> }
> println result // should be found but isn't if -1 above is commented out
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)