Skip to content

Records cannot be properly used in caches #3008

@JacobKeegan

Description

@JacobKeegan

If a cache is sized using MemoryUnit, and the cache key or value contains a record (which were added in Java 17), any attempt to put a value in the cache will fail. The core cause of this failure is this line in sun.misc.Unsafe:

if (declaringClass.isRecord()) {
     throw new UnsupportedOperationException("can't get field offset on a record class: " + f);
}

A simple project which shows the issue in practice is linked here.
This seems like a serious issue, because Ehcache gives no clear indication of why this failure happens, and records are natural to use as keys.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Unprioritized

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions