You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Shil Sinha (JIRA)" <ji...@apache.org> on 2015/12/02 00:44:11 UTC
[jira] [Commented] (GROOVY-7698) @CompileStatic safe-navigation
issue with java property setters
[ https://issues.apache.org/jira/browse/GROOVY-7698?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15034883#comment-15034883 ]
Shil Sinha commented on GROOVY-7698:
------------------------------------
This doesn't appear to be a case of java vs. groovy classes, but rather properties vs. fields with explicitly defined setters. The following example also reproduces the issue:
{code}
class Foo {
private String id
String setId(String id) {
this.id = id
}
}
@groovy.transform.CompileStatic
void test(Foo foo) {
foo?.id = 'new'
}
test(null)
{code}
The cause is the same as what you pointed out in the decompiled code - there's no branching for the null case.
> @CompileStatic safe-navigation issue with java property setters
> ---------------------------------------------------------------
>
> 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)