commit aaddebbb54ee370a589904192eef15f50761b462 Author: Alan Bateman Date: Sat Aug 26 13:59:08 2023 +0100 Initial commit diff --git a/src/java.base/share/classes/java/lang/module/Resolver.java b/src/java.base/share/classes/java/lang/module/Resolver.java index 3cd0254ba4e..cddd4d3632b 100644 --- a/src/java.base/share/classes/java/lang/module/Resolver.java +++ b/src/java.base/share/classes/java/lang/module/Resolver.java @@ -497,7 +497,6 @@ private void checkHashes() { * and m2 reads m3. */ private Map> makeGraph(Configuration cf) { - int moduleCount = nameToReference.size(); // the "reads" graph starts as a module dependence graph and @@ -537,9 +536,7 @@ private Map> makeGraph(Configuration cf) { } // populate g1 and g2 with the dependences from the selected modules - Map nameToResolved = HashMap.newHashMap(moduleCount); - for (ModuleReference mref : nameToReference.values()) { ModuleDescriptor descriptor = mref.descriptor(); String name = descriptor.name(); @@ -595,8 +592,7 @@ private Map> makeGraph(Configuration cf) { String name2 = descriptor2.name(); if (!name.equals(name2)) { - ResolvedModule m2 - = computeIfAbsent(nameToResolved, name2, cf, mref2); + ResolvedModule m2 = computeIfAbsent(nameToResolved, name2, cf, mref2); reads.add(m2); if (descriptor2.isAutomatic()) requiresTransitive.add(m2); @@ -622,29 +618,32 @@ private Map> makeGraph(Configuration cf) { g2.put(m1, requiresTransitive); } - // Iteratively update g1 until there are no more requires transitive - // to propagate + // Iteratively update g1 until there are no more requires transitive to propagate boolean changed; List toAdd = new ArrayList<>(); do { changed = false; - for (Set m1Reads : g1.values()) { - for (ResolvedModule m2 : m1Reads) { - Set m2RequiresTransitive = g2.get(m2); - if (m2RequiresTransitive != null) { - for (ResolvedModule m3 : m2RequiresTransitive) { - if (!m1Reads.contains(m3)) { - // m1 reads m2, m2 requires transitive m3 - // => need to add m1 reads m3 - toAdd.add(m3); + for (Map.Entry> e : g1.entrySet()) { + ResolvedModule m1 = e.getKey(); + if (!m1.descriptor().isAutomatic()) { + Set m1Reads = e.getValue(); + for (ResolvedModule m2 : m1Reads) { + Set m2RequiresTransitive = g2.get(m2); + if (m2RequiresTransitive != null) { + for (ResolvedModule m3 : m2RequiresTransitive) { + if (!m1Reads.contains(m3)) { + // m1 reads m2, m2 requires transitive m3 + // => need to add m1 reads m3 + toAdd.add(m3); + } } } } - } - if (!toAdd.isEmpty()) { - m1Reads.addAll(toAdd); - toAdd.clear(); - changed = true; + if (!toAdd.isEmpty()) { + m1Reads.addAll(toAdd); + toAdd.clear(); + changed = true; + } } } } while (changed);