@Override
    public List<PipelineDoc> loadPipelineStack(final PipelineDoc pipelineDoc) {
        // Load the pipeline.
        final List<PipelineDoc> pipelineList = new ArrayList<>();
        PipelineDoc parent = pipelineStore.readDocument(DocRefUtil.create(pipelineDoc));

        if (parent == null) {
            throw new RuntimeException("Unable to load pipeline: " + pipelineDoc);
        }

        pipelineList.add(0, parent);

        boolean circular = false;
        while (parent.getParentPipeline() != null && !circular) {
            final DocRef parentRef = parent.getParentPipeline();
            parent = pipelineStore.readDocument(parentRef);

            if (parent == null) {
                throw new RuntimeException("Unable to load parent pipeline: " + parentRef);
            }

            // Ensure all items in the list are unique to prevent circular
            // references.
            if (!pipelineList.contains(parent)) {
                pipelineList.add(0, parent);
            } else {
                circular = true;
                LOGGER.warn("Circular reference detected in pipeline: " + pipelineDoc.toString());
            }
        }
        return pipelineList;
    }
Loads and returns a stack of pipelines representing the inheritance
chain. The first pipeline in the chain is at the start of the list and
the last pipeline (the one we have supplied) is at the end.
<p>
This method will prevent circular pipeline references by ensuring only
unique items are added to the list.

@param pipelineDoc The pipeline that we want to load the inheritance chain for.
@return The inheritance chain for the supplied pipeline. The supplied
pipeline will be the last element in the list.
stroom-pipeline/src/main/java/stroom/pipeline/factory/PipelineStackLoaderImpl.java