You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Guillaume Nodet (Jira)" <ji...@apache.org> on 2022/10/20 08:11:02 UTC

[jira] [Updated] (MNG-6737) StackOverflowError when version ranges are unsolvable and graph contains a cycle

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

Guillaume Nodet updated MNG-6737:
---------------------------------
    Fix Version/s: 4.0.0-alpha-2

> StackOverflowError when version ranges are unsolvable and graph contains a cycle
> --------------------------------------------------------------------------------
>
>                 Key: MNG-6737
>                 URL: https://issues.apache.org/jira/browse/MNG-6737
>             Project: Maven
>          Issue Type: Bug
>    Affects Versions: 3.6.1
>            Reporter: Tomo Suzuki
>            Assignee: Michael Osipov
>            Priority: Major
>             Fix For: 3.8.2, 4.0.0-alpha-1, 4.0.0-alpha-2, 4.0.0
>
>
> Maven throws StackOverflowError when version ranges are unsolvable and the dependency graph contains a cycle.
> {code:java}
> $ mvn install
> ...
> [INFO] --------------------------< suztomo:module-c >--------------------------
> [INFO] Building module-c 1.0
> [INFO] --------------------------------[ jar ]---------------------------------
> [INFO] ------------------------------------------------------------------------
> [INFO] BUILD FAILURE
> [INFO] ------------------------------------------------------------------------
> [INFO] Total time:  0.406 s
> [INFO] Finished at: 2019-08-16T12:10:30-04:00
> [INFO] ------------------------------------------------------------------------
> ...
> Exception in thread "main" java.lang.StackOverflowError
> 	at org.eclipse.aether.graph.DefaultDependencyNode.accept(DefaultDependencyNode.java:341)
> 	at org.eclipse.aether.graph.DefaultDependencyNode.accept(DefaultDependencyNode.java:345)
> 	at org.eclipse.aether.graph.DefaultDependencyNode.accept(DefaultDependencyNode.java:345)
> 	at org.eclipse.aether.graph.DefaultDependencyNode.accept(DefaultDependencyNode.java:345)
> 	at org.eclipse.aether.graph.DefaultDependencyNode.accept(DefaultDependencyNode.java:345)
> 	at org.eclipse.aether.graph.DefaultDependencyNode.accept(DefaultDependencyNode.java:345)
> ...(omitting many lines)...
>  {code}
> h1. Example 
> Example project to reproduce the issue:  [https://github.com/suztomo/maven-cyclic-dependency-with-range] 
> h1. Diagnosis
> In the example above, because of a version conflict on grpc-core (1.21.0 v.s. 1.16.1), [org.eclipse.aether.util.graph.transformer.NearestVersionSelector.newFailure|https://github.com/apache/maven-resolver/blob/maven-resolver-1.4.0/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/transformer/NearestVersionSelector.java#L158] tries to throw UnsolvableVersionConflictExceptoin. However, before throwing the exception PathRecordingDependencyVisitor visits nodes in the dependency graph and the graph contains a cycle. The visitor goes to infinite recursion in visiting the cyclic path, resulting in StackOverflowError.
>  
> {code:java}
> private UnsolvableVersionConflictException newFailure( final ConflictContext context )
> {
>  ...
>  PathRecordingDependencyVisitor visitor = new PathRecordingDependencyVisitor( filter );
>  context.getRoot().accept( visitor );
>  return new UnsolvableVersionConflictException( visitor.getPaths() );
> }{code}
>  
> The cycle in the graph consists of module-a and module-b as illustrated below:
> {code:java}
> module-c:1.0.0
> +- module-b:2.0.0
>  +- module-a:1.0.0
>  +- module-b:0.0.1
>  +- module-b:1.0.0
>  | +- module-a:1.0.0
>  | +- module-b:0.0.1
>  | +- module-b:1.0.0
>    ...{code}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)