Skip to content

DynConstructors cleanup - #10542

Merged
nastra merged 6 commits into
apache:mainfrom
findepi:findepi/DynConstructors
Jun 28, 2024
Merged

nastra merged 6 commits into
apache:mainfrom
findepi:findepi/DynConstructors

Conversation

@findepi

@findepi findepi commented Jun 20, 2024

Copy link
Copy Markdown
Member

No description provided.

findepi added 6 commits June 20, 2024 11:58
The `DynConstructors.Builder.hiddenImpl(Class<?>...)` is a varargs
method, but cannot be used as such, because `hiddenImpl(Class<T>,
Class<?>...)` exists and would be used instead. Since there are no
usages, deprecate it instead of fixing.
@findepi
findepi requested a review from Fokko June 20, 2024 10:17
@Fokko
Fokko requested a review from nastra June 20, 2024 10:26

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks great @findepi Thanks for updating this code and adding the tests 👍

public void testInterfaceWrongImplString() throws Exception {
DynConstructors.Ctor<MyInterface> ctor =
DynConstructors.builder(MyInterface.class)
// TODO this should throw, since the MyUnrelatedClass does not implement MyInterface

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

still a TODO left here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is reflection on current state of the API, pre-existing problem.
I can remove this TODO if this helps. I did not plan to address this as part of this cleanup PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

BTW my thinking about TODO in the test is this -- a test should prevent undesired behavioral changes of the implementation. If i write a test exercising specific behavior and I don't think the behavior change should be prevented I put a comment like this one. If I don't put the comment in, someone may treat this test as asserting something important and thus give up an otherwise good change.
I understand this is a bit convoluted, but that's a lesson learned from Trino on how contributors sometimes react to test failures. I've seen test failures causing otherwise good code to become less good, because the contributor considered modifying the test is not an option.

Alternatively, I could not have the test, but I am not convinced this is a better option.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@nastra does this explanation address your concerns? or what should i change here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think leaving the TODO here is fine and we should probably address this in a follow up so that it throws when buildChecked is called

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

good point!

public void testInterfaceWrongImplClass() throws Exception {
DynConstructors.Ctor<MyInterface> ctor =
DynConstructors.builder(MyInterface.class)
// TODO this should throw or not compile at all, since the MyUnrelatedClass does not

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TODO left here. Are you planning to address this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

same answer as in #10542 (comment)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@findepi is this a case where we can make it a compile-time check? I think it is currently very permissive because the interface uses Class<?> but maybe we could keep track of MyInterface and make this Class<? extends MyInterface>?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can give this a try @rdblue . one concern is that the DynConstructors and other Dyn* classes appear to be considered a part of iceberg-common API, so changes around generics would technically be breaking changes.
@rdblue how would you recommend going about this?

@nastra
nastra merged commit c469edf into apache:main Jun 28, 2024
@findepi
findepi deleted the findepi/DynConstructors branch June 28, 2024 10:14
jasonf20 pushed a commit to jasonf20/iceberg that referenced this pull request Aug 4, 2024
The `DynConstructors.Builder.hiddenImpl(Class<?>...)` is a varargs
method, but cannot be used as such, because `hiddenImpl(Class<T>,
Class<?>...)` exists and would be used instead. Since there are no
usages, deprecate it instead of fixing.
zachdisc pushed a commit to zachdisc/iceberg that referenced this pull request Dec 23, 2024
The `DynConstructors.Builder.hiddenImpl(Class<?>...)` is a varargs
method, but cannot be used as such, because `hiddenImpl(Class<T>,
Class<?>...)` exists and would be used instead. Since there are no
usages, deprecate it instead of fixing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants