Skip to content

Mutable objects used for immutable values #772 #1596

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fabio-rizzo-01
Copy link
Contributor

Updated Polaris entity objects to use builders instead of normal constructors and removed all the set methods to guarantee object immutability.
All the other changes are refactoring based on those changes.

@snazy
Copy link
Member

snazy commented May 15, 2025

I like the removal of all the setters!
However, since these types now look pretty much how those would look like when using immutables, mind going down that route? That would also remove all the hand-written Builders.

@pingtimeout
Copy link
Contributor

pingtimeout commented May 15, 2025

I agree with Robert. I think this PR does not fully embrace the immutable pattern.

  • The class fields are not final, which would clearly establish the intent of those objects being immutable.
  • Adding the Builder subclasses adds a lot of code that could be automatically generated
  • (nit) It could even be possible to annotate the classes with @Immutable (from jcip) to enable an extra verification step in the IDE

It would be good to explore the immutables library to address some of these points.

Note that this PR contains a removal of some utility copy-constructors (PolarisEntityCore from PolarisBaseEntity), which might not be related?

@singhpk234
Copy link
Contributor

+1 to PolarisImmutables

@fabio-rizzo-01
Copy link
Contributor Author

I like the removal of all the setters! However, since these types now look pretty much how those would look like when using immutables, mind going down that route? That would also remove all the hand-written Builders.

From the bug description I thought the point was to make those object not mutable, i didn't think there was a library already there hence why I created the builders. can you guys point me in the right direction thx ? @singhpk234

@eric-maynard
Copy link
Contributor

@fabio-rizzo-01 I think the ask is that you use this interface.

Besides this, I think we should try to minimize the changes that callers need to make as much as possible.

@fabio-rizzo-01
Copy link
Contributor Author

@fabio-rizzo-01 I think the ask is that you use this interface.

Besides this, I think we should try to minimize the changes that callers need to make as much as possible.

Looking at that interface and seeing where it is used, it seems to me that using it would require even more changes that what I already did.

Taking PolarisEntityCore as an example, to convert that to an immutable object I'd have to create an interface (something like PolarisEntityCoreInt) that uses PolarisImmutable annotation, that would generate a class called Immutable PolarisEntityCoreInt. So all the code that is using PolarisEntityCore object it needs to be updated to use the new immutable object.

Is this what you guys are suggesting ? @snazy @singhpk234

@eric-maynard
Copy link
Contributor

Personally I'm fine with you not using @PolarisImmutable -- I still haven't figured out why we need that or why my IDE so often doesn't seem to like it:
Screenshot 2025-05-16 at 10 34 35 AM

But I do think this PR makes quite a few changes, such as those to TransactionalMetaStoreManagerImpl.java, which could be reduced or elimated. For example, does the method setGrantRecordsVersion really need to go away? If it does, can we implement a cloning method like withGrantRecordsVersion?

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.

5 participants