spring-data-redis icon indicating copy to clipboard operation
spring-data-redis copied to clipboard

Handle top-level collections without entity lookup in MappingRedisConverter #2168

Open Leehyoungwoo opened this issue 7 months ago • 0 comments

Fix. #2168

Summary

This issue arises in MappingRedisConverter.write(…), which by default treats all inputs—including JDK internal types like Arrays.asList(...)—as domain entities. It looks up a PersistentEntity for every input and then retrieves metadata (keyspace, identifier, TTL). On Java 9+ this leads to an InaccessibleObjectException when reflection tries to access the non-exported constructor of Arrays$ArrayList.

To address this, I added an early check in write(...):

if (source instanceof Collection) {
    writeCollection(
        sink.getKeyspace(),
        "",
        (List<?>) source,
        TypeInformation.of(Object.class),
        sink
    );
    return;
}

This skips all metadata lookups for top-level collections by directly invoking writeCollection(...).

I removed the @EnabledOnJre(JRE.JAVA_8) restriction on the writePlainList() test (now annotated // GH-2168) and verified that it passes on non–Java 8 environments.

  • [x] You have read the Spring Data contribution guidelines.
  • [x] You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • [x] You submit test cases (unit or integration tests) that back your changes.
  • [x] You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

Leehyoungwoo avatar May 09 '25 04:05 Leehyoungwoo