Skip to content

Fix setting JDK internal containers into Object properties - #1395

Merged
seongahjo merged 1 commit into
mainfrom
fix/1390-object-immutable-container
Nov 19, 2026
Merged

seongahjo merged 1 commit into
mainfrom
fix/1390-object-immutable-container

Conversation

@seongahjo

@seongahjo seongahjo commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

set() of a JDK internal container such as List.of(...), Set.of(...) or Map.of(...) into an Object property threw InaccessibleObjectException, or sampled null with three or more elements (#1390). The property now gets a public implementation with the same elements, as in 1.1.23.

This is the second of four stacked PRs, based on #1397:

  1. Do not take supertype type arguments for JDK value types and enums #1397 Do not take supertype type arguments for JDK value types and enums
  2. This PR
  3. Restore set value type checks and per-element setLazy #1398 Restore set value type checks and per-element setLazy
  4. Promote container elements from generator candidates #1399 Promote container elements from generator candidates

(Optional): Description

  • When the value's class is a non-public JDK container (ImmutableCollections$List12, Collections$UnmodifiableSet, ...), JvmNodeTreeTransformer resolves the node to the nearest public container supertype (List, Set, Map, NavigableSet, ...) and then to its implementation.
    • It uses the implementation registered for that supertype, such as interfaceImplements(NavigableSet.class, ...), or the default one.
    • It applies to any property that accepts the value, not only Object: Serializable, a type variable, List<Serializable> elements, wildcard elements and Map<Object, V> keys.
  • GenericTypeResolverConverter uses the type arguments inferred from the value only when they are assignable to the declared ones. It keeps the declared ones when the inferred type is a non-public JDK container and the declared type has a default container implementation.
  • Types.isJdkInternalType decides what a non-public JDK type is. It replaces the package-private InterfaceResolverConverter.isInstantiable.
  • An element that shares its container's path (the content of Supplier, Function or Optional) is resolved without the container's path-based interface resolver. A set object with a Supplier<Object> field no longer ends in a StackOverflowError.

How Has This Been Tested?

  • Added SetJdkInternalContainerTest in fixture-monkey-tests/java-17-tests (16 tests):
    • List.of, Set.of and Map.of with one and three elements into an Object property
    • a nested List.of into an Object property
    • Set.of into a List<Object> element
    • List.of into a Map<String, Object> value and a Map<Object, V> key
    • an unmodifiable NavigableSet uses the implementation registered for NavigableSet
    • Serializable property, type variable property, List<Serializable> element and wildcard list element
  • Added 2 tests to SetObjectIsolationTest: a set object keeps its Supplier<Object> and Supplier<Supplier<Object>> fields. Both ended in StackOverflowError before this PR.
  • Ran object-farm-api, fixture-monkey, fixture-monkey-kotlin, java-tests, java-17-tests and kotlin-tests with checkstyle, Checker Framework and ktlint

Is the Document updated?

No documentation change is needed.

@seongahjo
seongahjo force-pushed the fix/1390-object-immutable-container branch 5 times, most recently from 7008b97 to 9273483 Compare November 19, 2026 07:28
@seongahjo seongahjo changed the title Fix setting JDK internal containers into Object properties and restore set value type checks Fix setting JDK internal containers into Object properties Nov 19, 2026
@seongahjo
seongahjo changed the base branch from main to fix/jdk-value-type-arguments November 19, 2026 07:29
@seongahjo
seongahjo added this pull request to stack #1400 November 19, 2026 07:33
Base automatically changed from fix/jdk-value-type-arguments to main November 19, 2026 07:51
@seongahjo
seongahjo force-pushed the fix/1390-object-immutable-container branch 2 times, most recently from d635af9 to a86f7ca Compare November 19, 2026 08:18
- Resolve non-public JDK containers to the nearest public container supertype
- Use the implementation registered for that supertype, or the default one
- Keep declared type arguments when the inferred one is a non-public JDK container
- Resolve the content sharing its container's path without the container's path resolver
@seongahjo
seongahjo force-pushed the fix/1390-object-immutable-container branch from a86f7ca to 932469c Compare November 19, 2026 08:31
@seongahjo
seongahjo merged commit 7cb339f into main Nov 19, 2026
12 checks passed
@seongahjo
seongahjo deleted the fix/1390-object-immutable-container branch November 19, 2026 08:45
@seongahjo seongahjo added this to the 1.2.5 milestone Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant