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

[Hilt] Incorrect signature attribute? #3094

Closed
mrjameshamilton opened this issue Dec 6, 2021 · 0 comments
Closed

[Hilt] Incorrect signature attribute? #3094

mrjameshamilton opened this issue Dec 6, 2021 · 0 comments

Comments

@mrjameshamilton
Copy link

Given an Application class with a generic superclass, Hilt inserts the Hilt_ application class into the hierarchy but the signature attribute annotation is not updated with the new superclass. Is this intended behaviour or a bug?

Example:

open class BaseApplication<T> : Application()

@HiltAndroidApp
class MyApplication : BaseApplication<String>() {
    override fun onCreate() {
        super.onCreate()

        println(this.javaClass.superclass)
        println(this.javaClass.genericSuperclass)
        println(this.javaClass.genericSuperclass.typeName)
    }
}

Without Hilt:

.class public final Lcom/example/hiltexample/MyApplication;
.super Lcom/example/hiltexample/BaseApplication;

# annotations
.annotation system Ldalvik/annotation/Signature;
    value = {
        "Lcom/example/hiltexample/BaseApplication<",
        "Ljava/lang/String;",
        ">;"
    }
.end annotation

class com.example.hiltexample.BaseApplication
com.example.hiltexample.BaseApplication<java.lang.String>
com.example.hiltexample.BaseApplication<java.lang.String>

With Hilt the superclass in the signature attribute doesn't change and therefore doesn't match the actual superclass anymore:

.class public final Lcom/example/hiltexample/MyApplication;
.super Lcom/example/hiltexample/Hilt_MyApplication;

# annotations
.annotation system Ldalvik/annotation/Signature;
    value = {
        "Lcom/example/hiltexample/BaseApplication<",
        "Ljava/lang/String;",
        ">;"
    }
.end annotation

class com.example.hiltexample.Hilt_MyApplication
com.example.hiltexample.BaseApplication<java.lang.String>
com.example.hiltexample.BaseApplication<java.lang.String>
@mrjameshamilton mrjameshamilton changed the title Incorrect signature attribute? [Hilt] Incorrect signature attribute? Dec 6, 2021
@danysantiago danysantiago self-assigned this Dec 6, 2021
copybara-service bot pushed a commit that referenced this issue Dec 6, 2021
…s parameterized types.

When an Android entry point has a superclass that uses parameterized types then the Class file will contain a Signature attribute that also has to be updated since the super_class is changed via Hilt's transform. The attribute is not checked by the JVM during linking, which is why it had not caused any issues before, but it does affected certain reflective APIs. See: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.9

Fixes: #3094
RELNOTES=Fix an issue where Hilt transform was not correctly updating the Signature attribute of an @androidentrypoint whose superclass contained a type variable.
PiperOrigin-RevId: 414441547
copybara-service bot pushed a commit that referenced this issue Jan 5, 2022
…s parameterized types.

When an Android entry point has a superclass that uses parameterized types then the Class file will contain a Signature attribute that also has to be updated since the super_class is changed via Hilt's transform. The attribute is not checked by the JVM during linking, which is why it had not caused any issues before, but it does affected certain reflective APIs. See: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.9

Fixes: #3094
RELNOTES=Fix an issue where Hilt transform was not correctly updating the Signature attribute of an @androidentrypoint whose superclass contained a type variable.
PiperOrigin-RevId: 414441547
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants