Skip to content

Issue #171 - Fixing Some Lint Warnings #3171

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

Conversation

JasonSarwar
Copy link

@JasonSarwar JasonSarwar commented Oct 13, 2019

Description (required)

Fixes part of #171 Fix Lint errors/warnings

Fixing Some Android Lint and SonarLint Warnings in these packages:

  • fr.free.nrw.commons.bookmarks
  • fr.free.nrw.commons.bookmarks.locations
  • fr.free.nrw.commons.bookmarks.pictures
  • fr.free.nrw.commons.category

Some of the changes were:

  • Switching the try/catch/finally blocks for database querying into try-with-resources blocks, with the Cursor object getting set as the closable resource
  • Switching a lot of field types in the sqlite "Create Table Statements" from STRING to TEXT
  • Creating DAOException and throwing that instead of a generic RuntimeException in a few places (SonarLint: RSPEC-112)
  • Logging some Exceptions using Timber instead of e.printStackTrace() (SonarLint: RSPEC-1148)
  • Changing a few access modifiers to be more restrictive
  • Adding final to a few variables that are never changed
  • Adding a private constructor to some utility or static inner classes (SonarLint: RSPEC-1118)
  • Made some constant String variables for recurring Strings (SonarLint: RSPEC-1192)
  • Changing the switch cases with only one case into if/else statements (SonarLint: RSPEC-1301)
  • Adding some @NonNull and @Nullable annotations to methods that inherit methods that use those annotations
  • Replacing some junit.framework package imports in some Kotlin test classes with org.junit because the former is deprecated

Tests performed (required)
Ran the Gradle Tests and Tested ProdDebug on the Nexus 6 Emulator with API level 22.


Please let me know if there's anything I should change back or if there's anything I should elaborate on!

Copy link

@tests-checker tests-checker bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add tests to make sure this change works as expected?

@@ -122,7 +123,7 @@ boolean cacheContainsKey(String term) {
Observable<CategoryItem> categoryItemObservable = gpsCategories()
.concatWith(titleCategories(imageTitleList));
if (hasDirectCategories()) {
categoryItemObservable.concatWith(directCategories().concatWith(recentCategories()));
categoryItemObservable = categoryItemObservable.concatWith(directCategories().concatWith(recentCategories()));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one's a bit of logic change. Just wanted to point this one out.

@JasonSarwar JasonSarwar force-pushed the issue-171/fixing_some_lint_warnings branch from 233a48d to 6acd285 Compare October 26, 2019 20:19
@JasonSarwar
Copy link
Author

Fixing conflicts now.

Fixing Some Android Lint and SonarLint Warnings in these packages:
* `fr.free.nrw.commons.bookmarks`
* `fr.free.nrw.commons.bookmarks.locations`
* `fr.free.nrw.commons.bookmarks.pictures`

Some of the fixes were:
* Switching the try/catch/finally blocks for database querying into try-with-resources blocks, with the Cursor object getting set as the closable resource
* Switching a lot of field types in sqlite "Create Table Statements" from STRING to TEXT
* Creating a DAOException and throwing that instead of a generic RuntimeException in a few places
* Logging some Exceptions using Timber instead of `e.printStackTrace()`
* A few access modifier changes to be more restrictive
* Adding a private constructor to some static inner classes
Fixing Some Android Lint and SonarLint Warnings in this package:
* `fr.free.nrw.commons.category`

Some of the fixes were:
* Switching the try/catch/finally blocks for database querying in `CategoryDao` into try-with-resources blocks, with the Cursor object getting set as the closable resource
* Switching one field type in the sqlite "Create Table Statement" in CategoryDao from STRING to TEXT
* Throwing the new DAOException instead of a generic RuntimeException in CategoryDao
* Logging some Exceptions using Timber instead of `e.printStackTrace()`
* A few access modifier changes to be more restrictive
* Adding a private constructor to some static classes
* Made some constant String variables for recurring Strings
* Changed the switch cases with only one case into if/else statements
* Added some @nonnull and @nullable annotations to methods that inherit methods that use those annotations
…lin Test Files

`junit.framework` is deprecated. Replacing it with `org.junit` in 4 Kotlin Test files.
@JasonSarwar JasonSarwar force-pushed the issue-171/fixing_some_lint_warnings branch from 6acd285 to e4d0d88 Compare November 24, 2019 16:10
@codecov-io
Copy link

Codecov Report

Merging #3171 into master will increase coverage by 0.01%.
The diff coverage is 1.09%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #3171      +/-   ##
=========================================
+ Coverage    6.22%   6.23%   +0.01%     
=========================================
  Files         264     265       +1     
  Lines       11212   11189      -23     
  Branches      852     846       -6     
=========================================
  Hits          698     698              
+ Misses      10457   10434      -23     
  Partials       57      57
Impacted Files Coverage Δ
...e/nrw/commons/bookmarks/BookmarksPagerAdapter.java 0% <ø> (ø) ⬆️
...n/java/fr/free/nrw/commons/bookmarks/Bookmark.java 40% <ø> (ø) ⬆️
...va/fr/free/nrw/commons/category/QueryContinue.java 0% <ø> (ø) ⬆️
.../nrw/commons/category/SubCategoryListFragment.java 0% <ø> (ø) ⬆️
.../free/nrw/commons/bookmarks/BookmarksActivity.java 0% <ø> (ø) ⬆️
...a/fr/free/nrw/commons/bookmarks/BookmarkPages.java 0% <ø> (ø) ⬆️
.../nrw/commons/category/CategoryDetailsActivity.java 0% <0%> (ø) ⬆️
...java/fr/free/nrw/commons/category/CategoryDao.java 0% <0%> (ø) ⬆️
...w/commons/category/CategoryImagesListFragment.java 0% <0%> (ø) ⬆️
.../fr/free/nrw/commons/category/CategoriesModel.java 0% <0%> (ø) ⬆️
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b15a32...e4d0d88. Read the comment docs.

Copy link
Member

@domdomegg domdomegg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, although the merge conflicts are gonna be painful :(

@madhurgupta10
Copy link
Collaborator

@JasonSarwar Let us know if you are still working on it!

@madhurgupta10
Copy link
Collaborator

I am closing the PR for now as it seems like the author isn't working on it anymore, feel free to reopen if needed :)

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

Successfully merging this pull request may close these issues.

4 participants