Maven 2 & 3

Extensions are subject to NPEs in their hashCode() impl

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0.10
  • Fix Version/s: 2.0.10
  • Component/s: Dependencies
  • Labels:
    None
  • Complexity:
    Intermediate
  • Number of attachments :
    0

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

Issue Links

Activity

Hide
Benjamin Bentmann added a comment -

Looks like the hashCode() methods are actually hand-written in the MDOs, makes things easy to fix.

Show
Benjamin Bentmann added a comment - Looks like the hashCode() methods are actually hand-written in the MDOs, makes things easy to fix.
Hide
Benjamin Bentmann added a comment -

Fixed in r727548, r727553, r727555 and r727561, respectively.

Show
Benjamin Bentmann added a comment - Fixed in r727548, r727553, r727555 and r727561, respectively.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: