Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Log a warning when a @RootContext field isn't populated#678

Merged
DayS merged 1 commit into
androidannotations:developandroidannotations/androidannotations:developfrom
tbruyelle:674_WarningOnNullRootContexttbruyelle/androidannotations:674_WarningOnNullRootContextCopy head branch name to clipboard
Jul 26, 2013
Merged

Log a warning when a @RootContext field isn't populated#678
DayS merged 1 commit into
androidannotations:developandroidannotations/androidannotations:developfrom
tbruyelle:674_WarningOnNullRootContexttbruyelle/androidannotations:674_WarningOnNullRootContextCopy head branch name to clipboard

Conversation

@tbruyelle

Copy link
Copy Markdown
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

DayS commented Jul 26, 2013

Copy link
Copy Markdown
Contributor

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.