private ChainSpecification resolveChain(Deque<ComponentId> path,
                                            Resolver<ChainSpecification> allChainSpecifications,
                                            ComponentSpecification chainSpecification) {

        ChainSpecification chain = allChainSpecifications.resolve(chainSpecification);
        if (chain == null) {
            throw new RuntimeException("Missing chain '" + chainSpecification + "'.");
        } else if (path.contains(chain.componentId)) {
            throw new RuntimeException("The chain " + chain.componentId + " inherits(possibly indirectly) from itself.");
        } else {
            return chain;
        }
    }
@param allChainSpecifications resolves ChainSpecifications from ComponentSpecifications
                              as given in the inheritance fields.
@param path tracks which chains are used in each recursive invocation of flatten, used for detecting cycles.
@return ChainSpecification directly containing all the component references and phases of the inherited chains.
container-core/src/main/java/com/yahoo/component/chain/model/ChainSpecification.java