Skip to content

Conversation

@liach
Copy link
Member

@liach liach commented Oct 28, 2025

Current Status

In core reflection, there are a few holes with the documentation on the type conversions performed on the different setters. They generally follow this process:

  1. The Object-valued setters checks the destination type. If that type is primitive, unbox the object.
  2. Perform identity or (primitive/reference, depending on destination type) widening conversions.

For each step, they can fail with IllegalArgumentException, which has been the long standing behavior.

Note that this process is more restrictive than the JLS 5.2 assignment context, which allows boxing conversions, while the primitive reflective setters consistently reject them.

Problems

There are some problems with current specs:

  1. No mention that boxing is never done for primitive-typed setters
  2. Array.set missing description for the final identity or widening conversion (reference or primitive) and the associated IAE condition
  3. Class specification of field mentions widening/narrowing conversion rules that is not sensible for get/set Object accessors
  4. Field.set misses the identity or widening in IAE clause (but mentioned in main body)
  5. Field primitive setters incorrectly claim they are equivalent to set(instance, wrapper) which is wrong due to lack of boxing conversion
  6. Field primitive setters refer to nonsense "unwrapping conversion"

Solutions

  1. Make sure the unbox -> identity/widen process and the IAE conditions are present in both Field and Array.set
  2. Add that boxing is absent for all primitive setters
  3. Update Field class spec to mention the narrowing/widening conversion limits are for primitive accessors only
  4. Fix the Field primitive setters' "unwrapping conversion" to be "identity or primitive widening conversion" as in Array primitive setters
  5. Qualify the Field primitive setters assertion with "if this field is of a primitive type" to make it correct

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change requires CSR request JDK-8370849 to be approved
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issues

  • JDK-4517644: Core reflection setter type conversion spec bugs (Bug - P4)
  • JDK-8370849: Core reflection setter type conversion spec bugs (CSR)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28029/head:pull/28029
$ git checkout pull/28029

Update a local copy of the PR:
$ git checkout pull/28029
$ git pull https://git.openjdk.org/jdk.git pull/28029/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28029

View PR using the GUI difftool:
$ git pr show -t 28029

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28029.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 28, 2025

👋 Welcome back liach! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Oct 28, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added csr Pull request needs approved CSR before integration core-libs [email protected] labels Oct 28, 2025
@openjdk
Copy link

openjdk bot commented Oct 28, 2025

@liach The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 28, 2025
@mlbridge
Copy link

mlbridge bot commented Oct 28, 2025

Webrevs

@AlanBateman
Copy link
Contributor

AlanBateman commented Oct 29, 2025

The class description allows for widening but specifies IAE if a narrowing conversion is needed. Should we expand this sentence? I'm also wondering about identity conversions in description of each method as I don't know if this will be understand by readers without links.

@liach
Copy link
Member Author

liach commented Oct 29, 2025

I think that paragraph most likely applies to the primitive accessors, because Object set are already performing necessary casts as narrowing conversions, and Object get never narrows its result. I should qualify this paragraph.

@liach
Copy link
Member Author

liach commented Oct 29, 2025

I have pushed a commit correcting the class description paragraph in question to apply to primitive get/set only, and listed it in the problem and solutions sections on this PR and the CSR. Please review again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-libs [email protected] csr Pull request needs approved CSR before integration rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

2 participants