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

                 Key: MNG-2925
                 URL: http://jira.codehaus.org/browse/MNG-2925
             Project: Maven 2
          Issue Type: Bug
          Components: Plugin API
    Affects Versions: 2.0.5
            Reporter: Kohsuke Kawaguchi


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:

{code}
    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}

-- 
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

        

Reply via email to