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

Null cannot be cast to Non-null type of KClass in Module.verify #2070

Open
Nek-12 opened this issue Dec 9, 2024 · 4 comments
Open

Null cannot be cast to Non-null type of KClass in Module.verify #2070

Nek-12 opened this issue Dec 9, 2024 · 4 comments
Labels
core dsl status:checking currently in analysis - discussion or need more detailed specs test
Milestone

Comments

@Nek-12
Copy link

Nek-12 commented Dec 9, 2024

Describe the bug

Graph verification crashes when dependency params contain a lambda.

Koin module and version:
[e.g]: 4.1.0-Beta1

Snippet or Sample project to help reproduce
Add a snippet or even a small sample project to hel reproduce your case.

null cannot be cast to non-null type kotlin.reflect.KClass<*>
java.lang.NullPointerException: null cannot be cast to non-null type kotlin.reflect.KClass<*>
	at org.koin.test.verify.Verification.verifyConstructor(Verification.kt:131)
	at org.koin.test.verify.Verification.verifyFactory(Verification.kt:70)
	at org.koin.test.verify.Verification.verify(Verification.kt:46)
	at org.koin.test.verify.Verify.verify(VerifyModule.kt:81)
	at org.koin.test.verify.VerifyModuleKt.verify(VerifyModule.kt:30)
          <>

Dependency being verified:

// library class, no access to it
actual class LocalGameDataProvider(
    private val getGameData: suspend (GameId.Local) -> LocalGameData,
) {

    internal actual suspend fun awaitGameData(id: GameId.Local) = getGameData(id)
}

Injected through a builder function:

fun LocalGameDataProvider(
    detailsRepo: GameDataRepository, // project classes
    metadataRepository: VideoMetadataRepository,
) = LocalGameDataProvider { id ->
    // impl
}

val module = module {
    singleOf(::LocalGameDataProvider)
}
@arnaudgiuliani arnaudgiuliani added this to the 4.1.0 milestone Dec 12, 2024
@arnaudgiuliani
Copy link
Member

This is a current limitation of this implementation. This is not ideal as we try to inspect class metainfo. Lambda is hard to catchup from that, we don't really know what's inside your function. Without any static code analysis, or compiler plugin it's hard to provide something complete on this tooling API. This is why previous proposals were trying to sandbox, it's making your testing part so complex that it becomes hard to maintain on the scale.

More on that, reflection on other targets than JVM is incomplete.

I will continue to catch back on this API, but it's clearly linked to the current DSL design. This is why I'm preparing ground for new proposals around this DSL.

@arnaudgiuliani arnaudgiuliani added core dsl status:checking currently in analysis - discussion or need more detailed specs labels Jan 15, 2025
@Nek-12
Copy link
Author

Nek-12 commented Jan 15, 2025

Got it, but is there a way to avoid the crash so that at least our test works? We can't drop the functional parameter as it's 3rd party code.

@arnaudgiuliani
Copy link
Member

Ok, need to check how we can work around to accommodate at best. It's about verifying parameter injection on a definition right?

@Nek-12
Copy link
Author

Nek-12 commented Jan 16, 2025

Yes, that's correct, while using module.verify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core dsl status:checking currently in analysis - discussion or need more detailed specs test
Projects
None yet
Development

No branches or pull requests

2 participants