-
Notifications
You must be signed in to change notification settings - Fork 95
Make response member in OkHttpMethodBase nullable #380
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
Make response member in OkHttpMethodBase nullable #380
Conversation
| val useOcsApiRequestHeader: Boolean) { | ||
| lateinit var response: Response | ||
| private var response: Response? = null | ||
| var queryMap: Map<String, String> = HashMap() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those could be val
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok :-)
7e0a6c2 to
ee19f90
Compare
e367d17 to
e23bc5e
Compare
Codecov Report
@@ 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
|
src/main/java/com/owncloud/android/lib/resources/activities/GetActivitiesRemoteOperation.java
Show resolved
Hide resolved
|
Ready from my side :+1 |
|
@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>
6529b8b to
2ab8e7e
Compare
|
@tobiasKaminsky I squashed the branch, anticipating some tests updates, but I see no unit tests. |
Lint
SpotBugs (new)
SpotBugs (master)
|
|
/backport to stable-2.0 |
|
backport to stable-2.0 in #381 |
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