Uploaded image for project: 'Maven'
  1. Maven
  2. MNG-2925

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.5
    • 2.0.9, 3.0-alpha-1
    • Plugin API
    • None

    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}

      Attachments

        Activity

          People

            siveton Siveton Vincent
            kohsuke Kohsuke Kawaguchi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: