maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Schulte (JIRA)" <j...@apache.org>
Subject [jira] [Closed] (MRESOLVER-19) DefaultRepositorySystem resolveDependencies() can yield a NullPointerException
Date Fri, 17 Mar 2017 21:08:41 GMT

     [ https://issues.apache.org/jira/browse/MRESOLVER-19?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Christian Schulte closed MRESOLVER-19.
--------------------------------------
       Resolution: Fixed
         Assignee: Christian Schulte
    Fix Version/s: Maven Artifact Resolver 1.1.0

Thanks.

> DefaultRepositorySystem resolveDependencies() can yield a NullPointerException
> ------------------------------------------------------------------------------
>
>                 Key: MRESOLVER-19
>                 URL: https://issues.apache.org/jira/browse/MRESOLVER-19
>             Project: Maven Resolver
>          Issue Type: Bug
>          Components: resolver
>    Affects Versions: Maven Artifact Resolver 1.0.3
>            Reporter: Laird Nelson
>            Assignee: Christian Schulte
>             Fix For: Maven Artifact Resolver 1.1.0
>
>
> If a transfer of an artifact fails, then a {{NullPointerException}} is thrown.
> Starting from line 366:
> {code}
> ArtifactRequestBuilder builder = new ArtifactRequestBuilder( trace );
> DependencyFilter filter = request.getFilter();
> DependencyVisitor visitor = ( filter != null ) ? new FilteringDependencyVisitor( builder,
filter ) : builder;
> visitor = new TreeDependencyVisitor( visitor );
> result.getRoot().accept( visitor ); // <-- if getRoot() is null: kaboom!
> List<ArtifactRequest> requests = builder.getRequests();
> {code}
> This is the relevant section of my code that causes the error:
> {code}
> final CollectRequest collectRequest = new CollectRequest();
> collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
> collectRequest.setRepositories(Collections.singletonList(mavenCentral));
> final DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter);
> final DependencyResult dependencyResult = repositorySystem.resolveDependencies(repositorySystemSession,
dependencyRequest);
> {code}
> From looking inside {{DefaultRepositorySystem.java}}, it looks like the collection result
never gets its root set.  At line 340 and following you see this:
> {code}
> if ( request.getRoot() != null )
> {
>     result.setRoot( request.getRoot() );
> }
> else if ( request.getCollectRequest() != null )
> {
>     CollectResult collectResult;
>     try
>     {
>         request.getCollectRequest().setTrace( trace );
>         collectResult = dependencyCollector.collectDependencies( session, request.getCollectRequest()
);
>     }
>     catch ( DependencyCollectionException e )
>     {
>         dce = e;
>         collectResult = e.getResult();
>     }
>     result.setRoot( collectResult.getRoot() );
>     result.setCycles( collectResult.getCycles() );
>     result.setCollectExceptions( collectResult.getExceptions() );
> }
> {code}
> Note in particular this line: 
> {code}
> result.setRoot( collectResult.getRoot() );
> {code}
> Unless I'm missing something there's no guarantee that {{collectResult.getRoot()}} will
be non-{{null}} if the collection request failed.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message