groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Sun (Jira)" <j...@apache.org>
Subject [jira] [Resolved] (GROOVY-9270) Using "instanceof boolean" or using a Trait will cause the compiled code to not work with OSGi/maven-bundle-plugin/bnd
Date Fri, 11 Oct 2019 13:57:00 GMT

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

Daniel Sun resolved GROOVY-9270.
--------------------------------
    Resolution: Fixed

The proposed PR was merged. Thanks!

> Using "instanceof boolean" or using a Trait will cause the compiled code to not work
with  OSGi/maven-bundle-plugin/bnd
> -----------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-9270
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9270
>             Project: Groovy
>          Issue Type: Bug
>          Components: class generator, Compiler
>    Affects Versions: 3.0.0-beta-3
>         Environment: OSX (Mojave) JDK 11.
>            Reporter: Tommy Svensson
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 3.0.0-rc-1
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> Using "instanceof boolean" or using a Trait will cause the compiled code to not work
with OSGi/maven-bundle-plugin/bnd.
> Edited text:
> I made 2 test classes one Ok and one that bnd says has code in default package:
> OK:
> {{public void test(Object o) {}}
>  {{    CallSite[] var2 = $getCallSiteArray();}}
>  {{    if (o instanceof Boolean){            }}
>  {{        var2[0].callCurrent(this, "boolean");}}
>           }
> }
> Fail:
>  public void test(Object o) {
>  {{    CallSite[] var2 = $getCallSiteArray();}}
>  {{    if (o instanceof boolean) {}}
>  {{        var2[0].callCurrent(this, "boolean");}}
>           }
>  {{}}}
> The rest of the class is identical.
>  
> These comes from decompiled .class files and thus are Java, but they were compiled from
groovy classes. Now the question is, where do java handle autoboxing ? If it is the compiler
then this would explain the result. The "boolean" is a primitive and have no package.
> If the compiler is responsible for handling this, the problem lies with Groovy which
has clearly not boxed the "boolean" in  a "Boolean".  
> If its the JDK that handles autoboxing runtime then both cases should behave the same,
which they are not.
> Bnd ([https://bnd.bndtools.org)|https://bnd.bndtools.org)/] tries to import from "."
in the "Fail" case and reports: "The default package '.' is not permitted by the Import-Package
syntax."  
> I took these 2 test groovy files and moved them to a Java maven module, changed .groovy
to .java, added ;, etc to make them valid java. Java will not compile the fail case complaining
about "o instanceof boolean" no being valid. "Inconvertible types, cannot cast boolean to
Object" is the message you get. 
> Running the "if(o instanceof booelan)" code that Groovy have happily compiled, results
in: java.lang.NoClassDefFoundError: boolean
> I think that Groovy should report the same compilation error, rather than accept something
clearly incorrect and fail runtime.
> Even with @CompileStatic and @TypeChecked annotations Groovy compiles the code without
errors.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Mime
View raw message