Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 3.0-alpha-2
-
Fix Version/s: 3.0-alpha-3
-
Component/s: Artifacts and Repositories
-
Labels:None
-
Environment:Windows Vista w/ JDK 1.5.0_18
-
Complexity:Intermediate
-
Patch Submitted:Yes
-
Number of attachments :
Description
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)
I checked the code, the equals() impl looks good for all of the recent 2.x versions. This actually affects 3.x, as expected from the relation to embedded usage in an IDE.