iay / mdq-server

Metadata Query Protocol server implementation using Shibboleth MDA
6 stars 6 forks source link

HTML template rendering failing due to ambiguous "size" reference #59

Closed iay closed 2 years ago

iay commented 2 years ago

There's a place in each of the Groovy templates where the size of the collection of results is processed like this:

Collection<String> ids = result.getIdentifiers();
p("Identifiers: ${ids.size}");
if (ids.size != 0) {
   ...
}

Unfortunately, if the underlying object is an ArrayList and we're running under Java 16+ and the phase of the moon is inopportune, this will fail in one of a couple of different ways:

This appears to be due to GROOVY-9961 "List "size" property yields an ArrayList, not an integer, on Java 16 RC build 36".

The bottom line is that this behaviour was never guaranteed for an ArrayList and that it's not regarded as a bug in Groovy.

The fix is straightforward: simply replace .size with .size() in both cases, making it explicit that we're talking about the collection's size as determined by the #size method and not an implicit property acquired by pulling out the value of a private field.

It's not possible to test this very well under Java 11, which is what the project is currently built under, although the image ships with Java 17. I'll fix this and add a test, though, which will prevent a recurrence.