[ 
https://issues.apache.org/jira/browse/GROOVY-7698?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15061533#comment-15061533
 ] 

ASF GitHub Bot commented on GROOVY-7698:
----------------------------------------

Github user asfgit closed the pull request at:

    https://github.com/apache/groovy/pull/201


> @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
>
> {{@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)

Reply via email to