@Override
    protected void analyzeDependency(final Dependency dependency, final Engine engine) throws AnalysisException {
        // batch request component-reports for all dependencies
        synchronized (FETCH_MUTIX) {
            if (reports == null) {
                try {
                    requestDelay();
                    reports = requestReports(engine.getDependencies());
                } catch (TransportException ex) {
                    final String message = ex.getMessage();
                    final boolean warnOnly = getSettings().getBoolean(Settings.KEYS.ANALYZER_OSSINDEX_WARN_ONLY_ON_REMOTE_ERRORS, false);
                    this.setEnabled(false);
                    if (StringUtils.endsWith(message, "401")) {
                        LOG.error("Invalid credentials for the OSS Index, disabling the analyzer");
                        throw new AnalysisException("Invalid credentials provided for OSS Index", ex);
                    } else if (StringUtils.endsWith(message, "403")) {
                        LOG.error("OSS Index access forbidden, disabling the analyzer");
                        throw new AnalysisException("OSS Index access forbidden", ex);
                    } else if (StringUtils.endsWith(message, "429")) {
                        if (warnOnly) {
                            LOG.warn("OSS Index rate limit exceeded, disabling the analyzer", ex);
                        } else {
                            throw new AnalysisException("OSS Index rate limit exceeded, disabling the analyzer", ex);
                        }
                    } else if (warnOnly) {
                        LOG.warn("Error requesting component reports, disabling the analyzer", ex);
                    } else {
                        LOG.debug("Error requesting component reports, disabling the analyzer", ex);
                        throw new AnalysisException("Failed to request component-reports", ex);
                    }
                } catch (SocketTimeoutException e) {
                    final boolean warnOnly = getSettings().getBoolean(Settings.KEYS.ANALYZER_OSSINDEX_WARN_ONLY_ON_REMOTE_ERRORS, false);
                    this.setEnabled(false);
                    if (warnOnly) {
                        LOG.warn("OSS Index socket timeout, disabling the analyzer", e);
                    } else {
                        LOG.debug("OSS Index socket timeout", e);
                        throw new AnalysisException("Failed to establish socket to OSS Index", e);
                    }
                } catch (Exception e) {
                    LOG.debug("Error requesting component reports", e);
                    throw new AnalysisException("Failed to request component-reports", e);
                }
            }

            // skip enrichment if we failed to fetch reports
            if (reports != null) {
                enrich(dependency);
            }
        }

    }
@Test
    public void should_enrich_be_included_in_mutex_to_prevent_NPE()
            throws Exception {

        // Given
        SproutOssIndexAnalyzer analyzer = new SproutOssIndexAnalyzer();

        Identifier identifier = new PurlIdentifier("maven", "test", "test", "1.0",
                Confidence.HIGHEST);

        Dependency dependency = new Dependency();
        dependency.addSoftwareIdentifier(identifier);
        Settings settings = getSettings();
        Engine engine = new Engine(settings);
        engine.setDependencies(Collections.singletonList(dependency));

        analyzer.initialize(settings);

        String expectedOutput = "https://ossindex.sonatype.org/component/pkg:maven/test/test@1.0";

        // When
        analyzer.analyzeDependency(dependency, engine);

        // Then
        assertTrue(identifier.getUrl().startsWith(expectedOutput));
        analyzer.awaitPendingClosure();
    }