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

Expose a TypeMarker factory to wrap an arbitrary Type #2264

Merged
merged 2 commits into from
Mar 22, 2024

Conversation

carterkozak
Copy link
Contributor

Before this PR

It was impossible to make a reusable serializer/deserializer factory for a generic wrapper type, a new de/serializer would need to be implemented for each component, passing the concrete TypeMarker. While likely safer, it's not ideal to repeat unnecessary cruft like this.

After this PR

==COMMIT_MSG==
Expose a TypeMarker factory to wrap an arbitrary Type
==COMMIT_MSG==

Downsides: This method doesn't provide compile-time safety, as the returned TypeMarker cannot have generic type info (result is TypeMarker<?> because Type itself doesn't provide type info). However, this is reasonable because it can simplify code used by the annotation processor, and doesn't represent anything more dangerous than cast suppressions folks already use.

@changelog-app
Copy link

changelog-app bot commented Mar 22, 2024

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

Expose a TypeMarker factory to wrap an arbitrary Type

Check the box to generate changelog(s)

  • Generate changelog entry

Comment on lines +76 to +88
@Override
public int hashCode() {
return getType().hashCode();
}

@Override
public boolean equals(Object other) {
if (other instanceof WrappingTypeMarker) {
WrappingTypeMarker otherMarker = (WrappingTypeMarker) other;
return Objects.equals(getType(), otherMarker.getType());
}
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

Should these be moved to TypeMarker? I don't see any reason why we wouldn't want this implementation for all TypeMarker instances.

I guess maybe it's a little weird to consider different anonymous types equal, but that feel like the correct behavior for TypeMarker.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went back and forth on this. We definitely want to allow caches to work correctly for these, where in the usual anonymous class creation path we’d get the same instance and didn’t need to worry about it.
Equals and hashcode are pretty special in that they should take implementation details into account, so I don’t think it would be correct to make them final in the base class.

I think in a follow-up id like to update our caches to create a copy of TypeMarker instances used as keys using TypeMarker.of(marker.getType()) to avoid holding onto encapsulating classes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bulldozer-bot bulldozer-bot bot merged commit 912ac04 into develop Mar 22, 2024
5 checks passed
@bulldozer-bot bulldozer-bot bot deleted the ckozak/TypeMarkerFactory branch March 22, 2024 17:22
@svc-autorelease
Copy link
Collaborator

Released 8.13.0

carterkozak added a commit to palantir/dialogue that referenced this pull request Mar 22, 2024
This mirrors a change we've just introduced to conjure-undertow
here: palantir/conjure-java#2264

Dialogue takes advantage of this new factory method in ConjureBodySerDe
to avoid holding class references in serializer caches, which
introduced some friction in our dns-polling lifecycle management.
I haven't reverted the change to specify `weakKeys` in the caches,
however the keys should never be freed unless classes are unloaded
(e.g. plugins).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants