Skip to content

Commit b587c3e

Browse files
committed
YAMLOpInfoDiscoverer: fix resource iteration bugs
1. If thread context class loader is null, use the system class loader. 2. When iterating the resources enumeration, process all elements. 3. When iterating resources, only process each unique URL once.
1 parent 15f4a1b commit b587c3e

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

‎scijava/scijava-ops-engine/src/main/java/org/scijava/ops/engine/yaml/impl/YAMLOpInfoDiscoverer.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Optional;
1616
import java.util.ServiceLoader;
1717

18+
import org.scijava.common3.Classes;
1819
import org.scijava.discovery.Discoverer;
1920
import org.scijava.ops.api.OpInfo;
2021
import org.scijava.ops.engine.yaml.YAMLOpInfoCreator;
@@ -42,9 +43,10 @@ public <U> List<U> discover(Class<U> c) {
4243
Enumeration<URL> opFiles = getOpYAML();
4344
// Parse each YAML file
4445
List<OpInfo> opInfos = new ArrayList<>();
45-
opFiles.asIterator().forEachRemaining(opFile -> {
46+
Collections.list(opFiles).stream().distinct().forEach(opFile -> {
47+
System.out.println("--------> " + opFile);
4648
try {
47-
parse(opInfos, opFiles.nextElement());
49+
parse(opInfos, opFile);
4850
}
4951
catch (IOException e) {
5052
throw new IllegalArgumentException( //
@@ -62,9 +64,7 @@ public <U> List<U> discover(Class<U> c) {
6264
*/
6365
private Enumeration<URL> getOpYAML() {
6466
try {
65-
return Thread.currentThread() //
66-
.getContextClassLoader() //
67-
.getResources("op.yaml");
67+
return Classes.classLoader().getResources("op.yaml");
6868
}
6969
catch (IOException e) {
7070
throw new RuntimeException("Could not load Op YAML files!", e);

0 commit comments

Comments
 (0)