Skip to content

Conversation

@ezaquarii
Copy link
Contributor

@ezaquarii ezaquarii commented Jan 11, 2020

The class uses non-null lateinit variable that
is not initialized. The member should be of
nullable type.

Fixes nextcloud/android#5073
Fixes nextcloud/android#5102
Fixes nextcloud/android#5100
Fixes nextcloud/android#5142
Fixes nextcloud/android#5156

Signed-off-by: Chris Narkiewicz hello@ezaquarii.com

val useOcsApiRequestHeader: Boolean) {
lateinit var response: Response
private var response: Response? = null
var queryMap: Map<String, String> = HashMap()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tobiasKaminsky Is there a reason why those members are public?

Copy link
Member

Choose a reason for hiding this comment

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

No, I just forgot that the default visibility in Kotlin is different than in Java.

Copy link
Member

Choose a reason for hiding this comment

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

I wanted to avoid null, and thus I used lateinit, but seems to be wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is incorrect use. Keyword latetinit is a workaround for situations where you want to declare a non-nullable value, but it cannot be initialized immediately. Kotlin requires all variables to be initailized in a primary constructor (this eliminates whole class of bugs). When this is not possible (for example, when you can set it in onCreate(), you can annotate a variable lateinit. Kotlin will generate some code that checks if variable is initialized before first use and throw NPE if not, but the variable is still non-nullable.

This is not an alternative for java.util.Optional or nullable type.

private var response: Response? = null
var queryMap: Map<String, String> = HashMap()
var requestHeaders: MutableMap<String, String> = HashMap()
var requestBuilder: Request.Builder = Request.Builder()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

those could be val

Copy link
Member

Choose a reason for hiding this comment

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

ok :-)

@ezaquarii ezaquarii force-pushed the ezaquarii/make-response-member-in-okhttpmethodbase-nullable branch from 7e0a6c2 to ee19f90 Compare January 11, 2020 20:38
@ezaquarii ezaquarii self-assigned this Jan 11, 2020
@ezaquarii ezaquarii force-pushed the ezaquarii/make-response-member-in-okhttpmethodbase-nullable branch 2 times, most recently from e367d17 to e23bc5e Compare January 11, 2020 20:50
@codecov
Copy link

codecov bot commented Jan 11, 2020

Codecov Report

Merging #380 into master will decrease coverage by <.01%.
The diff coverage is 29.41%.

@@            Coverage Diff             @@
##           master     #380      +/-   ##
==========================================
- Coverage   34.32%   34.32%   -0.01%     
==========================================
  Files         133      133              
  Lines        5724     5727       +3     
  Branches      751      751              
==========================================
+ Hits         1965     1966       +1     
- Misses       3486     3487       +1     
- Partials      273      274       +1
Impacted Files Coverage Δ
.../main/java/com/nextcloud/common/NextcloudClient.kt 30.43% <0%> (ø) ⬆️
...urces/activities/GetActivitiesRemoteOperation.java 36.84% <100%> (ø) ⬆️
...main/java/com/nextcloud/common/OkHttpMethodBase.kt 53.12% <28.57%> (-2.05%) ⬇️

@tobiasKaminsky
Copy link
Member

Ready from my side :+1

@AndyScherzinger
Copy link
Member

@tobiasKaminsky feel free to merge (from my pov)

The class uses non-null lateinit variable that
is not initialized. The member should be of
nullable type.

Fixes nextcloud/android#5073
Fixes nextcloud/android#5102
Fixes nextcloud/android#5100
Fixes nextcloud/android#5142
Fixes nextcloud/android#5156

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
@ezaquarii ezaquarii force-pushed the ezaquarii/make-response-member-in-okhttpmethodbase-nullable branch from 6529b8b to 2ab8e7e Compare January 14, 2020 05:35
@ezaquarii
Copy link
Contributor Author

@tobiasKaminsky I squashed the branch, anticipating some tests updates, but I see no unit tests.
If this is all we shall do here, I'm done as well.

@nextcloud-android-bot
Copy link
Collaborator

Lint

TypemasterPR
Warnings00
Errors00

SpotBugs (new)

Warning TypeNumber
Bad practice Warnings14
Correctness Warnings39
Internationalization Warnings6
Malicious code vulnerability Warnings7
Multithreaded correctness Warnings3
Performance Warnings17
Security Warnings1
Dodgy code Warnings58
Total145

SpotBugs (master)

Warning TypeNumber
Bad practice Warnings14
Correctness Warnings39
Internationalization Warnings6
Malicious code vulnerability Warnings7
Multithreaded correctness Warnings3
Performance Warnings17
Security Warnings1
Dodgy code Warnings58
Total145

@tobiasKaminsky tobiasKaminsky merged commit cb8e616 into master Jan 14, 2020
@delete-merged-branch delete-merged-branch bot deleted the ezaquarii/make-response-member-in-okhttpmethodbase-nullable branch January 14, 2020 08:39
@tobiasKaminsky
Copy link
Member

/backport to stable-2.0

@backportbot-nextcloud
Copy link

backport to stable-2.0 in #381

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NPE in OkHttpMethodBase Crash when sharing directory on External storage App crashed when try to view details or open file Pdf viewer

5 participants