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.
In Kafka,
AnyCodecrequires an explicit class loader to be provided, hence this trick:pew/pew/src/main/scala/com/workflowfm/pew/mongodb/bson/AnyCodec.scala
Lines 23 to 26 in 4a5bfae
See also:
This requires this switch using
setContextClassLoader:pew/pew/src/main/scala/com/workflowfm/pew/util/ClassLoaderUtil.scala
Lines 14 to 20 in 4a5bfae
This fails in pew-mongo because everything runs on the default
ForkJoinPoolwhich producesInnocuousThreads which do not allow you tosetContextClassLoaderleading to a security exception.We want an easy way to bypass this loader switch, perhaps as simpke as a flag in
AnyCodecand the codec provider.Perhaps later on after #55 is implemented we will have a more elegant solution available.