groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7014) A Java compile time error results in a runtime exception in Groovy
Date Sat, 13 Aug 2016 19:03:20 GMT

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

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

Github user jwagenleitner commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/381#discussion_r74690791
  
    --- Diff: src/main/org/codehaus/groovy/control/StaticImportVisitor.java ---
    @@ -317,6 +337,10 @@ protected Expression transformMethodCallExpression(MethodCallExpression
mce) {
             return result;
         }
     
    +    private boolean isInnerClass(ClassNode currentClass) {
    --- End diff --
    
    There was an identical method added to `StaticVerifier`, how about replacing both with
a static method in `ClassNodeUtils`?


> A Java compile time error results in a runtime exception in Groovy
> ------------------------------------------------------------------
>
>                 Key: GROOVY-7014
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7014
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.3.4, 2.4.0-rc-1
>         Environment: Window 7
>            Reporter: Harminder Singh
>            Priority: Minor
>
> A Groovy class with CompileStatic annotation exhibit a different behavior than Java.
 The following code results in a compile time error in Java, but throws a runtime exception
in Groovy.
> {code}
> @CompileStatic
> class Base
> {
>   String getData() { return "ABCD" }
>   Base() { this(getData()) } // Calling an instance method before the class is constructed
>   Base(String arg) {}
> }
> @CompileStatic
> public class GMain
> {
>   public static void main(String[] args)
>   {
>     Base b = new Base();
>   }
> }
> {code}
> Java produces:
> {noformat}
> Java Compiler error: Error:(11, 11) java: cannot reference this before supertype constructor
has been called
> {noformat}
> Groovy produces:
> {noformat}
> Groovy Runtime Error details:
> Exception in thread "main" java.lang.ClassCastException: java.lang.Class cannot be cast
to main.groovy.Base
> 	at main.groovy.Base.<init>(Base.groovy:9)
> 	at main.groovy.Derived.<init>(Derived.groovy)
> 	at main.groovy.GMain.main(Base.groovy:18)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         ......
> {noformat}



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

Mime
View raw message