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

Android Lint error #103

Open
edwardhuerta opened this issue Dec 4, 2016 · 3 comments
Open

Android Lint error #103

edwardhuerta opened this issue Dec 4, 2016 · 3 comments
Assignees

Comments

@edwardhuerta
Copy link

I generated a simple content provider and I get this when i run Android Lint on the newly generated classes:

Do not place Android context classes in static fields (static reference to MyDataStoreProviderSQLiteOpenHelper which has field mContext pointing to Context); this is a memory leak (and also breaks Instant Run)

This is located in the generated ...SQLiteOpenHelper extends SQLiteOpenHelper class.

@BoD
Copy link
Owner

BoD commented Dec 5, 2016

This warning can safely be ignored.
You can add @SuppressLint("StaticFieldLeak") manually for now, and I will add it to the generated code in the next version.

@BoD BoD added the enhancement label Dec 5, 2016
@BoD BoD self-assigned this Dec 5, 2016
@edwardhuerta
Copy link
Author

edwardhuerta commented Dec 5, 2016 via email

@BoD
Copy link
Owner

BoD commented Dec 5, 2016

If lint says it's a problem, then I would think that it cannot be ignored.

Sorry, you are wrong about this. The problems reported by lint have different severities (errors, warnings, info, etc.). This one is a warning.
Moreover, static code analyzers are not bullet proof, sometimes they are overzealous - at times they are even plain wrong. A developer should always think and make sure that the reported problem really is one, and not blindly try to "fix" it. That's why they have a mechanism to ignore reported problems (@SuppressLint).

Can you elaborate on why it is safe to ignore that error?

In this particular case, the generated code already has something to say about this (look at the comment inside getInstance).
As you can see, we only keep a reference to the Application Context. Which is a singleton.

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

No branches or pull requests

2 participants