Brian Dellisanti created GROOVY-9961:
----------------------------------------

             Summary: List "size" property yields an ArrayList, not an integer, 
on Java 16 RC build 36
                 Key: GROOVY-9961
                 URL: https://issues.apache.org/jira/browse/GROOVY-9961
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 3.0.7, 2.4.15
            Reporter: Brian Dellisanti


On Java 16 RC build 36, the "size" property yields an ArrayList. This change in 
behavior seems related to JEP 396 ([https://openjdk.java.net/jeps/396]). It is 
surprising that the new behavior is to return a list because that causes 
comparisons with numbers to yield false rather than throw an exception on 
evaluating ".size", which causes code to fail silently.

>From groovy console:
{noformat}
groovy> def x = [] 
groovy> println(System.getProperty("java.version")) 
groovy> println(x.size) 
groovy> println(x.size()) 
groovy> println(x === x.size) 
groovy> println(x.getClass()) 
groovy> println(x.size.getClass()) 
 
16
[]
0
false
class java.util.ArrayList
class java.util.ArrayList
{noformat}
On Java 15:
{noformat}
groovy> def x = [] 
groovy> println(System.getProperty("java.version")) 
groovy> println(x.size) 
groovy> println(x.size()) 
groovy> println(x === x.size) 
groovy> println(x.getClass()) 
groovy> println(x.size.getClass()) 
 
15.0.1
0
0
false
class java.util.ArrayList
class java.lang.Integer
{noformat}
Also with Java 15, this is logged to the console:
{noformat}
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v9.Java9 
(file:/Users/bdd/Downloads/groovy-3.0.7/lib/groovy-3.0.7.jar) to field 
java.util.ArrayList.size
WARNING: Please consider reporting this to the maintainers of 
org.codehaus.groovy.vmplugin.v9.Java9
WARNING: Use --illegal-access=warn to enable warnings of further illegal 
reflective access operations
WARNING: All illegal access operations will be denied in a future release
{noformat}
Overriding the new illegal access behavior restores Java 15 behavior:
{noformat}
$ export JAVA_OPTS=--illegal-access=permit
$ ./bin/groovyConsole
OpenJDK 64-Bit Server VM warning: Option --illegal-access is deprecated and 
will be removed in a future release.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v9.Java9 
(file:/Users/bdd/Downloads/groovy-3.0.7/lib/groovy-3.0.7.jar) to field 
java.util.ArrayList.size
WARNING: Please consider reporting this to the maintainers of 
org.codehaus.groovy.vmplugin.v9.Java9
WARNING: Use --illegal-access=warn to enable warnings of further illegal 
reflective access operations
WARNING: All illegal access operations will be denied in a future release
{noformat}
{noformat}
groovy> def x = [] 
groovy> println(System.getProperty("java.version")) 
groovy> println(x.size) 
groovy> println(x.size()) 
groovy> println(x === x.size) 
groovy> println(x.getClass()) 
groovy> println(x.size.getClass()) 
 
16
0
0
false
class java.util.ArrayList
class java.lang.Integer
{noformat}
Full Java version info:
{noformat}
groovy-3.0.7$ java -version
openjdk version "16" 2021-03-16
OpenJDK Runtime Environment (build 16+36-2231)
OpenJDK 64-Bit Server VM (build 16+36-2231, mixed mode, sharing)
{noformat}



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

Reply via email to