Exposed
Exposed copied to clipboard
Exposed Proguard Problem
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.
Did you tried to remove internal
on MyClasses?
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
}
Tried both ways, didn't work. I am suspecting usage of companion object.
@goksunonal It's wired, my solution should work. The NullPointerException was thrown from here:
So passing in the
entityType
should solve the problem.
@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()
}
}
Did you relocate packages with Proguard?
Yep,
problem is definitely with
companion object : IntEntityClass<MyClass>(MyClasses)
that part. No error occurs when i remove it.
Hi @goksunonal. Are you still getting this error?
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.