Using good ol' Java collections usually works great in WO templates.
However, in the past years the JDK has been increasingly introducing the pattern of factory methods that return private implementions of public interfaces. Examples of commonly used methods that do this are List.of() and Collectors.toList().
This poses a problem for us WO-folks, especially in templating, since when KVC encounters a class like this (a private class implementing a public interface) it will fail to locate the correct method to invoke, causing an exception.
Examples:
var size1 = NSKeyValueCoding.Utility.valueForKey( new ArrayList<>(), "size" );
var size2 = NSKeyValueCoding.Utility.valueForKey( List.of(), "size" );
var filteredList = people()
.stream()
.filter( p -> p.name().startsWith( "H" ) )
.toList();
var size3 = NSKeyValueCoding.Utility.valueForKey( filteredList, "size" );
Obtaining size1 will work fine since ArrayList is a public class - but the same will fail for size2 and size3 with an IllegalAccessException.
I occasionally worked around this by wrapping collections in a public class like ArrayList when returning from a method I expected to use in a WO template - but obviously, that's no solution and quite the bother.
To make life easier, I've added a hack in wonder-slim to fix this: ERXKVCReflectionHack.
This is a small modification to KVC's default way of invoking methods, making an inaccessible method accessible on it's first invocation. If you're not using wonder-slim, you can drop this class into your own project to fix this - or add it to the actual original Project Wonder if you're brave enough. I have a general policy of not changing Wonder myself since I rarely use it, meaning I can't contribute much actual testing. Unfortunately, the best way to know if a hacky fix works is really to see it running in production without problems for a while (this one's been in use in all of my projects for a couple of months).
While the patch works we'll probably have to update it soon since we're using terminally deprecated functionality from sun.misc.Unsafe to replace a private static final field in KVC's default implementation. But that's for later.
ng-objects has a more generic fix in progress that attempts to properly locate an interface method to invoke when encountering an inaccessible method. Using this method in WO's KVC would involve some hacking, but I'll probably look into it once the time arrives (as in; when the functionality we're using in Unsafe gets removed).
| 🌶 cayenne | CAY-2908 Review and upgrade dependencies | Jan 12 |
| 🌶 cayenne | Merge pull request #636 from m-dzianishchyts/CAY-2908-update-dependen… | Jan 12 |
| 🛠️ wolips | Merge pull request #200 from wocommunity/dependabot/maven/org.mozilla… | Jan 8 |
| 🦡 vermilingua | Update maven-source-plugin v3.3.1 -> v3.4.0 | Jan 5 |
| 🦡 vermilingua | Update maven-core v3.9.11 -> v3.9.12 | Jan 5 |
| 🦡 vermilingua | Update junit v6.0.0 -> v6.0.1 | Jan 5 |
| 🤖 modulo | Create a config class to hold our configuration | Dec 30 |
| 🤸♀️ wonder-slim | Deleted registration of unused "erxadm" request handler for stats | Dec 28 |
| 🛠️ wolips | Remove the SubTypeHierarchyCache. | Dec 27 |
| 🚀 ng-objects | Organized imports after package cleanup | Dec 26 |