Repository navigation
Conversation
github-actions
Bot
requested review from
SooKim1110,
acktsap,
benelog,
jwChung,
mhyeon-lee and
seongahjo
October 19, 2026 11:04
…er value Setting a container value whose elements are instances of different subtypes of the declared element type generated every element as the first element's subtype, because the generic type argument of the container was inferred from the first element only. Infer it from the most specific common superclass of all elements instead, and keep the declared element type when the only common superclass is Object. Fixes naver#1347
poketopa
force-pushed
the
fix/set-mixed-subtypes-into-abstract-container
branch
from
October 19, 2026 11:36
d78574d to
18ea529
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1347.
Setting a container value whose elements are instances of different subtypes of the declared element type
(e.g.
set("shapes", List.of(circle, square))intoList<Shape>) generated every element as the firstelement's subtype. In strict mode the same call failed with
No matching results for given NodeResolvers. Invalid paths: [$.shapes[1].side].This worked in 1.1.21 and regressed in 1.2.0.
(Optional): Description
When a container value is set,
ValueAnalyzerbuilds two kinds of path resolvers from the value:GenericTypeResolverfor the container path ($.shapes), inferred from the value, andInterfaceResolverper element path ($.shapes[0]→Circle,$.shapes[1]→Square).GenericTypeResolverConverter.extractCollectionTypeArgumentsinferred the element type argument from thefirst element only, so
List<Shape>was rewritten toArrayList<Circle>and every element node wascreated as
Circlebefore the per-element resolvers ran. The resolver for$.shapes[1]then saw aCirclenode,
Circle.isAssignableFrom(Square)is false, and theSquarevalue was projected onto aCirclenode.extractMapTypeArgumentshad the same problem with the first entry's key and value.This change infers the element (and map key/value) type from all non-null elements:
Shape), so each element nodekeeps the declared type and the per-element
InterfaceResolverpicks its runtime type;Object(e.g. implementations of an interface, or unrelated classes) →no type argument is inferred and the declared element type is kept.
How Has This Been Tested?
ContainerElementSubtypeTest(java-tests): the two cases from Setting a list of mixed subtypes into an abstract-typed list generates every element as the first subtype (1.2.x regression) #1347 (default and strict mode), elementorder and element values preserved, mixed implementations of an interface, and mixed values in a
Map<String, Shape>. All fail onmainand pass with this change.GenericTypeResolverConverterTest(object-farm-api): same class, different subclasses, unrelated classes,null elements, map values.
CLAUDE.md:./gradlew --continue clean :object-farm-api:check :fixture-monkey:test :fixture-monkey-tests:java-tests:test :fixture-monkey-tests:java-17-tests:test :fixture-monkey-tests:kotlin-tests:test(JDK 17)Is the Document updated?
No. The behaviour matches what the documentation already describes for
setwith container values.Note: #1337 also adds a
GenericTypeResolverConverterTest(for a different method,createResolver).The production changes do not overlap; if #1337 lands first I will rebase and merge the two test classes.