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.

invokeSuspend throws NullPointer while minifyEnabled is true

See original GitHub issue

Hello, 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tRuNKatorcommented, Jan 17, 2019

@tRuNKator , R8 team fixed the issue, but how can I use the version with this fix? We need to wait for next gradle tools version and it will include R8 version with the fix? Or there is other way to set it manually? Thanks.

You can apply new version manually. But I don’t know if this fix entered this version.

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url "http://storage.googleapis.com/r8-releases/raw/" }
    }

    dependencies {
        classpath 'com.android.tools:r8:1.4.25'  // Must be before the Gradle Plugin for Android.
        classpath "com.android.tools.build:gradle:androidGradlePluginVersion"
    }
}
0reactions
elizarovcommented, Oct 16, 2019

You can work around by turning off minification or tweaking minification settings. I’m not sure there’s anything more we can help with.

Read more comments on GitHub >

github_iconTop 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 >

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