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



##########
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:
       According to the doc, NoElementException should be thrown when a mapping 
is expected to return one element but returns none. -1 means it is not mapped. 
Maybe we can just leave it as it is (and other places), let it throw 
ArrayIndexOutOfBoundsException.




----------------------------------------------------------------
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