[
https://issues.apache.org/jira/browse/GROOVY-7698?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Shil Sinha resolved GROOVY-7698.
--------------------------------
Resolution: Fixed
Assignee: Shil Sinha
Fix Version/s: 2.4.6
> @CompileStatic safe navigation is broken for property style non-synthetic
> setter calls
> --------------------------------------------------------------------------------------
>
> Key: GROOVY-7698
> URL: https://issues.apache.org/jira/browse/GROOVY-7698
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.4.0, 2.4.1, 2.4.2, 2.4.3, 2.4.4, 2.4.5
> Reporter: Leonard Brünings
> Assignee: Shil Sinha
> Fix For: 2.4.6
>
>
> {{@CompileStatic}} does not create correct safe-navigation code for java
> setters when using property syntax. This regression happened with the update
> to 2.4 and affects all released versions up till now. The 2.3.x versions
> produce correct instructions.
> I've created a small demo project to reproduce this issue
> https://github.com/leonard84/groovy-compilestatic-bug
> Here a minimal excerpt to visualize the problem.
> {code:java|title=SafeNavigation.groovy}
> @CompileStatic
> class SafeNavigation {
> void javaSafeNavigation6() {
> DetailJava detailJava = null
> detailJava?.id = 'new'
> }
> }
> {code}
> {code:java|title=DetailJava.java}
> public class DetailJava {
> private String id;
> public String getId() {
> return id;
> }
> public void setId(String id) {
> this.id = id;
> }
> }
> {code}
> Using IntelliJs decompiler (Fernflower)
> {code:java|title=groovy-2.4.x}
> public void javaSafeNavigation6() {
> Object detailJava = null;
> String var2 = "new";
> ((DetailJava)detailJava).setId(var2);
> Object var10001 = null;
> }
> {code}
> {code:java|title=groovy-2.3.x}
> public void javaSafeNavigation6() {
> Object detailJava = null;
> Object var10000;
> if(detailJava != null) {
> ((DetailJava)detailJava).setId("new");
> var10000 = null;
> } else {
> var10000 = null;
> }
> }
> {code}
> As you can see the null check is completely omitted. When using the setter
> directly it works, also reading the value works for both getter and property
> style. It also works correctly for groovy classes.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)