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

Vladimir Sitnikov commented on CALCITE-4226:
--------------------------------------------

Here's what I suggest

{code:java}
  /**
   * Returns a mapping as a list such that {@code list.get(source)} is
   * {@code mapping.getTarget(source)} and {@code list.size()} is
   * {@code mapping.getSourceCount()}.
   *
   * <p>The resulting list never contains null elements</p>
   *
   * <p>Converse of {@link #target(List, int)}</p>
   * @see #asList(TargetMapping)
   */
  public static List<Integer> asListNonNull(final TargetMapping mapping) {
    return new AbstractList<Integer>() {
      public Integer get(int source) {
        int target = mapping.getTargetOpt(source);
        if (target < 0) {
          throw new IllegalArgumentException("Element " + source + " is not 
found in mapping "
              + mapping);
        }
        return target;
      }

      public int size() {
        return mapping.getSourceCount();
      }
    };
  }
{code}

> Mappings#asList might return null for negative ordinals which would result in 
> later NPEs
> ----------------------------------------------------------------------------------------
>
>                 Key: CALCITE-4226
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4226
>             Project: Calcite
>          Issue Type: Sub-task
>          Components: core
>    Affects Versions: 1.25.0
>            Reporter: Vladimir Sitnikov
>            Priority: Major
>
> It looks like none of the uses for Mappings#asList is ready to handle nulls.
> So far there are 6 usages of the method, however, it is puzzling if NPE is 
> expected behavior there.
> I'm inclined to create two variations of the method:
> 1) {{List<@Nullable Integer> asList(...)}} -- keep the current method current 
> one
> 2) {{List<@NonNull Integer> asList(...)}} -- throw exceptions on invalid 
> mappings



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

Reply via email to