You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2015/10/28 05:24:27 UTC

[jira] [Commented] (GROOVY-6669) Compile in groovyConsole instantiates class

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

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

GitHub user jwagenleitner opened a pull request:

    https://github.com/apache/incubator-groovy/pull/163

    GROOVY-6669 - Compile in groovyConsole instantiates class

    For scripts that contain Class definitions the `GroovyShell#parse` [[1]](https://github.com/apache/incubator-groovy/blob/d1979d119f805f721600c114466311b928c4c587/src/main/groovy/lang/GroovyShell.java#L700) calls `InvokeHelper#createScript` which creates a new instance in order to bind properties [[2]](https://github.com/apache/incubator-groovy/blob/d1979d119f805f721600c114466311b928c4c587/src/main/org/codehaus/groovy/runtime/InvokerHelper.java#L436-L460).  The compile command should only parse the class to make sure there are no syntax errors so this fix just calls the same `GroovyClassLoader#parseClass` method that the `GroovyShell#run` command uses.
    
    With this change the following will compile:
    
    ```groovy
    class OtherThing {
        OtherThing() {
            def v = null
            v.hashCode()
        }
    }
    ```
    If one of the braces is left off:
    
    ```groovy
     class OtherThing {
        OtherThing() {
            def v = null
            v.hashCode()
        
    }
    ```
    The following compilation error occurs:
    
    ```
    1 compilation error:
    
    expecting '}', found '' at line: 6, column: 2
    ```

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/jwagenleitner/incubator-groovy GROOVY-6669

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-groovy/pull/163.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #163
    
----
commit 2f4039047d27aedf99bc88d506623489cde2f0df
Author: John Wagenleitner <jo...@gmail.com>
Date:   2015-10-28T04:00:01Z

    GROOVY-6669 - Compile in groovyConsole instantiates class
    
    For scripts that contain Class definitions the GroovyShell#parse calls InvokeHelper#createScript which creates a new instance in order to bind properties.  The compile command should only parse the class to make sure there are no syntax errors so this fix just calls the same parseClass method that the GroovyShell#run command uses.

----


> Compile in groovyConsole instantiates class
> -------------------------------------------
>
>                 Key: GROOVY-6669
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6669
>             Project: Groovy
>          Issue Type: Bug
>          Components: Groovy Console
>    Affects Versions: 2.2.2
>            Reporter: Luke Daley
>
> Probably not serious, but put this in groovyConsole and compile…
> {code}
> class OtherThing {
>     OtherThing() {
>         def v = null
>         v.hashCode()
>     }
> }
> {code}
> You'll get an NPE for the v.hashCode() line. If you add another statement before the class def (e.g. def c = null) it doesn't happen.
> Weird.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)