Skip to content

Commit

Permalink
Fixes #5521 ResourceCollection list NPE
Browse files Browse the repository at this point in the history
NPE check.
Note that I cannot work out how the none directory resource was added in the first place, so I was unable to reproduce the exact exception.
  • Loading branch information
gregw committed Oct 28, 2020
1 parent 47885f7 commit 0dc9f6c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Expand Up @@ -571,11 +571,7 @@ public String[] list()
int size = entries.size();
return entries.toArray(new String[size]);
}
catch (DirectoryIteratorException e)
{
LOG.debug(e);
}
catch (IOException e)
catch (DirectoryIteratorException | IOException e)
{
LOG.debug(e);
}
Expand Down
Expand Up @@ -434,10 +434,12 @@ public long length()
public String[] list()
{
assertResourcesSet();

HashSet<String> set = new HashSet<>();
for (Resource r : _resources)
{
String[] list = r.list();
if (list != null)
Collections.addAll(set, list);
Collections.addAll(set, r.list());
}
String[] result = set.toArray(new String[0]);
Expand Down
Expand Up @@ -22,6 +22,7 @@
import java.io.File;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.util.Arrays;

import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
Expand All @@ -32,7 +33,9 @@
import org.junit.jupiter.api.extension.ExtendWith;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -174,6 +177,19 @@ private void assertThrowIllegalStateException(ResourceCollection coll)
});
}

@Test
public void testList() throws Exception
{
ResourceCollection rc1 = new ResourceCollection(
Resource.newResource("src/test/resources/org/eclipse/jetty/util/resource/one/"),
Resource.newResource("src/test/resources/org/eclipse/jetty/util/resource/two/"),
Resource.newResource("src/test/resources/org/eclipse/jetty/util/resource/three/"));

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());
}

@Test
public void testMultipleSources1() throws Exception
{
Expand Down

0 comments on commit 0dc9f6c

Please sign in to comment.