Skip to content

Commit

Permalink
Fixes #5521 ResourceCollection list NPE
Browse files Browse the repository at this point in the history
Minimized changes in 9.  Will do bulk of changes in 10.
  • Loading branch information
gregw committed Oct 28, 2020
1 parent 1569437 commit 6c7a63b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
Expand Up @@ -256,40 +256,51 @@ public Resource addPath(String path) throws IOException
return this;
}

Resource resource = null;
ArrayList<Resource> resources = null;

// Attempt a simple (single) Resource lookup that exists
for (Resource res : _resources)
int i = 0;
for (; i < _resources.length; i++)
{
Resource r = res.addPath(path);
if (!r.exists())
continue;

if (!r.isDirectory())
return r;

if (resources == null)
resources = new ArrayList<>();
resources.add(r);
resource = _resources[i].addPath(path);
if (resource.exists())
{
if (resource.isDirectory())
{
break;
}
return resource;
}
}

if (resources == null)
for (i++; i < _resources.length; i++)
{
return null; /* TODO this is not allowed in 10. Instead do:
for (Resource res : _r1esources)
Resource r = _resources[i].addPath(path);
if (r.exists() && r.isDirectory())
{
Resource r = res.addPath(path);
if (r.exists())
return r;
if (resources == null)
{
resources = new ArrayList<>();
}

if (resource != null)
{
resources.add(resource);
resource = null;
}

resources.add(r);
}
return EmptyResource.INSTANCE;
*/
}

if (resources.size() == 1)
return resources.get(0);

return new ResourceCollection(resources.toArray(new Resource[0]));
if (resource != null)
{
return resource;
}
if (resources != null)
{
return new ResourceCollection(resources.toArray(new Resource[0]));
}
return null;
}

@Override
Expand Down
Expand Up @@ -187,7 +187,7 @@ public void testList() throws Exception

assertThat(Arrays.asList(rc1.list()), contains("1.txt", "2.txt", "3.txt", "dir/"));
assertThat(Arrays.asList(rc1.addPath("dir").list()), contains("1.txt", "2.txt", "3.txt"));
assertThat(rc1.addPath("unknown"), nullValue());
assertThat(rc1.addPath("unknown").list(), nullValue());
// TODO for jetty-10 assertThat(rc1.addPath("unknown").list(), nullValue());
}

Expand Down

0 comments on commit 6c7a63b

Please sign in to comment.