[
https://issues.apache.org/jira/browse/GROOVY-8552?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King updated GROOVY-8552:
------------------------------
Description:
Another example with a while loop:
{code}
int index
final 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) {
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) {
final 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
final 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 for while loop
> ---------------------------------------------------------------------
>
> Key: GROOVY-8552
> URL: https://issues.apache.org/jira/browse/GROOVY-8552
> Project: Groovy
> Issue Type: Improvement
> Reporter: Paul King
> Priority: Major
>
> Another example with a while loop:
> {code}
> int index
> final 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)