Probably unwanted use of constant expression: Math.random().toInt().toString()
See original GitHub issueIn the closed issue #406 we saw a reference to a weird line of code regarding a HTTP header cwa-fake
:
https://github.com/corona-warn-app/cwa-app-android/blob/970e8b859cff3c8beeca83ac83e9ed534927107a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/http/WebRequestBuilder.kt#L182-L183
The expression Math.random().toInt().toString()
will always evaluate to "0"
, since 0 <= Math.random() < 1
and Double.toInt()
simply cuts off the fractional part. So this piece of code is quite redundant.
I do not fully understand the purpose of the cwa-fake
header, but it seems to me that the code for it was meant to fill it with a random value, when the faked
flag is true
. But as it is, it will always be set to "0"
, regardless of the value of faked
. This might be an oversight of some kind, so I want to bring this to your attention explicitly with this issue.
And since this is a “question” type issue, here is my question:
Is it safe to always set the header to "0"
, or is this something that needs to be fixed?
Additional information
The initial commit of this repository had 4 instances of the expression: https://github.com/corona-warn-app/cwa-app-android/blob/4804888ad0d3ee4c4abfb85294bab3006b75c250/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/http/request/KeySubmissionRequest.kt#L45-L46 https://github.com/corona-warn-app/cwa-app-android/blob/4804888ad0d3ee4c4abfb85294bab3006b75c250/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/http/request/RegistrationTokenRequest.kt#L60-L61 https://github.com/corona-warn-app/cwa-app-android/blob/4804888ad0d3ee4c4abfb85294bab3006b75c250/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/http/request/TanRequest.kt#L50-L51 https://github.com/corona-warn-app/cwa-app-android/blob/4804888ad0d3ee4c4abfb85294bab3006b75c250/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/http/request/TestResultRequest.kt#L50-L51 Then in commit b195623 the usages were unified into the current code snippet referenced above. If this really is an issue, it existed before this repository was created.
Internal Tracking ID: EXPOSUREAPP-1966
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
@LostMekka i think corona-warn-app/cwa-documentation/issues/225 on the documentation repo is relevant here. This feature will be implemented in
Version 1.1
as stated in the comments.Hi @LostMekka, this issue will be closed now, see https://github.com/corona-warn-app/cwa-app-android/pull/463, https://github.com/corona-warn-app/cwa-app-android/pull/463#issuecomment-694315254 Many thanks for your contributions.
Best wishes, DS
Corona-Warn-App Open Source Team