You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Tommy Svensson (Jira)" <ji...@apache.org> on 2022/06/08 16:10:00 UTC

[jira] [Comment Edited] (GROOVY-10652) Code that worked in Groovy 3 throws exception in Groovy 4.0.1

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

Tommy Svensson edited comment on GROOVY-10652 at 6/8/22 4:09 PM:
-----------------------------------------------------------------

Hmm, this was wrong for Groovy 3 also, but there it just happened to work! When I add the 4.0.1 dependency in the appropriate place, it now works, I'm swearing out loud over this. 




was (Author: tombensve):
Hmm, this was wrong for Groovy 3 also, but there it just happened to work! When I add the 4.0.1 dependency in the appropriate place, it now works.



> Code that worked in Groovy 3 throws exception in Groovy 4.0.1
> -------------------------------------------------------------
>
>                 Key: GROOVY-10652
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10652
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Tommy Svensson
>            Priority: Major
>
> The following code is an example of this fail:
> {code:groovy}
>     @NotNull Line removeBegNumberDot() {
>        Line line = this
>         if (this.origLine.trim() =~ /^[0-9]+\..*/){ final int ix = this.origLine.indexOf(".") 
>         // As of Groovy 4 this no longer works!
>         line = newLine(this.origLine[(ix+1)..-1]) // <-- 
>        }
>         line
>     }
> {code}
> This method is part of class Line! 
> Results in the following stack trace:
> {code}
> java.lang.NoSuchMethodError: 'void groovy.lang.IntRange.<init>(boolean, boolean, int, int)'
> at se.natusoft.doc.markdown.io.Line.removeBegNumberDot(Line.groovy:160)
> at ...
> {code}
> In Groovy 3 this both compiles and executes without problem, but with Groovy 4.0.1 it does compile, but gets above exception when executed. It looks like there is functionality missing the the Groovy 4.0.1 runtime library for {{groovy.lang.IntRange}}. But it is the Groovy 4.0.1 compiler that has produced the code that uses {{IntRange}}, so it can possibly produce the wrong code.
> For now I have to rewrite this method doing it the Java way rather than the Groovy way.
> Again, the code does compile, but the compiler produces code that can't be executed.
> It is being built for JDK 11 byte code. Don't believe that matters though.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)