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

ASF GitHub Bot commented on DRILL-2618:
---------------------------------------

Github user adeneche commented on a diff in the pull request:

    https://github.com/apache/drill/pull/270#discussion_r45418223
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSelection.java 
---
    @@ -190,22 +136,40 @@ private static String commonPath(FileStatus... paths) 
{
             break;
           }
         }
    -    URI oneURI = paths[0].getPath().toUri();
    +    URI oneURI = statuses.get(0).getPath().toUri();
         return new Path(oneURI.getScheme(), oneURI.getAuthority(), 
commonPath).toString();
       }
     
    -  public static FileSelection create(DrillFileSystem fs, String parent, 
String path) throws IOException {
    -    Path p = new Path(parent,removeLeadingSlash(path));
    -    FileStatus[] status = fs.globStatus(p);
    -    if (status == null || status.length == 0) {
    +  public static FileSelection create(final DrillFileSystem fs, final 
String parent, final String path) throws IOException {
    +    final Path combined = new Path(parent, removeLeadingSlash(path));
    +    final FileStatus[] statuses = fs.globStatus(combined);
    +    if (statuses == null) {
           return null;
         }
    -    if (status.length == 1) {
    -      URI oneURI = status[0].getPath().toUri();
    -      String selectionRoot = new Path(oneURI.getScheme(), 
oneURI.getAuthority(), p.toUri().getPath()).toString();
    -      return new FileSelection(Collections.singletonList(status[0]), 
selectionRoot);
    +    return create(Lists.newArrayList(statuses), null, 
combined.toUri().toString());
    +  }
    +
    +  /**
    +   * Creates a {@link FileSelection selection} with the given file 
statuses/files and selection root.
    +   *
    +   * @param statuses  list of file statuses
    +   * @param files  list of files
    +   * @param root  root path for selections
    +   *
    +   * @return  null if creation of {@link FileSelection} fails with an 
{@link IllegalArgumentException}
    +   *          otherwise a new selection.
    +   *
    +   * @see FileSelection#FileSelection(List, List, String)
    +   */
    +  public static FileSelection create(final List<FileStatus> statuses, 
final List<String> files, final String root) {
    +    try {
    +      final String selectionRoot = Strings.isNullOrEmpty(root) ? 
commonPath(statuses) : root;
    --- End diff --
    
    `FormatSelection` C'tor calls this method passing `statuses` and `root` as 
null. this will call `commonPath()` passing null as a parameter, which will 
cause a NPE


> BasicFormatMatcher calls getFirstPath(...) without checking # of paths is not 
> zero
> ----------------------------------------------------------------------------------
>
>                 Key: DRILL-2618
>                 URL: https://issues.apache.org/jira/browse/DRILL-2618
>             Project: Apache Drill
>          Issue Type: Bug
>          Components: Storage - Other
>            Reporter: Daniel Barclay (Drill)
>            Assignee: Deneche A. Hakim
>             Fix For: 1.4.0
>
>
> {{BasicFormatMatcher.isReadable(...)}} calls {{getFirstPath(...)}} without 
> checking that there is at least one path.  This can cause an 
> IndexOutOfBoundsException.
> To reproduce, create an empty directory {{/tmp/CaseInsensitiveColumnNames}} 
> and run 
> {{exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java}}.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to