invokeSuspend throws NullPointer while minifyEnabled is true
See original GitHub issueHello, I used version 1.0.1, but found a problem when exceptions were not processed if the coroutine was canceled (same issue(fixed in new version)). Now I have updated the version to 1.1.0-alpha. And again I ran into another problem. Such code: MainActivity.kt
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
GlobalScope.launch {
val result = safeApiCall { doDelay() }
println(result)
}
}
suspend fun doDelay(): Boolean {
delay(2000)
return true
}
}
Utils.kt:
suspend fun safeApiCall(call: suspend () -> Boolean): Boolean {
return try {
call()
} catch (throwable: Throwable) {
false
}
}
Generates such code for Utils.kt (see on last line):
.method public final invokeSuspend(Ljava/lang/Object;)Ljava/lang/Object;
.registers 3
.param p1 # Ljava/lang/Object;
.annotation build Lorg/jetbrains/annotations/NotNull;
.end annotation
.end param
.annotation build Lorg/jetbrains/annotations/Nullable;
.end annotation
iput-object p1, p0, Lcom/example/myapplication/UtilsKt$safeApiCall$1;->result:Ljava/lang/Object;
iget p1, p0, Lcom/example/myapplication/UtilsKt$safeApiCall$1;->label:I
const/high16 v0, -0x80000000
or-int/2addr p1, v0
iput p1, p0, Lcom/example/myapplication/UtilsKt$safeApiCall$1;->label:I
const/4 p1, 0x0
throw p1
.end method
Even with this rules:
-dontobfuscate
-dontoptimize
-dontnote
-dontobfuscate
-dontoptimize
-dontpreverify
-dontshrink
AS 3.4 Canary 9, android gradle plugin ver 3.4.0-alpha09, kotlin version 1.3.11
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
invokeSuspend throws NullPointer while minifyEnabled is true ...
I got this when I was using the Retrofit suspend functions in my Android Compose app (I use Retrofit + Pagin 3 library)....
Read more >ProGuard leads to NullPointerException - Stack Overflow
When setting minifyEnabled true in my gradle I get a NullPointerException when starting my app: java.lang.RuntimeException: Unable to start activity ...
Read more >How to avoid null pointer exception in Java - Javatpoint
1. The method is invoked using a null object. Java program throws a NullPointerException if we invoke some method on the null object....
Read more >“NetworkOnMainThreadException” in the android Kollin app ...
My problem is when i run my app in my mobile phone, a "NetworkOnMainThreadException" sets off.I tried for several times to correct this ......
Read more >square - Bountysource
Provide a way, such that while uploading or downloading any media( files, images, ... I'm getting following error when running with minifyEnabled true:...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can apply new version manually. But I don’t know if this fix entered this version.
You can work around by turning off minification or tweaking minification settings. I’m not sure there’s anything more we can help with.