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

StackOverflowError when version ranges are unsolvable and graph contains a cycle

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.6.1
    • 3.8.2, 4.0.0-alpha-2, 4.0.0
    • None
    • None

    Description

      Maven throws StackOverflowError when version ranges are unsolvable and the dependency graph contains a cycle.

      $ 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)...
       

      Example 

      Example project to reproduce the issue:  https://github.com/suztomo/maven-cyclic-dependency-with-range 

      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 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.

       

      private UnsolvableVersionConflictException newFailure( final ConflictContext context )
      {
       ...
       PathRecordingDependencyVisitor visitor = new PathRecordingDependencyVisitor( filter );
       context.getRoot().accept( visitor );
       return new UnsolvableVersionConflictException( visitor.getPaths() );
      }

       

      The cycle in the graph consists of module-a and module-b as illustrated below:

      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
         ...

       

      Attachments

        Issue Links

          Activity

            People

              michael-o Michael Osipov
              suztomo Tomo Suzuki
              Votes:
              2 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: