Skip to content

[do-not-merge] Generate reachability-metadata.json files for generated object types #2473

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

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

mpritham
Copy link
Contributor

@mpritham mpritham commented Mar 3, 2025

Context

In order to use reflection in native executables created with Graal's native-image feature we need to provide the Graal compiler a listing of the types and methods we'd like to be accessible for reflection. This is exposed via reachability metadata files stored in META-INF/native-image/**/reachability-metadata.json files.

Before this PR

No reflection metadata is generated. Jackson is unable to deserialize Conjure object types.

After this PR

When creating the metadata files, instead of listing the methods accessed for reflection, we use the convenience functions allDeclaredFields, allPublicFields and allDeclaredConstructors.

==COMMIT_MSG==
Generate reachability-metadata.json files for generated object types
==COMMIT_MSG==

Possible downsides?

We over-include certain methods: several methods in the Builder classes are convenience overrides and are not accessed via reflection by Jackson (e.g. addAllX methods for collections fields). This over-inclusion isn't preferred: 1) it'd be safer to enforce that only a certain fields are accessible via reflection to prohibit arbitrary uses of reflection, 2) including extra methods increases binary size. We are still in the early stages of exploring Java native executables and have opt'd to over-include methods accessible for reflection to iterate faster.

@changelog-app
Copy link

changelog-app bot commented Mar 3, 2025

Generate changelog in changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Generate reachability-metadata.json files for generated object types

Check the box to generate changelog(s)

  • Generate changelog entry

}
}

record GeneratedReachabilityMetadataFile(String packageName, ReachabilityMetadata reachabilityMetadata)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generating one JSON per package here. An alternative is to create one JSON per type. This is what we'd want to do when generating metadata in an annotation library as it allows Gradle to make use of incremental compilation: skip generation of metadata for classes that have not changed.

For conjure-java, I can go either way. One JSON per type is a load of files and slightly more difficult to inspect manually so I opted to do this. (it's not really all that much more difficult - I can just cat all the files in a directory)

@mpritham mpritham force-pushed the mpritham/reachability-metadata branch from 773338c to 655c284 Compare March 3, 2025 22:47
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