Skip to content

Commit 3fc3557

Browse files
authored
Bugfix: Prioritized Components Cache change detection got removed (#1698)
The commit c32b8c9 added discriminator ("owner class") to key, but by mistake dropped the change detection. The original intent of that commit was to avoid hash clashes as key did not factor in owner. Also now this uses cache as intended.
1 parent fd44490 commit 3fc3557

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/PrioritizedComponents.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@
3535
*/
3636
public final class PrioritizedComponents<T> {
3737
/**
38-
* Reuses or creates and stores (if session data does not contain yet) prioritized components under certain key into
39-
* given session. Same session is used to configure prioritized components, so priority sorted components during
40-
* session are immutable and reusable.
38+
* Reuses or creates and caches (if session is equipped with cache, and it does not contain it yet)
39+
* prioritized components under certain key into session cache. Same session is used to configure prioritized
40+
* components, so priority sorted components during session are immutable and reusable (if {@code components}
41+
* component map is unchanged).
4142
* <p>
42-
* The {@code components} are expected to be Sisu injected {@link Map<String, C>}-like component maps. There is a
43+
* The {@code components} are expected to be Sisu injected {@link Map}-like dynamic component maps. There is a
4344
* simple "change detection" in place, as injected maps are dynamic, they are atomically expanded or contracted
4445
* as components are dynamically discovered or unloaded.
4546
*
@@ -53,10 +54,11 @@ public static <C> PrioritizedComponents<C> reuseOrCreate(
5354
Function<C, Float> priorityFunction) {
5455
boolean cached = ConfigUtils.getBoolean(
5556
session, ConfigurationProperties.DEFAULT_CACHED_PRIORITIES, ConfigurationProperties.CACHED_PRIORITIES);
56-
if (cached) {
57-
String key = PrioritizedComponents.class.getName() + ".pc." + discriminator.getName();
58-
return (PrioritizedComponents<C>)
59-
session.getData().computeIfAbsent(key, () -> create(session, components, priorityFunction));
57+
if (cached && session.getCache() != null) {
58+
String key = PrioritizedComponents.class.getName() + ".pc." + discriminator.getName()
59+
+ Integer.toHexString(components.hashCode());
60+
return (PrioritizedComponents<C>) session.getCache()
61+
.computeIfAbsent(session, key, () -> create(session, components, priorityFunction));
6062
} else {
6163
return create(session, components, priorityFunction);
6264
}

0 commit comments

Comments
 (0)