Exposed icon indicating copy to clipboard operation
Exposed copied to clipboard

Exposed Proguard Problem

Open goksunonal opened this issue 3 years ago • 9 comments

Hi, I am using IntEntityClass and EntityId in my database class and getting this error while using proguard.

Caused by: java.lang.NullPointerException: null
	at org.jetbrains.exposed.dao.EntityClass.<init>(EntityClass.kt:18)
	at org.jetbrains.exposed.dao.IntEntityClass.<init>(IntEntity.kt:8)
	at org.jetbrains.exposed.dao.IntEntityClass.<init>(IntEntity.kt:8)
	at myPath.MyClass$Companion.<init>(SourceFile:50)
	at myPath.MyClass$Companion.<init>(SourceFile)
	at myPath.MyClass.<clinit>(SourceFile:52)

Tried these rules too but didn't seem to solve:

-keepclassmembers class myPath.MyClass{
    public static ** Companion;
}

-keep class myPath.MyClass$Companion { *; }
-keep class org.jetbrains.** { *; }
-keep interface org.jetbrains.** { *; }
-keep enum org.jetbrains.** { *; }

class context ->

internal object MyClasses: IntIdTable(Constant.MyCLASS) {
    val name = varchar("name", length = 50).uniqueIndex()
}

class MyClass(id: EntityID<Int>) : IntEntity(id) {
    companion object : IntEntityClass<MyClass>(MyClasses)

    var name by MyClasses.name
}

I am not sure if problem is totally related to 'Exposed' but i would like to hear your opinions.

goksunonal avatar Nov 03 '21 06:11 goksunonal

Did you tried to remove internal on MyClasses?

stengvac avatar Nov 03 '21 13:11 stengvac

No proguard rules are needed. Just pass your DAO class to your EntityClass's constructor:

class MyClass(id: EntityID<Int>) : IntEntity(id) {
    companion object : IntEntityClass<MyClass>(MyClasses, MyClass::class.java)

    var name by MyClasses.name
}

RationalityFrontline avatar Nov 04 '21 06:11 RationalityFrontline

Tried both ways, didn't work. I am suspecting usage of companion object.

goksunonal avatar Nov 04 '21 06:11 goksunonal

@goksunonal It's wired, my solution should work. The NullPointerException was thrown from here: image So passing in the entityType should solve the problem.

RationalityFrontline avatar Nov 04 '21 06:11 RationalityFrontline

@RationalityFrontline 'Null Pointer' problem is happening less often after your recommendation. There is another problem which starting to happen more which may give us more idea:

java.lang.NoClassDefFoundError: Could not initialize class myPath.MyClass
	at myPath.MyClass.I.a(SourceFile:82)
	at myPath.MyClass.I.invoke(SourceFile:81)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt$transaction$1.invoke(ThreadLocalTransactionManager.kt:131)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.keepAndRestoreTransactionRefAfterRun(ThreadLocalTransactionManager.kt:202)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:123)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:121)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction$default(ThreadLocalTransactionManager.kt:120)
	at myPath.MyClass.F.a(SourceFile:81)
	at myPath.MyClass.F.a(SourceFile:62)
	at myPath.MyClass.H.a(SourceFile:97)
	at myPath.MyClass.H.invoke(SourceFile:95)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt$inTopLevelTransaction$1.invoke(ThreadLocalTransactionManager.kt:173)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt$inTopLevelTransaction$2.invoke(ThreadLocalTransactionManager.kt:194)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.keepAndRestoreTransactionRefAfterRun(ThreadLocalTransactionManager.kt:202)

Related function:

    private fun findBySystemName(id: Int): String {
        return transaction {
            MyClass.findById(id).toString()
        }
    }

image

goksunonal avatar Nov 04 '21 07:11 goksunonal

Did you relocate packages with Proguard?

Tapac avatar Nov 14 '21 15:11 Tapac

Yep,

problem is definitely with companion object : IntEntityClass<MyClass>(MyClasses) that part. No error occurs when i remove it.

goksunonal avatar Nov 18 '21 11:11 goksunonal

Hi @goksunonal. Are you still getting this error?

joc-a avatar May 24 '23 13:05 joc-a

It's been a long time since I looked, the last time I worked on it, I did find a workaround and got rid of the companion object usage. I am no longer working on the project but the error was still there when I last tried it in mid 2022.

goksunonal avatar May 24 '23 14:05 goksunonal