Bug with records in Ehcache 3

395 views
Skip to first unread message

Jacob Keegan

unread,
Apr 7, 2022, 5:52:10 PM4/7/22
to ehcache-users
I've recently been working on upgrading an application from Ehcache 2.10.6 to 3.10.0, and also upgrading from Java 15 to 17. During testing, I ran into a problem where trying to put values into one of our caches would always fail. Importantly, the cache was using a record as the key, and was sized using EntryUnit. Here's the code for that cache, if you're curious:
https://github.com/nysenate/OpenLegislation/blob/3.9/src/main/java/gov/nysenate/openleg/legislation/member/dao/SessionMemberNonIdCache.java

It took me awhile to figure out the core cause, this line in sun.misc.Unsafe throwing an error:

if (declaringClass.isRecord()) {

     throw new UnsupportedOperationException("can't get field offset on a record class: " + f);
}
https://github.com/openjdk/jdk/blob/master/src/jdk.unsupported/share/classes/sun/misc/Unsafe.java

So, it seems that records just can't be used as part of the key or value of caches, if it's sized by entries. I haven't seen this mentioned anywhere. Are there plans to fix this? Records are a natural thing to use as keys, after all. Or at the very least, could an error be thrown if you try to use a record in a cache with entry sizing? Tracking down the issue was quite difficult.

----
Jacob Keegan
Junior Programmer
New York State Senate

泠恒谦

unread,
Apr 8, 2022, 4:44:04 AM4/8/22
to ehcache-users

I don't seem to see such a problem in the github issue. Since I'm not familiar with `record`, it's a little difficult for me to reproduce.

Jacob Keegan

unread,
Apr 8, 2022, 5:36:18 PM4/8/22
to ehcache-users
Here, I made a simple project that reproduces the issue. Hopefully this makes it more clear!

泠恒谦

unread,
Apr 10, 2022, 12:44:52 PM4/10/22
to ehcache-users
I'm a bit late to reply because I don't actually look at my gmail much - I think you should open a new issue at https://github.com/ehcache/ehcache3/issues , I'm on my side and another for Jcache JUnit test with Ehcache successfully reproduce the issue.
Reply all
Reply to author
Forward
0 new messages