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

[CALCITE-4156] ReflectiveRelMetadataProvider constructor should throw an exception (instead of assertion) when called with an empty map #2095

Merged
merged 1 commit into from Aug 6, 2020

Conversation

rubenada
Copy link
Contributor

@rubenada rubenada commented Aug 5, 2020

Jira ticket: CALCITE-4156

ReflectiveRelMetadataProvider's constructor verifies that it is not created with an empty map, using an assertion. However, this is not the most reliable way of verifying this situation, since assertions can be deactivated. In such scenario, we could silently end up having an invalid ReflectiveRelMetadataProvider, with no actual methods attached.
Also, since the map is private and has no getter, there is no way for a caller module to verify this situation on its side.
For this reason, it is proposed a minor change: replace the assertion with an IllegalArgumentException, which will work in 100% of the cases and will always prevent constructing an invalid ReflectiveRelMetadataProvider.

… an exception (instead of assertion) when called with an empty map
Copy link
Contributor

@chunweilei chunweilei left a comment

Choose a reason for hiding this comment

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

LGTM

@rubenada rubenada added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Aug 5, 2020
@rubenada rubenada merged commit ad53962 into apache:master Aug 6, 2020
@@ -78,7 +78,9 @@ protected ReflectiveRelMetadataProvider(
ConcurrentMap<Class<RelNode>, UnboundMetadata> map,
Class<? extends Metadata> metadataClass0,
Multimap<Method, MetadataHandler> handlerMap) {
assert !map.isEmpty() : "are your methods named wrong?";
if (map.isEmpty()) {
throw new IllegalArgumentException("ReflectiveRelMetadataProvider methods map is empty");
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I missed your PR.

Why not use CheckArgument in Guava?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback @amaliujia , you are right, I am considering open a follow-up PR to change it into Preconditions.checkArgument

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@amaliujia please check #2100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LGTM-will-merge-soon Overall PR looks OK. Only minor things left.
Projects
None yet
4 participants