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

Extensions are subject to NPEs in their hashCode() impl

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.10
    • 2.0.10
    • Dependencies
    • None

    Description

      From Henrique Prange on the user list:

      java.lang.NullPointerException
              at org.apache.maven.model.Extension.hashCode(Extension.java:147)
              at java.lang.Object.toString(Object.java:219)
              at java.lang.String.valueOf(String.java:2827)
              at java.lang.StringBuffer.append(StringBuffer.java:219)
              at org.apache.maven.lifecycle.DefaultLifecycleExecutor.findExtensions(DefaultLifecycleExecutor.java:157)
              at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140)
              at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
              at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
              at org.apache.maven.cli.MavenCli.main(MavenCli.java:301)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
              at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
              at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
              at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
      

      The actual bug is in the hashCode() impl generated by Modello:

      public int hashCode()
      {
          int result = 17;
          result = 37 * result + getArtifactId() != null ? getArtifactId().hashCode() : 0;
          result = 37 * result + getGroupId() != null ? getGroupId().hashCode() : 0;
          result = 37 * result + getVersion() != null ? getVersion().hashCode() : 0;
          return result;
      }
      

      due to operator precedence, this ends up being like

          result = ( 37 * result + getVersion() ) != null ? getVersion().hashCode() : 0;
      

      i.e. always triggering the call to getVersion() as the string concatenation delivers a non-null result.

      This bug is also present in at least Maven 2.0.9, but went unnoticed. It was now triggered by a debug statement added in r724969

      Attachments

        Issue Links

          Activity

            People

              bentmann Benjamin Bentmann
              bentmann Benjamin Bentmann
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: