[ https://issues.apache.org/jira/browse/GROOVY-8346?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17050561#comment-17050561 ]
Brian Ray commented on GROOVY-8346: ----------------------------------- [~paulk] would you suggest a distinct issue for this use case? {code:groovy} import spock.lang.* class FinalVariableAnalysisSpec extends Specification { @Issue( [ "GROOVY-8346", "spockframework/spock#1017" ] ) def "final String variable split across Spock blocks"() { when: "we define a finalized variable in this block" final foo = "bar" //Oddly enough if this block is commented and the downstream and: block //becomes a then: block, then the FVA problem goes away. And I //think this has to be a thrown(E) or notThrown(E) flavor of assertion. A //simple assertion a la 1 == 1 will not trigger the FVA problem. Nor will //another "wrapper" variant like verifyAll { 1 == 1 }. then: "no exception" notThrown(IllegalArgumentException) and: "we should be able to validate it in a later block" foo == "bar" } } //[...]FinalVariableAnalysisSpec.groovy: 20: The variable [foo] may be uninitialized //. At [20:5] @ line 20, column 5. // foo == "bar" // //With: // groovy:2.5.9:indy // spock-core:1.3-groovy-2.5 {code} I believe under the covers Spock is ASTing verification blocks into {{try-catch}} blocks, and know that there are one or two issues on this JIRA to do with FVA and {{try-catch}} (GROOVY-8801 e.g.). So I could tag this on to one of those. Relatedly I suspect the Spock project would argue against mitigating this in their framework given [spock#1017|https://github.com/spockframework/spock/issues/1017]. But I could try there. Last as much as I'm a fan of immutability, I wouldn't mind sweeping all my tests and switching these to {{def}}. Immutability in test source isn't quite as important as in application sources. > The variable [XXX] may be uninitialized > ---------------------------------------- > > Key: GROOVY-8346 > URL: https://issues.apache.org/jira/browse/GROOVY-8346 > Project: Groovy > Issue Type: Bug > Affects Versions: 2.5.0-beta-1, 2.5.0-beta-2 > Reporter: paolo di tommaso > Priority: Major > > I'm getting several errors when compiling Groovy 2.5.0-beta-2 (and beta-1) > related to final variable initialisations. > For example: > {code} > [:compileTestGroovy] WorkflowMetadataTest.groovy: 43: The variable [begin] > may be uninitialized > [:compileTestGroovy] . At [43:15] @ line 43, column 15. > [:compileTestGroovy] final begin = new Date() > [:compileTestGroovy] ^ > {code} > Related to the following line > {code} > final begin = new Date() > {code} > See also > [here|https://github.com/nextflow-io/nextflow/blob/master/src/test/groovy/nextflow/script/WorkflowMetadataTest.groovy#L43-43], > > [here|https://github.com/nextflow-io/nextflow/blob/master/src/test/groovy/nextflow/file/SequentialFileStoreTest.groovy#L40-40] > > [here|https://github.com/nextflow-io/nextflow/blob/master/src/test/groovy/nextflow/cloud/CloudConfigTest.groovy#L299-299] > and > [here|https://github.com/nextflow-io/nextflow/blob/master/src/test/groovy/nextflow/processor/PublishDirTest.groovy#L96-96] > -- This message was sent by Atlassian Jira (v8.3.4#803005)