Skip to content

Switching class loader in AnyCodec does not work for Mongo #65

@PetrosPapapa

Description

@PetrosPapapa

In Kafka, AnyCodec requires an explicit class loader to be provided, hence this trick:

// Jev, unset the `ClassLoader` to ensure the default is used.
def classForName(name: String): Class[_] = ClassLoaderUtil.withClassLoader(null) {
Class.forName(name)
}

See also:

This requires this switch using setContextClassLoader:

val pushedClassLoader = Thread.currentThread().getContextClassLoader
try {
Thread.currentThread().setContextClassLoader(tmpClassLoader)
fnWrapped
} finally {
Thread.currentThread().setContextClassLoader(pushedClassLoader)
}

This fails in pew-mongo because everything runs on the default ForkJoinPool which produces InnocuousThreads which do not allow you to setContextClassLoader leading to a security exception.

We want an easy way to bypass this loader switch, perhaps as simpke as a flag in AnyCodec and the codec provider.

Perhaps later on after #55 is implemented we will have a more elegant solution available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions