WIth Maven 2.2.0 i'm getting an N.P.E from DefaultArtifact when calling
getSelectedVersion on a dependency.
 
This is in a multimodule project - and several modules build fine before
I hit the one that constantly failes.
 
[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:483)

The code in question (below) is an enforcer rule that does the following
- which looks ok to me.
 
Looking at the DefaultArtifact code there is the following comment
513
<http://maven.apache.org/ref/2.2.0/xref/org/apache/maven/artifact/Defaul
tArtifact.html#513>          // I am assuming this is happening as a
result of the MNG-1577 work, but somehow the value
514
<http://maven.apache.org/ref/2.2.0/xref/org/apache/maven/artifact/Defaul
tArtifact.html#514>          // of versionRange just goes null or is not
set. But this is happeningin Yoko and the value is
515
<http://maven.apache.org/ref/2.2.0/xref/org/apache/maven/artifact/Defaul
tArtifact.html#515>          // set when attaching the JAR and not set
when attaching the test JAR.
516
<http://maven.apache.org/ref/2.2.0/xref/org/apache/maven/artifact/Defaul
tArtifact.html#516>          if ( versionRange == null )
517
<http://maven.apache.org/ref/2.2.0/xref/org/apache/maven/artifact/Defaul
tArtifact.html#517>          {
518
<http://maven.apache.org/ref/2.2.0/xref/org/apache/maven/artifact/Defaul
tArtifact.html#518>              versionRange =
VersionRange.createFromVersion( version );
519
<http://maven.apache.org/ref/2.2.0/xref/org/apache/maven/artifact/Defaul
tArtifact.html#519>          }

However - the defaultArtifactHandler itself doesn't call getVersionRange
but uses the field diretly, which to me seems a little strange.
        
    public void execute(EnforcerRuleHelper helper) throws
EnforcerRuleException {

           // 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(); if
(props.containsKey("skipEngineeringReleaseRule")) { log.warn("Skipping
EngineeringReleaseRule (user requested)"); } else if (
project.getArtifact().isSnapshot() ) { // snapshots can contain
engineering versions } else if
(isEngineeringVersion(project.getArtifact().getSelectedVersion())) { //
project is an engineering version so engineering versions are allowed! }
else { // we are a release version so check the dependencies for any
engineering release. log.info("Checking for engineering dependencies");
Set dependencies = project.getArtifacts(); 66: Iterator i =
dependencies.iterator(); 67: while (i.hasNext()) { 68: Artifact artifact
= (Artifact) i.next(); 69:        if
(isEngineeringVersion(artifact.getSelectedVersion())) { 70: //
Engineering releases only come from NDS! 71: if
(artifact.getGroupId().startsWith("com.mycorp")) { throw new
EnforcerRuleException(ERROR_MSG); } } } } 
Am i doing somehting I'm not supposed to?  the quick and dirty is for me
to add a call to getVersionRange() before getSelectedVersion() but this
is masking the issue not nescesarily fixing it and if something deep
down is broken it doesn't leave me with a warm fuzzy feeling.
 
/James
 

**************************************************************************************
This message is confidential and intended only for the addressee. If you have 
received this message in error, please immediately notify the 
postmas...@nds.com 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
**************************************************************************************

Reply via email to