question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Probably unwanted use of constant expression: Math.random().toInt().toString()

See original GitHub issue

In 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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
IndianaDschonescommented, Jun 13, 2020

@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.

0reactions
dsarkarcommented, Dec 30, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Math.random is deprecated · Issue #406 - GitHub
LostMekka mentioned this issue on Jun 13, 2020. Probably unwanted use of constant expression: Math.random().toInt().toString() #448.
Read more >
Lots of Ways to Use Math.random() in JavaScript - CSS-Tricks
Math.random() is an API in JavaScript. It is a function that gives you a random number. The number returned will be between 0...
Read more >
generate 4 digit random number using substring
Math.random() will generate a floating point number in the range [0, 1) (this is not a typo, it is standard mathematical notation to...
Read more >
V2566. MISRA. Constant expression evaluation should not ...
This diagnostic rule is based on the software development guidelines developed by MISRA (Motor Industry Software Reliability Association).
Read more >
Diagnostic messages - Dart
When code refers to a member of an object (for example, o.m() or o.m or ... lookupFunction has an isLeaf argument whose value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found