rkondakov commented on a change in pull request #1959:
URL: https://github.com/apache/calcite/pull/1959#discussion_r422699962
##########
File path: core/src/main/java/org/apache/calcite/util/mapping/Mappings.java
##########
@@ -1245,12 +1271,30 @@ public void set(int source, int target) {
assert isValid();
}
+ /**
+ * Returns the source that a target maps to, or -1 if it is not mapped.
+ *
+ * @throws NoElementException if target is out of sources range.
+ */
public int getSourceOpt(int target) {
- return sources[target];
+ try {
+ return sources[target];
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new Mappings.NoElementException("invalid target " + target);
Review comment:
Hmm.. it is also said in javadoc that `FunctionMapping#getTarget` throws
`NoElementException if source is not mapped`. Which is closer to the truth. In
this case `NoElementException` is valid move.
I also noticed that for some mappings it was an original behavior, i.e.
`Permutation#getTarget()`. I just made the fix by analogy with this legacy
behavior.
I agree that it is far from perfect. May be `IllegalArgumentException` is
more suitable here. But I think that `ArrayIndexOutOfBoundsException` is not
the best choice.
What if I just change the javadoc of `NoElementException` to `Should be
thrown when source or target is not mapped`?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]