o Fix potential recursion in hashCode with parent.hashCode by using parent's artifact only
o Aligned equals to also use parent's artifact only
git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@651439 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyNode.java b/src/main/java/org/apache/maven/shared/dependency/tree/DependencyNode.java
index c759d78..ea27dca 100644
--- a/src/main/java/org/apache/maven/shared/dependency/tree/DependencyNode.java
+++ b/src/main/java/org/apache/maven/shared/dependency/tree/DependencyNode.java
@@ -774,11 +774,12 @@
{
int hashCode = 1;
- hashCode = hashCode * 31 + nullHashCode( getParent() );
hashCode = hashCode * 31 + getArtifact().hashCode();
-
// DefaultArtifact.hashCode does not consider scope
hashCode = hashCode * 31 + nullHashCode( getArtifact().getScope() );
+
+ // TODO: use parent's artifact to prevent recursion - how can we improve this?
+ hashCode = hashCode * 31 + nullHashCode( nullGetArtifact( getParent() ) );
hashCode = hashCode * 31 + getChildren().hashCode();
hashCode = hashCode * 31 + getState();
@@ -805,12 +806,13 @@
{
DependencyNode node = (DependencyNode) object;
- // TODO: no parent.equals() to prevent recursion
equal = getArtifact().equals( node.getArtifact() );
-
// DefaultArtifact.hashCode does not consider scope
equal &= nullEquals( getArtifact().getScope(), node.getArtifact().getScope() );
+ // TODO: use parent's artifact to prevent recursion - how can we improve this?
+ equal &= nullEquals( nullGetArtifact( getParent() ), nullGetArtifact( node.getParent() ) );
+
equal &= getChildren().equals( node.getChildren() );
equal &= getState() == node.getState();
equal &= nullEquals( getRelatedArtifact(), node.getRelatedArtifact() );
@@ -885,4 +887,16 @@
{
return ( a == null ? b == null : a.equals( b ) );
}
+
+ /**
+ * Gets the artifact for the specified node.
+ *
+ * @param node
+ * the dependency node, possibly <code>null</code>
+ * @return the node's artifact, or <code>null</code> if the specified node was <code>null</code>
+ */
+ private static Artifact nullGetArtifact( DependencyNode node )
+ {
+ return ( node != null ) ? node.getArtifact() : null;
+ }
}