Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #5521 ResourceCollection list NPE #5523

Merged
merged 4 commits into from Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,11 +434,12 @@ public long length()
public String[] list()
{
assertResourcesSet();

HashSet<String> set = new HashSet<>();
for (Resource r : _resources)
{
Collections.addAll(set, r.list());
String[] list = r.list();
if (list != null)
Collections.addAll(set, list);
}
String[] result = set.toArray(new String[0]);
Arrays.sort(result);
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,20 @@ 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());
// TODO for jetty-10 assertThat(rc1.addPath("unknown").list(), nullValue());
}

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