fix compatibility with spring boot

This commit is contained in:
金戟 2021-04-03 23:54:01 +08:00
parent cc2deeff1c
commit 844323af3a
2 changed files with 13 additions and 2 deletions

View File

@ -31,7 +31,7 @@ public class OmniClassHandler extends BaseClassHandler {
@Override
protected void transform(ClassNode cn) {
if (isInterface(cn) || isJunitTestClass(cn)) {
if (isInterface(cn) || isJunitTestClass(cn) || isUninstantiableClass(cn)) {
return;
}
MethodNode constructor = new MethodNode(ACC_PUBLIC, CONSTRUCTOR,
@ -51,6 +51,16 @@ public class OmniClassHandler extends BaseClassHandler {
cn.methods.add(constructor);
}
private boolean isUninstantiableClass(ClassNode cn) {
// if the class has no even default constructor, skip it
for (MethodNode mn : cn.methods) {
if (mn.name.equals(CONSTRUCTOR)) {
return false;
}
}
return true;
}
private boolean isInterface(ClassNode cn) {
// is interface or the object class
return (cn.access & ACC_INTERFACE) != 0 || cn.superName == null;

View File

@ -41,7 +41,8 @@ public class TestableClassTransformer implements ClassFileTransformer {
/**
* Just avoid spend time to scan those surely non-user classes, should keep these lists as tiny as possible
*/
private final String[] BLACKLIST_PREFIXES = new String[] { "sun/", "com/sun/", "org/gradle/" };
private final String[] BLACKLIST_PREFIXES = new String[] { "sun/", "com/sun/", "org/gradle/",
"org/springframework/boot/autoconfigure/" };
public MockClassParser mockClassParser = new MockClassParser();