Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom lookup for reflective schemas #5885

Merged
merged 4 commits into from
Feb 21, 2025
Merged

Conversation

dagnir
Copy link
Contributor

@dagnir dagnir commented Feb 17, 2025

Motivation and Context

This commit updates BeanTableSchema and ImmutableTableSchema to allow
customers to provide their own instance of MethodHandle.Lookup.

This is a necessary feature for situations where either of these schemas
are used in an application where the item classes and the SDK classes
are loaded by different classloaders. Since these schemas work by
reflectively scanning the item class to find the attributes' getters and
setters (or builder for immutable classes), the enhanced client makes
use of a LambdaMetaFactory to construct lambdas that directly call these
methods to avoid reflection when mapping to and from a
AttributeValues. At least as of Java 21, the way that lambdas are
constructed (all lambdas, not just the ones created by the enhanced
client), is they are made internal classes of the "caller" class, i.e.
the class that defined it. The calling class is identified by the class
that created the Lookup object. This means that when using the default
Lookup created LambdaToMethodBridgeBuilder, all of these lambdas are
inner classes of of LambdaToMethodBridgeBuilder. This is an issue when
the item class is from a different classloader (or module) because when
the lambda attempts to reference the item class (e.g. to call a getter),
it's ClassLoader will throw a ClassNotFoundException because because
it's not a class that it knows about.

By allowing the customer to provide a Lookup object, they can
guarantee that the the Lookup has visibility and access to the item
classes.

Modifications

Testing

  • Added new tests

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@dagnir dagnir force-pushed the dongie/ddb-schema-lookup branch 4 times, most recently from 4beef67 to bcccbc6 Compare February 18, 2025 00:38
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This JAR just contains the test POJOs.

I opted to just have a one-off JAR since it's simpler than setting up a new module and using that as a test dependency for the enhanced client, since it involves updating the import config and release yml files.

@dagnir dagnir marked this pull request as ready for review February 18, 2025 00:41
@dagnir dagnir requested a review from a team as a code owner February 18, 2025 00:41
This commit updates `BeanTableSchema` and `ImmutableTableSchema` to allow
customers to provide their own instance of `MethodHandle.Lookup`.

This is a necessary feature for situations where either of these schemas
are used in an application where the item classes and the SDK classes
are loaded by different classloaders. Since these schemas work by
reflectively scanning the item class to find the attributes' getters and
setters (or builder for immutable classes), the enhanced client makes
use of a LambdaMetaFactory to construct lambdas that directly call these
methods to avoid reflection when mapping to and from a
`AttributeValue`s. At least as of Java 21, the way that lambdas are
constructed (all lambdas, not just the ones created by the enhanced
client), is they are made internal classes of the "caller" class, i.e.
the class that defined it. The calling class is identified by the class
that created the `Lookup` object. This means that when using the default
`Lookup` created `LambdaToMethodBridgeBuilder`, all of these lambdas are
inner classes of of `LambdaToMethodBridgeBuilder`. This is an issue when
the item class is from a different classloader (or module) because when
the lambda attempts to reference the item class (e.g. to call a getter),
it's `ClassLoader` will throw a `ClassNotFoundException` because because
it's not a class that it knows about.

By allowing the customer to provide a `Lookup` object, they can
guarantee that the the `Lookup` has visibility and access to the item
classes.
@dagnir dagnir force-pushed the dongie/ddb-schema-lookup branch from bcccbc6 to da65644 Compare February 18, 2025 18:35
* @return An initialized {@link BeanTableSchema}
*/
@SuppressWarnings("unchecked")
public static <T> BeanTableSchema<T> create(BeanTableSchemaParams<T> params) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a naming convention for this? "Params" feels placeholder/gross to me.

Copy link
Contributor Author

@dagnir dagnir Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no precedent in the Enhanced Client for naming of parameters objects, but in core, we do have several public API's that follow the 'Params' naming, e.g. in auth: https://sdk.amazonaws.com/java/api/2.27.12/software/amazon/awssdk/auth/signer/params/package-summary.html

The endpoint providers also follow this pattern https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/endpoints/S3EndpointParams.html

@dagnir
Copy link
Contributor Author

dagnir commented Feb 19, 2025

Integ failure not related, it's Kinesis

@dagnir dagnir enabled auto-merge February 20, 2025 23:10
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@dagnir dagnir added this pull request to the merge queue Feb 20, 2025
Merged via the queue into master with commit bfd5461 Feb 21, 2025
16 of 17 checks passed
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.

2 participants