julianhyde commented on a change in pull request #1959:
URL: https://github.com/apache/calcite/pull/1959#discussion_r422804623



##########
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:
       `NoElementException` is for the case where the source is within the 
domain (0 .. sourceCount - 1) but no mapping is present.
   
   If the source is outside the domain - less than 0 or greater than or equal 
to sourceCount - then `IndexOutOfBoundsException` would be appropriate.
   
   I don't think `getSourceOpt` or `getTargetOpt` should ever throw 
`NoElementException`. They have a different way to communicate no element - 
namely by returning -1.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to