Hi all,
I have a custom enforcer rule that occasionally is failing as
DefaultArtifact is throwing a NullPointerException when calling
getSelectedVersion()
Looking at the code for DefaultArtifact it appears there was a related
error which has been fixed in getVersionRange (which could have
returened null) however getSelectedVersion blindly uses the versionRange
field and not the getter which protects it.
This is with Maven 2.2.1 (and also happens in 2.0.9) running on jdk
1.6.0_7.
[INFO] [INFO] Trace
[INFO] java.lang.NullPointerException
[INFO] at
org.apache.maven.artifact.DefaultArtifact.getSelectedVersion(DefaultArti
fact.java:621)
[INFO] at
com.nds.cab.build.enforcer.EngineeringReleaseRule.execute(EngineeringRel
easeRule.java:69)
[INFO] at
org.apache.maven.plugins.enforcer.EnforceMojo.execute(EnforceMojo.java:1
85)
[INFO] at
org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginMa
nager.java:490)
I wonder really if DefaultArtifact.setVersion() shouldn't null the
versionRange but recreate it, or if there is something else at play - or
if am I doing something wrong in my enforcer rule?
public void execute(EnforcerRuleHelper helper) throws
EnforcerRuleException {
try {
// the following results in a bogus POM during
some phases
// MavenProject project = (MavenProject)
helper.evaluate( "${project}" );
MavenSession session = (MavenSession)
helper.evaluate("${session}");
MavenProject project =
session.getCurrentProject();
Properties props =
session.getExecutionProperties();
// check the dependencies for any engineering
release.
Set dependencies = project.getArtifacts();
Iterator i = dependencies.iterator();
while (i.hasNext()) {
Artifact artifact = (Artifact) i.next();
if
(isEngineeringVersion(artifact.getSelectedVersion())) {
// !!! the above line causes the
null pointer !!!
Not all projects exhibit this behaviour - and in multi-module projects
several modules can pass before it hits one that it doesn't like.
/James
**************************************************************************************
This message is confidential and intended only for the addressee. If you have
received this message in error, please immediately notify the
[email protected] and delete it from your system as well as any copies. The
content of e-mails as well as traffic data may be monitored by NDS for
employment and security purposes. To protect the environment please do not
print this e-mail unless necessary.
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX,
United Kingdom. A company registered in England and Wales. Registered no.
3080780. VAT no. GB 603 8808 40-00
**************************************************************************************