8000 Why does FeatureContext return the previous FeatureManager? · Issue #1228 · togglz/togglz · GitHub
[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does FeatureContext return the previous FeatureManager? #1228

Open
kevinm416 opened this issue Jan 17, 2025 · 0 comments
Open

Why does FeatureContext return the previous FeatureManager? #1228

kevinm416 opened this issue Jan 17, 2025 · 0 comments

Comments

@kevinm416
Copy link

I'm looking at FeatureManager.getFeatureManagerOrNull in v4.4.0:

    public static FeatureManager getFeatureManagerOrNull() {
        ClassLoader classLoader = getContextClassLoader();
        FeatureManager featureManager = cache.get(classLoader);
        if (featureManager != null) {
            return featureManager;
        }
        featureManager = findFeatureManagerInClassLoader(classLoader);
        if (featureManager != null) {
            FeatureManager previousFeatureManager = cache.putIfAbsent(classLoader, featureManager);
            if (previousFeatureManager != null) {
                // Return FeatureManager that was inserted first
                return previousFeatureManager; // <--------------- Why?
            }
        }
        return featureManager;
    }

I think that this might be causing spurious test failures, because I'm getting test failures related to feature flags for the first test that runs in the suite. I think it might be caused by the wrong feature manager being returned from this method but haven't proved that yet.

Regardless of my test failures, can anyone explain why returning previousFeatureManager is the correct behavior for this method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0