You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/12/21 16:58:00 UTC

[jira] [Commented] (GROOVY-10429) StringBuilder misses setLength method in Java17

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

Eric Milles commented on GROOVY-10429:
--------------------------------------

{{setLength(int)}} is a public method but it is declared by {{AbstractStringBuilder}}, which is a package-private class.  I think it is correct behavior for Java 16+ to hide the method from the user since it would not be accessible.

Have you tried this case using Groovy 4.0rc1?

> StringBuilder misses setLength method in Java17
> -----------------------------------------------
>
>                 Key: GROOVY-10429
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10429
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.9
>         Environment: Java11, Java17, Windows 10
>            Reporter: Joe Li
>            Priority: Major
>
> The following code will break on Groovy 3.0.9 with Java 17 but works with Java 11:
> {code:java}
> def sb = new StringBuilder()
> sb << 'a'
> sb << 'b'
> println sb.toString()
> sb.setLength(0) {code}
> The error is
> {code:java}
> groovy.lang.MissingMethodException: No signature of method: java.lang.StringBuilder.setLength() is applicable for argument types: (Integer) values: [0]{code}
> This error can be reproduced in Groovy Console.
> The doc for Java's StringBuilder.setLength method
> [https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/StringBuilder.html#setLength(int)]
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)