This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git


The following commit(s) were added to refs/heads/master by this push:
     new c32b8c92 [MRESOLVER-628] Explicit cache key for prioritized components 
(#601)
c32b8c92 is described below

commit c32b8c9236389ee04ab5d0aac3d206f8bb1b2f36
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Thu Nov 14 11:46:18 2024 +0100

    [MRESOLVER-628] Explicit cache key for prioritized components (#601)
    
    As original solution using map.hashCode may clash, and in
    that case runtime "just in time" class clast issue happens.
    
    Rather provide explicit discriminator class "what is in maps"
    and use that to create key to cache in session.
    
    ---
    
    https://issues.apache.org/jira/browse/MRESOLVER-628
---
 .../aether/internal/impl/DefaultLocalRepositoryProvider.java |  5 ++++-
 .../internal/impl/DefaultRepositoryConnectorProvider.java    |  2 +-
 .../internal/impl/DefaultRepositoryLayoutProvider.java       |  4 ++--
 .../aether/internal/impl/DefaultTransporterProvider.java     |  4 ++--
 .../eclipse/aether/internal/impl/PrioritizedComponents.java  | 12 ++++++++----
 .../main/java/org/eclipse/aether/internal/impl/Utils.java    |  9 ++++++---
 6 files changed, 23 insertions(+), 13 deletions(-)

diff --git 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultLocalRepositoryProvider.java
 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultLocalRepositoryProvider.java
index e2c23e65..3556cab9 100644
--- 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultLocalRepositoryProvider.java
+++ 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultLocalRepositoryProvider.java
@@ -60,7 +60,10 @@ public class DefaultLocalRepositoryProvider implements 
LocalRepositoryProvider {
         requireNonNull(repository, "repository cannot be null");
 
         PrioritizedComponents<LocalRepositoryManagerFactory> factories = 
PrioritizedComponents.reuseOrCreate(
-                session, localRepositoryManagerFactories, 
LocalRepositoryManagerFactory::getPriority);
+                session,
+                LocalRepositoryManagerFactory.class,
+                localRepositoryManagerFactories,
+                LocalRepositoryManagerFactory::getPriority);
 
         List<NoLocalRepositoryManagerException> errors = new ArrayList<>();
         for (PrioritizedComponent<LocalRepositoryManagerFactory> factory : 
factories.getEnabled()) {
diff --git 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositoryConnectorProvider.java
 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositoryConnectorProvider.java
index c913dd15..859d06cb 100644
--- 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositoryConnectorProvider.java
+++ 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositoryConnectorProvider.java
@@ -78,7 +78,7 @@ public class DefaultRepositoryConnectorProvider implements 
RepositoryConnectorPr
         }
 
         PrioritizedComponents<RepositoryConnectorFactory> factories = 
PrioritizedComponents.reuseOrCreate(
-                session, connectorFactories, 
RepositoryConnectorFactory::getPriority);
+                session, RepositoryConnectorFactory.class, connectorFactories, 
RepositoryConnectorFactory::getPriority);
 
         RemoteRepositoryFilter filter = 
remoteRepositoryFilterManager.getRemoteRepositoryFilter(session);
         List<NoRepositoryConnectorException> errors = new ArrayList<>();
diff --git 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositoryLayoutProvider.java
 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositoryLayoutProvider.java
index 6671505b..35483084 100644
--- 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositoryLayoutProvider.java
+++ 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositoryLayoutProvider.java
@@ -59,8 +59,8 @@ public final class DefaultRepositoryLayoutProvider implements 
RepositoryLayoutPr
         requireNonNull(session, "session cannot be null");
         requireNonNull(repository, "remote repository cannot be null");
 
-        PrioritizedComponents<RepositoryLayoutFactory> factories =
-                PrioritizedComponents.reuseOrCreate(session, layoutFactories, 
RepositoryLayoutFactory::getPriority);
+        PrioritizedComponents<RepositoryLayoutFactory> factories = 
PrioritizedComponents.reuseOrCreate(
+                session, RepositoryLayoutFactory.class, layoutFactories, 
RepositoryLayoutFactory::getPriority);
 
         List<NoRepositoryLayoutException> errors = new ArrayList<>();
         for (PrioritizedComponent<RepositoryLayoutFactory> factory : 
factories.getEnabled()) {
diff --git 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTransporterProvider.java
 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTransporterProvider.java
index dabe36fb..b494a1bf 100644
--- 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTransporterProvider.java
+++ 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTransporterProvider.java
@@ -59,8 +59,8 @@ public final class DefaultTransporterProvider implements 
TransporterProvider {
         requireNonNull(session, "session cannot be null");
         requireNonNull(repository, "repository cannot be null");
 
-        PrioritizedComponents<TransporterFactory> factories =
-                PrioritizedComponents.reuseOrCreate(session, 
transporterFactories, TransporterFactory::getPriority);
+        PrioritizedComponents<TransporterFactory> factories = 
PrioritizedComponents.reuseOrCreate(
+                session, TransporterFactory.class, transporterFactories, 
TransporterFactory::getPriority);
 
         List<NoTransporterException> errors = new ArrayList<>();
         for (PrioritizedComponent<TransporterFactory> factory : 
factories.getEnabled()) {
diff --git 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/PrioritizedComponents.java
 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/PrioritizedComponents.java
index 8a5c917c..3fe020f9 100644
--- 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/PrioritizedComponents.java
+++ 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/PrioritizedComponents.java
@@ -35,8 +35,9 @@ import org.eclipse.aether.util.ConfigUtils;
  */
 public final class PrioritizedComponents<T> {
     /**
-     * Reuses or creates and stores (if session data does not contain yet) 
prioritized components under this key into
-     * given session. Same session is used to configure prioritized components.
+     * Reuses or creates and stores (if session data does not contain yet) 
prioritized components under certain key into
+     * given session. Same session is used to configure prioritized 
components, so priority sorted components during
+     * session are immutable and reusable.
      * <p>
      * The {@code components} are expected to be Sisu injected {@link 
Map<String, C>}-like component maps. There is a
      * simple "change detection" in place, as injected maps are dynamic, they 
are atomically expanded or contracted
@@ -46,11 +47,14 @@ public final class PrioritizedComponents<T> {
      */
     @SuppressWarnings("unchecked")
     public static <C> PrioritizedComponents<C> reuseOrCreate(
-            RepositorySystemSession session, Map<String, C> components, 
Function<C, Float> priorityFunction) {
+            RepositorySystemSession session,
+            Class<C> discriminator,
+            Map<String, C> components,
+            Function<C, Float> priorityFunction) {
         boolean cached = ConfigUtils.getBoolean(
                 session, ConfigurationProperties.DEFAULT_CACHED_PRIORITIES, 
ConfigurationProperties.CACHED_PRIORITIES);
         if (cached) {
-            String key = PrioritizedComponents.class.getName() + ".pc" + 
Integer.toHexString(components.hashCode());
+            String key = PrioritizedComponents.class.getName() + ".pc." + 
discriminator.getName();
             return (PrioritizedComponents<C>)
                     session.getData().computeIfAbsent(key, () -> 
create(session, components, priorityFunction));
         } else {
diff --git 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/Utils.java 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/Utils.java
index dbebe6e5..87cb48ae 100644
--- 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/Utils.java
+++ 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/Utils.java
@@ -48,7 +48,8 @@ public final class Utils {
 
     private static PrioritizedComponents<ArtifactDecoratorFactory> 
sortArtifactDecoratorFactories(
             RepositorySystemSession session, Map<String, 
ArtifactDecoratorFactory> factories) {
-        return PrioritizedComponents.reuseOrCreate(session, factories, 
ArtifactDecoratorFactory::getPriority);
+        return PrioritizedComponents.reuseOrCreate(
+                session, ArtifactDecoratorFactory.class, factories, 
ArtifactDecoratorFactory::getPriority);
     }
 
     public static List<? extends ArtifactDecorator> getArtifactDecorators(
@@ -67,7 +68,8 @@ public final class Utils {
 
     private static PrioritizedComponents<ArtifactGeneratorFactory> 
sortArtifactGeneratorFactories(
             RepositorySystemSession session, Map<String, 
ArtifactGeneratorFactory> factories) {
-        return PrioritizedComponents.reuseOrCreate(session, factories, 
ArtifactGeneratorFactory::getPriority);
+        return PrioritizedComponents.reuseOrCreate(
+                session, ArtifactGeneratorFactory.class, factories, 
ArtifactGeneratorFactory::getPriority);
     }
 
     private static List<? extends ArtifactGenerator> doGetArtifactGenerators(
@@ -107,7 +109,8 @@ public final class Utils {
 
     private static PrioritizedComponents<MetadataGeneratorFactory> 
sortMetadataGeneratorFactories(
             RepositorySystemSession session, Map<String, 
MetadataGeneratorFactory> factories) {
-        return PrioritizedComponents.reuseOrCreate(session, factories, 
MetadataGeneratorFactory::getPriority);
+        return PrioritizedComponents.reuseOrCreate(
+                session, MetadataGeneratorFactory.class, factories, 
MetadataGeneratorFactory::getPriority);
     }
 
     private static List<? extends MetadataGenerator> doGetMetadataGenerators(

Reply via email to