Skip to content
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

Fix/simplify lazy initialization #108

Merged
merged 2 commits into from
Oct 5, 2023

Conversation

Sergey-Makarov
Copy link
Contributor

Simplified safe lazy initialization. All factory code is now run lazily instead of only some of it's parts.
With this change, the return type of getFingerprintingSignalsProvider() inevitably became nullable.

/**
* @return [FingerprintingSignalsProvider] which is useful in conjunction with the getFingerprint(signals, hasher) method.
* @return [FingerprintingSignalsProvider] which is useful in conjunction with the getFingerprint(signals, hasher) method, or null

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style. Warning

Line detected that is longer than the defined maximum line length in the code style.
@@ -0,0 +1,10 @@
package com.fingerprintjs.android.fingerprint.tools

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning

The file /home/runner/work/fingerprintjs-android/fingerprintjs-android/fingerprint/src/main/java/com/fingerprintjs/android/fingerprint/tools/ExceptionSafeExecutor.kt is not ending with a new line.

@Test
fun flattenOuterErrorReturned() {
val res = runCatching { runCatching { 0 }.also { throw Exception() } }.flatten()

Check warning

Code scanning / detekt

Thrown exception is too generic. Prefer throwing project specific exceptions to handle error cases. Warning test

Exception is a too generic Exception. Prefer throwing specific exceptions that indicate a specific error case.

@Test
fun flattenInnerErrorReturned() {
val res = runCatching { runCatching { 0.also { throw Exception() } } }.flatten()

Check warning

Code scanning / detekt

Thrown exception is too generic. Prefer throwing project specific exceptions to handle error cases. Warning test

Exception is a too generic Exception. Prefer throwing specific exceptions that indicate a specific error case.
@@ -0,0 +1,29 @@
package com.fingerprintjs.android.fingerprint

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning test

The file /home/runner/work/fingerprintjs-android/fingerprintjs-android/fingerprint/src/test/java/com/fingerprintjs/android/fingerprint/ResultExtensionsTests.kt is not ending with a new line.
// defaults from Executors.newCachedThreadPool()
ThreadPoolExecutor(
0, Integer.MAX_VALUE,
60L, TimeUnit.SECONDS,

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
activityManager = safeLazy { context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager },
internalStorageStats = safeLazy { StatFs(Environment.getRootDirectory()!!.absolutePath!!) },
externalStorageStats = safeLazy {
activityManager = safe { context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager }.getOrNull(),

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style. Warning

Line detected that is longer than the defined maximum line length in the code style.
@@ -107,7 +105,7 @@ class SafeTests {
val errLvl1: Throwable?
var errLvl2: Throwable? = null
var errLvl3: Throwable? = null
val countDownLatch = CountDownLatch(1)
val countDownLatch = CountDownLatch(2)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not related to other changes. This is just to avoid a race condition

@Sergey-Makarov Sergey-Makarov merged commit afc30d4 into main Oct 5, 2023
3 checks passed
@Sergey-Makarov Sergey-Makarov deleted the fix/simplify-lazy-initialization branch April 23, 2024 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants