I have written a piece of code where I'm checking the size of an ArrayList like:
[1,2,3].size
All works well on Groovy Console and with Grails embedded Tomcat server. But once I deployed this code to Websphere Application Server, I receivec an exception stating
Exception evaluating property 'size' for java.util.ArrayList, Reason: groovy.lang.MissingPropertyException: No such property: size for class: java.lang.Integer.
After a while of debugging, testing and plenty of WTFs, I realized that there were parenthesis missing from the method call. The property notation should not work as there's no method getSize()
for Collection (it's plain size()
) and this all makes sense.
What's puzzling me, is why does someCollection.size
work on Groovy Console and Grails?
Grails and Groovy Console version is 2.3.6
ArrayList
in (at least) the Sun JDK 1.7u67 and in OpenJDK 1.6 holds a private int size
, which is accessible to groovy. If your other environment uses another JDK, this var might not exist and groovy would fallback to the interpretation of [1,2,3]*.getSize()
, which then fails.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With