sanjana2505006 commented on code in PR #270:
URL: 
https://github.com/apache/maven-dependency-analyzer/pull/270#discussion_r3003344776


##########
src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java:
##########
@@ -226,19 +230,14 @@ private static Set<Artifact> 
buildDeclaredArtifacts(MavenProject project) {
     }
 
     private static Map<Artifact, Set<DependencyUsage>> buildUsedArtifacts(
-            Map<Artifact, Set<String>> artifactClassMap, Set<DependencyUsage> 
dependencyClasses) {
+            Map<String, Artifact> classToArtifactMap, Set<DependencyUsage> 
dependencyClasses) {
         Map<Artifact, Set<DependencyUsage>> usedArtifacts = new HashMap<>();
 
         for (DependencyUsage classUsage : dependencyClasses) {
-            Artifact artifact = findArtifactForClassName(artifactClassMap, 
classUsage.getDependencyClass());
+            Artifact artifact = 
classToArtifactMap.get(classUsage.getDependencyClass());
 
             if (artifact != null && !includedInJDK(artifact)) {
-                Set<DependencyUsage> classesFromArtifact = 
usedArtifacts.get(artifact);
-                if (classesFromArtifact == null) {
-                    classesFromArtifact = new HashSet<>();
-                    usedArtifacts.put(artifact, classesFromArtifact);
-                }
-                classesFromArtifact.add(classUsage);
+                usedArtifacts.computeIfAbsent(artifact, k -> new 
HashSet<>()).add(classUsage);
             }
         }

Review Comment:
   That's a fair point. I'll add focused unit tests covering the new 
class-to-artifact resolution path, including duplicate-class scenarios, to 
ensure the chosen artifact is deterministic. Will update it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to