修复Rest部分情况下获取不到参数的BUG

This commit is contained in:
Redkale
2018-06-09 10:15:49 +08:00
parent a540eed0ed
commit 3c645b4c7f
2 changed files with 4 additions and 0 deletions

View File

@@ -401,6 +401,7 @@ public final class Rest {
Set<String> paramnames = new HashSet<>();
String methodesc = method.getName() + ":" + Type.getMethodDescriptor(method);
List<String> names = asmParamMap.get(methodesc);
if (names != null) while (names.remove(" ")); //删掉空元素
Parameter[] params = method.getParameters();
final LinkedHashMap<String, Parameter> paramap = new LinkedHashMap(); //必须使用LinkedHashMap确保顺序
for (int j = 0; j < params.length; j++) { //字段列表
@@ -891,6 +892,7 @@ public final class Rest {
int maxLocals = 4;
List<String> asmParamNames = asmParamMap == null ? null : asmParamMap.get(method.getName() + ":" + Type.getMethodDescriptor(method));
if (asmParamNames != null) while (asmParamNames.remove(" ")); //删掉空元素
List<Object[]> paramlist = new ArrayList<>();
//解析方法中的每个参数
for (int i = 0; i < params.length; i++) {
@@ -1723,6 +1725,7 @@ public final class Rest {
}
cw.visitEnd();
Class<?> newClazz = new RestClassLoader(loader).loadClass(newDynName.replace('/', '.'), cw.toByteArray());
try {
T obj = ((Class<T>) newClazz).getDeclaredConstructor().newInstance();

View File

@@ -140,6 +140,7 @@ public interface Creator<T> {
}
final List<String> fieldnames = new ArrayList<>();
new ClassReader(out.toByteArray()).accept(new SimpleClassVisitor(Opcodes.ASM6, fieldnames, constructorDesc), 0);
while (fieldnames.remove(" ")); //删掉空元素
if (fieldnames.isEmpty()) return null;
if (paramcount == fieldnames.size()) {
return getConstructorField(clazz, paramcount, fieldnames.toArray(new String[fieldnames.size()]));