Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Conversation

@tbruyelle
Copy link
Contributor

Related to #674

When a bean is injected in another class which has a different Context
from the required @rootcontext field class, the field is left null. This
could produce hard to find bugs. The fix adds a log to warn the user.

The generated code from EnhancedClass_ :

 @SuppressWarnings("all")
    private void init_() {
        if (context_ instanceof Activity) {
            Activity activity = ((Activity) context_);
        }
        OnViewChangedNotifier.registerOnViewChangedListener(this);
        Resources resources_ = context_.getResources();
        hello = resources_.getString(string.hello);
        activityManager = ((ActivityManager) context_.getSystemService(Context.ACTIVITY_SERVICE));
        customApplication = SampleRoboApplication_.getInstance();
        if (context_ instanceof ThreadActivity) {
            threadActivity = ((ThreadActivity) context_);
        } else {
            Log.w("EnhancedClass_", (("Due to Context class "+ context_.getClass().getSimpleName())+", the @RootContext ThreadActivity won't be populated"));
        }
        context = context_;
        if (context_ instanceof Service) {
            service = ((Service) context_);
        } else {
            Log.w("EnhancedClass_", (("Due to Context class "+ context_.getClass().getSimpleName())+", the @RootContext Service won't be populated"));
        }
        if (context_ instanceof Activity) {
            activity = ((Activity) context_);
        } else {
            Log.w("EnhancedClass_", (("Due to Context class "+ context_.getClass().getSimpleName())+", the @RootContext Activity won't be populated"));
        }
        secondDependency = SecondDependency_.getInstance_(context_);
        calledAfterInjection();
    }

I don't know very well Codemodel yet, please check if I used it well.

When a bean is injected in another class which has a different Context
from the required @rootcontext field class, the field is left null. This
could produce hard to find bugs. The fix adds a log to warn the user.
DayS added a commit that referenced this pull request Jul 26, 2013
@DayS DayS merged commit 4b0abd6 into androidannotations:develop Jul 26, 2013
@DayS
Copy link
Contributor

DayS commented Jul 26, 2013

Perfect. Thanks 👍

@tbruyelle tbruyelle deleted the 674_WarningOnNullRootContext branch April 15, 2014 08:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants