Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Unable to switch ClassLoader if default ClassLoader is insufficient #27

Copy link
Copy link
Open
@ckosmowski

Description

@ckosmowski
Issue body actions

I am trying to use Kotlin Scripting inside a Quarkus Application. However the Quarkus RuntimeClassloader seems to be insufficient to load the classes into the Scripting Engine. That is basically because it only loads classes that has been indexed at startup time.

I also filed a ticket with quarkus:

quarkusio/quarkus#43271 (comment)

And i created a minimal reproducer for the problem:

https://github.com/ckosmowski/kotlin-script-reproducer

1.) Start the Main class directly -> The script works. It outputs "Hello World!" and "A Model From Outside"
2.) run quarkus dev -> The output will be "Hello World" and a longish output with the message " ERROR Unresolved reference 'printName'. " at its end.

Something to add, there is a way that you can usually replace the used classloader like this:

val result = host.eval(StringScriptSource("""
            printName()
        """.trimIndent()), ScriptWithMavenDepsConfiguration, ScriptEvaluationConfiguration {
            implicitReceivers(modelFromOutside)
            jvm {
                baseClassLoader(FilteringClassLoader(Thread.currentThread().contextClassLoader, listOf("org.example", "java.lang")))
            }
        })

FilterClassLoader:

class FilteringClassLoader(
        parent: ClassLoader,
        val allowedPackages: List<String>
    ) : ClassLoader(parent) {

        override fun loadClass(name: String, resolve: Boolean): Class<*> {
            if (allowedPackages.any { name.startsWith(it) }) {
                return super.loadClass(name, resolve)
            }
            throw ClassNotFoundException("Class $name is not allowed")
        }
    }

I hoped that this does the trick but however this works in the plain java version but not with quarkus dev.
Is there a way that you kotlin people could assist here, or work together with quarkus?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.