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 2022/04/13 01:00:18 UTC

[jira] [Updated] (GROOVY-10580) Conditionally initialized `final` variables considered maybe uninitialized

     [ https://issues.apache.org/jira/browse/GROOVY-10580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King updated GROOVY-10580:
-------------------------------
    Description: 
Running the following in `groovyConsole`:
{code:groovy}
final int i
final boolean a = true
if (a) {
    i = 1
} else {
    throw new IllegalStateException('a is false')
}
println "i = $i"
{code}

would give me:

{noformat}
1 compilation error:
The variable [i] may be uninitialized
. At [9:15] at line: 9, column: 15
{noformat}

It seems groovyc does not take throwing an exception as a non-reachable branch.

This code is almost a verbatim copy from a java code that is working.

This looks similar to GROOVY-8472, and a few others.

  was:
Running the following in `groovyConsole`:

```
final int i
final boolean a = true
if (a) {
  i = 1
} else {
  throw new IllegalStateException('a is false')
}
println "i = $i"
```

would give me:

```
1 compilation error:

The variable [i] may be uninitialized
. At [9:15]  at line: 9, column: 15
```

It seems groovyc does not take throwing an exception as a non-reachable branch.

This code is almost a verbatim copy from a java code that is working.

This looks similar to GROOVY-8472, and a few others.


> Conditionally initialized `final` variables considered maybe uninitialized
> --------------------------------------------------------------------------
>
>                 Key: GROOVY-10580
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10580
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 4.0.1
>            Reporter: V
>            Priority: Major
>
> Running the following in `groovyConsole`:
> {code:groovy}
> final int i
> final boolean a = true
> if (a) {
>     i = 1
> } else {
>     throw new IllegalStateException('a is false')
> }
> println "i = $i"
> {code}
> would give me:
> {noformat}
> 1 compilation error:
> The variable [i] may be uninitialized
> . At [9:15] at line: 9, column: 15
> {noformat}
> It seems groovyc does not take throwing an exception as a non-reachable branch.
> This code is almost a verbatim copy from a java code that is working.
> This looks similar to GROOVY-8472, and a few others.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)