Skip to content

Do not take supertype type arguments for JDK value types and enums - #1397

Merged
seongahjo merged 1 commit into
mainfrom
fix/jdk-value-type-arguments
Nov 19, 2026
Merged

seongahjo merged 1 commit into
mainfrom
fix/jdk-value-type-arguments

Conversation

@seongahjo

@seongahjo seongahjo commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

GenericTypeResolverConverter inferred the type arguments of a set value's elements from their supertypes when the element class had none of its own. A String element got String<String> from Comparable<String>, and an enum element Color<Color> from Enum<Color>. This PR gives JDK classes without type parameters and enums no type arguments.

This is the first of four stacked PRs:

  1. This PR
  2. Fix setting JDK internal containers into Object properties #1395 Fix setting JDK internal containers into Object properties
  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

  • GenericTypeResolverConverter.extractTypeArgumentsFromValue returns no type arguments for:
    • JDK classes that declare no type parameters, such as String, Integer, BigDecimal or LocalDate. Their parameterized supertypes, such as Comparable<String>, describe the supertype, not the value.
    • enums, whose superclass is Enum<E>
  • Collections and maps still infer type arguments from their contents. Other classes still use the type arguments of their generic superclass or interfaces, such as a class implementing Supplier<String>, whose element type comes from them.
  • Generated values do not change. The wrong type arguments were attached to leaf nodes, which do not use them. They would spread once a container's type arguments are inferred from its content, which the third PR of the stack does for Optional and Map.Entry: an Optional holding a String would become Optional<String<String>>.

How Has This Been Tested?

  • Added 2 tests to GenericTypeResolverConverterTest: a collection of Strings and a collection of enums are inferred as String and as the enum class, without type arguments
  • 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.

- Infer no type arguments for JDK classes without type parameters, such as String
- Infer no type arguments for enums, instead of Enum<E>'s
@seongahjo
seongahjo added this pull request to stack #1400 November 19, 2026 07:33
@seongahjo
seongahjo merged commit c5bc734 into main Nov 19, 2026
15 of 19 checks passed
@seongahjo
seongahjo deleted the fix/jdk-value-type-arguments branch November 19, 2026 07:51
@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