[
https://issues.apache.org/jira/browse/CALCITE-4156?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17172707#comment-17172707
]
Ruben Q L commented on CALCITE-4156:
------------------------------------
[~julianhyde], it is not that simple. In my specific case, I ended up with the
empty ReflectiveRelMetadataProvider for a series of circumstances. First, as
you say, assertions disabled. Secondly, code obfuscation: methods names were
changed during this process and because of that
{{ReflectiveRelMetadataProvider#reflectiveSource}} could not find them. I
cannot control the former, but I was able to fix the latter; so I could correct
the empty ReflectiveRelMetadataProvider situation. I agree with you this is a
developer problem, and the developer should fix it. But even though it's the
developer's responsibility and I was able to fix it, I think this situation is
not ideal, and in the future we should fail fast and prevent empty
ReflectiveRelMetadataProvider from being constructed, and an
IllegalArgumentException is a valid (and in this case IMHO safer) mechanism.
Calcite uses asserts, and Calcite uses IllegalArgumentException too. The
difference on when we should use one or the other can be subtle, and I think in
this case it is better the exception approach.
I am not saying I want to change "every single assert to an 'if ... throw'", I
just say it makes sense to change this specific one, for the reasons that I
have mentioned.
> 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)