mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-23 16:48:07 +02:00
java: fixed a bug that javassist cannot find class files that were loaded by custom class loader
This commit is contained in:
@@ -46,21 +46,29 @@ import org.msgpack.template.NullableTemplate;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
class DynamicCodeGen extends DynamicCodeGenBase implements Constants {
|
public class DynamicCodeGen extends DynamicCodeGenBase implements Constants {
|
||||||
|
|
||||||
private static Logger LOG = LoggerFactory.getLogger(DynamicCodeGen.class);
|
private static Logger LOG = LoggerFactory.getLogger(DynamicCodeGen.class);
|
||||||
|
|
||||||
private static DynamicCodeGen INSTANCE;
|
private static DynamicCodeGen INSTANCE;
|
||||||
|
|
||||||
public static DynamicCodeGen getInstance() {
|
public static DynamicCodeGen getInstance() {
|
||||||
|
return getInstance(null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DynamicCodeGen getInstance(ClassLoader cl) {
|
||||||
if (INSTANCE == null) {
|
if (INSTANCE == null) {
|
||||||
LOG.info("create an instance of the type: "
|
LOG.info("create an instance of the type: "
|
||||||
+ DynamicCodeGen.class.getName());
|
+ DynamicCodeGen.class.getName());
|
||||||
INSTANCE = new DynamicCodeGen();
|
INSTANCE = new DynamicCodeGen();
|
||||||
|
if (cl != null) {
|
||||||
|
INSTANCE.setClassLoader(cl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConcurrentHashMap<String, Template[]> tmplCache;
|
private ConcurrentHashMap<String, Template[]> tmplCache;
|
||||||
|
|
||||||
DynamicCodeGen() {
|
DynamicCodeGen() {
|
||||||
|
@@ -38,6 +38,7 @@ import javassist.CtField;
|
|||||||
import javassist.CtMethod;
|
import javassist.CtMethod;
|
||||||
import javassist.CtNewConstructor;
|
import javassist.CtNewConstructor;
|
||||||
import javassist.CtNewMethod;
|
import javassist.CtNewMethod;
|
||||||
|
import javassist.LoaderClassPath;
|
||||||
import javassist.NotFoundException;
|
import javassist.NotFoundException;
|
||||||
|
|
||||||
import org.msgpack.CustomConverter;
|
import org.msgpack.CustomConverter;
|
||||||
@@ -151,6 +152,10 @@ public class DynamicCodeGenBase implements Constants {
|
|||||||
pool = ClassPool.getDefault();
|
pool = ClassPool.getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setClassLoader(ClassLoader cl) {
|
||||||
|
pool.appendClassPath(new LoaderClassPath(cl));
|
||||||
|
}
|
||||||
|
|
||||||
protected void checkTypeValidation(Class<?> type) {
|
protected void checkTypeValidation(Class<?> type) {
|
||||||
DynamicCodeGenException e = new DynamicCodeGenException(String.format(
|
DynamicCodeGenException e = new DynamicCodeGenException(String.format(
|
||||||
"Fatal error: %s", new Object[] { type.getName() }));
|
"Fatal error: %s", new Object[] { type.getName() }));
|
||||||
|
Reference in New Issue
Block a user