[ 
https://issues.apache.org/jira/browse/CALCITE-4156?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17172664#comment-17172664
 ] 

Ruben Q L commented on CALCITE-4156:
------------------------------------

Thanks for you feedback [~julianhyde].
I think assertions are a perfectly valid mechanism. The downside is that they 
can be deactivated. Some projects do that for efficiency reasons, and this 
decision can be beyond the reach of a particular developer.
In this specific case, I (and other people) think it is better to throw an 
exception (or as [~amaliujia] suggests in the PR, use guava's 
{{checkArgument}}, which is essentially the same). I described the reasons in 
the description. Most of the times, when using assertions e.g. to check an 
object is not null or an index is in range, even if the code runs with them 
disabled, we'll get eventually a runtime exception, so we know that something 
went wrong. But this is not the case in this scenario. In this situation, we 
can silently en up with an invalid, empty {{ReflectiveRelMetadataProvider}}, 
and there is no way to verify this circumstance. For this reason, I consider 
that  for this particular case an {{IllegalArgumentException}} is a better 
approach.
I think [~amaliujia] suggestion of using  guava's checkArgument is a fair 
point, since this mechanism is already in place in other parts of Calcite and 
leads to a cleaner code, so I propose to open a follow-up PR and to use 
{{checkArgument}}.

> ReflectiveRelMetadataProvider constructor should throw an exception (instead 
> of assertion) when called with an empty map
> ------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-4156
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4156
>             Project: Calcite
>          Issue Type: Task
>          Components: core
>            Reporter: Ruben Q L
>            Assignee: Ruben Q L
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: 1.25.0
>
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> 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.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to