mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
findResources("SomeDir/") fails (IDEA-182329)
This commit is contained in:
@@ -266,19 +266,16 @@ public class ClassPath {
|
||||
List<Loader> loaders = null;
|
||||
|
||||
if (myCanUseCache && myAllUrlsWereProcessed) {
|
||||
boolean nameIsDirectory = name.endsWith("/");
|
||||
Collection<Loader> loadersSet = nameIsDirectory ? new SmartList<Loader>() : new LinkedHashSet<Loader>();
|
||||
Collection<Loader> loadersSet = new LinkedHashSet<Loader>();
|
||||
myCache.iterateLoaders(name, ourLoaderCollector, loadersSet, this);
|
||||
|
||||
if (!nameIsDirectory) {
|
||||
if (name.endsWith("/")) {
|
||||
myCache.iterateLoaders(name.substring(0, name.length() - 1), ourLoaderCollector, loadersSet, this);
|
||||
} else {
|
||||
myCache.iterateLoaders(name.concat("/"), ourLoaderCollector, loadersSet, this);
|
||||
}
|
||||
|
||||
if (nameIsDirectory) {
|
||||
loaders = (List<Loader>)loadersSet;
|
||||
} else {
|
||||
loaders = new ArrayList<Loader>(loadersSet);
|
||||
}
|
||||
loaders = new ArrayList<Loader>(loadersSet);
|
||||
}
|
||||
|
||||
myLoaders = loaders;
|
||||
|
||||
@@ -17,8 +17,7 @@ package com.intellij.util.lang;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.ConcurrencyUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -218,4 +217,43 @@ public class UrlClassLoaderTest {
|
||||
return loader.findResource(name);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindDirWhenUsingCache() throws IOException {
|
||||
int counter = 1;
|
||||
for (String dirName : new String[]{ "dir", "dir/", "dir.class", "dir.class/"}) {
|
||||
for(String resourceName: new String[] {"a.class", "a.txt"} ) {
|
||||
File root = FileUtil.createTempDirectory("testFindDirWhenUsingCache", String.valueOf(counter++));
|
||||
File subDir = createTestDir(root, dirName);
|
||||
createTestFile(subDir, resourceName);
|
||||
|
||||
URL url = root.toURI().toURL();
|
||||
URLClassLoader standardCl = new URLClassLoader(new URL[] {url});
|
||||
|
||||
try {
|
||||
Enumeration<URL> resources = standardCl.findResources(dirName);
|
||||
assertTrue(resources.hasMoreElements());
|
||||
URL expectedResourceUrl = resources.nextElement();
|
||||
|
||||
withCustomCachedClassloader(url, (customCl) -> {
|
||||
assertNull(customCl.findResource("SomeNonExistentResource.resource"));
|
||||
checkResourceUrlIsTheSame(customCl, dirName, expectedResourceUrl);
|
||||
});
|
||||
withCustomCachedClassloader(url, (customCl) -> checkResourceUrlIsTheSame(customCl, dirName, expectedResourceUrl));
|
||||
} finally {
|
||||
standardCl.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkResourceUrlIsTheSame(UrlClassLoader customCl, String resourceName, URL expectedResourceUrl) throws IOException {
|
||||
Enumeration<URL> customClResources = customCl.findResources(resourceName);
|
||||
assertTrue(customClResources.hasMoreElements());
|
||||
assertEquals(expectedResourceUrl, customClResources.nextElement());
|
||||
}
|
||||
|
||||
private static void withCustomCachedClassloader(URL url, ThrowableConsumer<UrlClassLoader, IOException> testAction) throws IOException {
|
||||
testAction.consume(UrlClassLoader.build().useCache().urls(url).get());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user