fix out of index exception when mocking native method

This commit is contained in:
金戟 2021-02-06 10:44:51 +08:00
parent adfba4bac0
commit 126c7257d8
2 changed files with 6 additions and 6 deletions

View File

@ -60,6 +60,10 @@ public class SourceClassHandler extends BaseClassHandler {
Set<MethodInfo> newOperatorInjectMethods) { Set<MethodInfo> newOperatorInjectMethods) {
LogUtil.diagnose(" Handling method %s", mn.name); LogUtil.diagnose(" Handling method %s", mn.name);
AbstractInsnNode[] instructions = mn.instructions.toArray(); AbstractInsnNode[] instructions = mn.instructions.toArray();
if (instructions.length == 0) {
// native method (issue-52)
return;
}
int i = 0; int i = 0;
int maxStackDiff = 0; int maxStackDiff = 0;
do { do {

View File

@ -61,17 +61,17 @@ public class TestableClassTransformer implements ClassFileTransformer {
LogUtil.diagnose("Handling source class %s", className); LogUtil.diagnose("Handling source class %s", className);
bytes = new SourceClassHandler(injectMethods).getBytes(classFileBuffer); bytes = new SourceClassHandler(injectMethods).getBytes(classFileBuffer);
dumpByte(className, bytes); dumpByte(className, bytes);
resetMockContext();
} else if (shouldTransformAsTestClass(className)) { } else if (shouldTransformAsTestClass(className)) {
// it's a test class with testable enabled // it's a test class with testable enabled
LogUtil.diagnose("Handling test class %s", className); LogUtil.diagnose("Handling test class %s", className);
bytes = new TestClassHandler().getBytes(classFileBuffer); bytes = new TestClassHandler().getBytes(classFileBuffer);
dumpByte(className, bytes); dumpByte(className, bytes);
resetMockContext();
} }
} catch (Throwable t) { } catch (Throwable t) {
LogUtil.warn("Failed to transform class " + className); LogUtil.warn("Failed to transform class " + className);
LogUtil.diagnose(t.toString()); LogUtil.diagnose(t.toString());
} finally {
LogUtil.resetLogLevel();
} }
return bytes; return bytes;
} }
@ -226,10 +226,6 @@ public class TestableClassTransformer implements ClassFileTransformer {
} }
} }
private void resetMockContext() {
LogUtil.resetLogLevel();
}
/** /**
* Split desc to "first parameter" and "desc of rest parameters" * Split desc to "first parameter" and "desc of rest parameters"
* @param desc method desc * @param desc method desc