Skip to content

Commit

Permalink
Fixes #5521 ResourceCollection list NPE
Browse files Browse the repository at this point in the history
Refactor addPath in a simpler way, plus with TODOs to fix issues in 10 when merged.
  • Loading branch information
gregw committed Oct 28, 2020
1 parent 0dc9f6c commit 1569437
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 37 deletions.
Expand Up @@ -256,51 +256,40 @@ public Resource addPath(String path) throws IOException
return this;
}

Resource resource = null;
ArrayList<Resource> resources = null;
int i = 0;
for (; i < _resources.length; i++)
{
resource = _resources[i].addPath(path);
if (resource.exists())
{
if (resource.isDirectory())
{
break;
}
return resource;
}
}

for (i++; i < _resources.length; i++)
// Attempt a simple (single) Resource lookup that exists
for (Resource res : _resources)
{
Resource r = _resources[i].addPath(path);
if (r.exists() && r.isDirectory())
{
if (resources == null)
{
resources = new ArrayList<>();
}
Resource r = res.addPath(path);
if (!r.exists())
continue;

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

resources.add(r);
}
if (resources == null)
resources = new ArrayList<>();
resources.add(r);
}

if (resource != null)
{
return resource;
}
if (resources != null)
if (resources == null)
{
return new ResourceCollection(resources.toArray(new Resource[0]));
return null; /* TODO this is not allowed in 10. Instead do:
for (Resource res : _r1esources)
{
Resource r = res.addPath(path);
if (r.exists())
return r;
}
return EmptyResource.INSTANCE;
*/
}
return null;

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

return new ResourceCollection(resources.toArray(new Resource[0]));
}

@Override
Expand Down
Expand Up @@ -187,7 +187,8 @@ 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").list(), nullValue());
assertThat(rc1.addPath("unknown"), nullValue());
// TODO for jetty-10 assertThat(rc1.addPath("unknown").list(), nullValue());
}

@Test
Expand Down

0 comments on commit 1569437

Please sign in to comment.