diff --git a/src/main/java/com/alibaba/testable/generator/StaticNewClassGenerator.java b/src/main/java/com/alibaba/testable/generator/StaticNewClassGenerator.java index c219240..a1e2619 100644 --- a/src/main/java/com/alibaba/testable/generator/StaticNewClassGenerator.java +++ b/src/main/java/com/alibaba/testable/generator/StaticNewClassGenerator.java @@ -42,7 +42,11 @@ public class StaticNewClassGenerator { .beginControlFlow("for (Object o : args)") .addStatement("pts.add(o.getClass())") .endControlFlow() - .addStatement("return type.getConstructor(pts.toArray(new Class[0])).newInstance(args)"); + .beginControlFlow("try") + .addStatement("return type.getConstructor(pts.toArray(new Class[0])).newInstance(args)") + .nextControlFlow("catch (Exception e)") + .addStatement("return null") + .endControlFlow(); } }