DefaultArtifactVersion equals implementation does not handle null -----------------------------------------------------------------
Key: MNG-4227 URL: http://jira.codehaus.org/browse/MNG-4227 Project: Maven 2 Issue Type: Bug Components: Artifacts and Repositories Affects Versions: 2.2.0, 2.1.0, 2.0.10, 2.0.9, 2.0.8 Environment: Windows Vista w/ JDK 1.5.0_18 Reporter: Sean Griffin Priority: Minor A NullPointerException is possible in org.apache.maven.artifact.versioning.DefaultArtifactVersion because it simply delegates to the compareTo() method as its implementation. The compareTo method need not handle objects of a different type or null objects (and in fact does not), but the equals() method is supposed to handle these two situations. In certain cases (although I have not been able to track down the exact cause of null argument) a NPE is thrown for this reason. It's fine to call compareTo() as the equals implementation, but it should first be wrapped in an instanceof check: Change "return compareTo( other ) == 0;" to if !(other instanceof DefaultArtifactVersion) return false; return compareTo(other) == 0; This bug is exposed when using the new NetBeans 6.7 "Show Dependency Graph" functionality on certain projects. Here is the full stack trace: java.lang.NullPointerException at org.apache.maven.artifact.versioning.DefaultArtifactVersion.compareTo(DefaultArtifactVersion.java:65) at org.apache.maven.artifact.versioning.DefaultArtifactVersion.equals(DefaultArtifactVersion.java:59) at org.apache.maven.artifact.versioning.Restriction.equals(Restriction.java:164) at java.util.AbstractList.equals(AbstractList.java:507) at org.apache.maven.artifact.versioning.VersionRange.equals(VersionRange.java:568) at org.apache.maven.shared.dependency.tree.DependencyNode.nullEquals(DependencyNode.java:890) at org.apache.maven.shared.dependency.tree.DependencyNode.equals(DependencyNode.java:825) at org.netbeans.modules.maven.graph.ArtifactGraphNode.represents(ArtifactGraphNode.java:116) at org.netbeans.modules.maven.graph.DependencyGraphScene.getGraphNodeRepresentant(DependencyGraphScene.java:173) at org.netbeans.modules.maven.graph.EdgeWidget.getConflictType(EdgeWidget.java:210) at org.netbeans.modules.maven.graph.EdgeWidget.(EdgeWidget.java:85) at org.netbeans.modules.maven.graph.DependencyGraphScene.attachEdgeWidget(DependencyGraphScene.java:202) at org.netbeans.modules.maven.graph.DependencyGraphScene.attachEdgeWidget(DependencyGraphScene.java:95) at org.netbeans.api.visual.graph.GraphScene.addEdge(GraphScene.java:152) at org.netbeans.modules.maven.graph.GraphConstructor.endVisit(GraphConstructor.java:133) at org.apache.maven.shared.dependency.tree.DependencyNode.accept(DependencyNode.java:317) at org.netbeans.modules.maven.graph.DependencyGraphTopComponent$8.run(DependencyGraphTopComponent.java:416) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:577) at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:1030) -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira