Skip to content

Commit 5fe1ad8

Browse files
Fix java.lang.NullPointerException for username in ContributionBoundaryCallback (commons-app#5003)
1 parent d8e4c03 commit 5fe1ad8

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

app/src/main/java/fr/free/nrw/commons/contributions/ContributionBoundaryCallback.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ContributionBoundaryCallback @Inject constructor(
2121
@param:Named(CommonsApplicationModule.IO_THREAD) private val ioThreadScheduler: Scheduler
2222
) : BoundaryCallback<Contribution>() {
2323
private val compositeDisposable: CompositeDisposable = CompositeDisposable()
24-
lateinit var userName: String
24+
var userName: String? = null
2525

2626

2727
/**
@@ -53,13 +53,13 @@ class ContributionBoundaryCallback @Inject constructor(
5353
/**
5454
* Fetches contributions using the MediaWiki API
5555
*/
56-
fun fetchContributions() {
56+
private fun fetchContributions() {
5757
if (sessionManager.userName != null) {
58-
compositeDisposable.add(
59-
mediaClient.getMediaListForUser(userName!!)
58+
userName?.let { userName ->
59+
mediaClient.getMediaListForUser(userName)
6060
.map { mediaList ->
61-
mediaList.map {
62-
Contribution(media = it, state = Contribution.STATE_COMPLETED)
61+
mediaList.map { media ->
62+
Contribution(media = media, state = Contribution.STATE_COMPLETED)
6363
}
6464
}
6565
.subscribeOn(ioThreadScheduler)
@@ -69,11 +69,13 @@ class ContributionBoundaryCallback @Inject constructor(
6969
error.message
7070
)
7171
}
72-
)
73-
}else {
74-
if (compositeDisposable != null){
75-
compositeDisposable.clear()
72+
}?.let {
73+
compositeDisposable.add(
74+
it
75+
)
7676
}
77+
}else {
78+
compositeDisposable.clear()
7779
}
7880
}
7981

0 commit comments

Comments
 (0)