Maven 2 & 3

NullPointerException in PluginDescriptor.getMojo() if there's no mojo in pom.xml

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0.5
  • Fix Version/s: 2.0.9, 3.0-alpha-1
  • Component/s: Plugin API
  • Labels:
    None
  • Complexity:
    Intermediate
  • Number of attachments :
    0

Description

The getMojo method fails with NPE because getMojos() method returns null. This happens when there's no mojo in the plugin.
The code should be modified to check for this situation, like this:


public MojoDescriptor getMojo( String goal )
{
List mojos = getMojos();
if(mojos==null) return null; // no mojo in this POM

MojoDescriptor mojoDescriptor = null;
for ( Iterator i = mojos.iterator(); i.hasNext() && mojoDescriptor == null; )
{
MojoDescriptor desc = (MojoDescriptor) i.next();
if ( goal.equals( desc.getGoal() ) )

{ mojoDescriptor = desc; }

}
return mojoDescriptor;
}

{/code}

Activity

Hide
Kohsuke Kawaguchi added a comment -

Also see MPLUGIN-32 for a relevant RFE.

Show
Kohsuke Kawaguchi added a comment - Also see MPLUGIN-32 for a relevant RFE.
Hide
Vincent Siveton added a comment -
Show
Vincent Siveton added a comment - Applied in r609576 For the next time, please provide us a patch. http://maven.apache.org/guides/development/guide-m2-development.html#Creating_and_submitting_a_patch

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: