Open zrlw opened 4 years ago
i resovled the problem by keep interfaces and abstract classes original, it's much better than restoring mocked classes after each test execution which will cause JMockit's few functions failure. at lease this commit will build success by maven clean install with testing. https://github.com/zrlw/jmockit1/commit/18aee0d04612b4aa7613a6bd056214647d67d420 Since Oracle JDK not opensource, i checked the latest OpenJDK source, JDK Instrumentation.retransformClasses don't write MethodParameters attribute in JvmtiClassFileReconstituter.cpp: void JvmtiClassFileReconstituter::write_method_info(const methodHandle& method) { ... // write attributes in the same order javac does, so we can test with byte for // byte comparison int attr_count = 0; if (const_method->code_size() != 0) { ++attr_count; // has Code attribute } if (const_method->has_checked_exceptions()) { ++attr_count; // has Exceptions attribute } if (default_anno != NULL) { ++attr_count; // has AnnotationDefault attribute } // Deprecated attribute would go here if (access_flags.is_synthetic()) { // FIXME // ++attr_count; } if (generic_signature_index != 0) { ++attr_count; } if (anno != NULL) { ++attr_count; // has RuntimeVisibleAnnotations attribute } if (param_anno != NULL) { ++attr_count; // has RuntimeVisibleParameterAnnotations attribute } if (type_anno != NULL) { ++attr_count; // has RuntimeVisibleTypeAnnotations attribute }
write_u2(attr_count); ....
I sent a email to jdk-dev mailing list to suggest that the maintainers add MethodParameter attribute in JvmtiClassFileReconstituter::write_method_info(), and got response emails that asked if i could reproduce the issue with JDK 14 or the latest JDK 15 EA build. I runned the sample - https://github.com/zrlw/jmockit-mybatis-bindingexception-sample.git - with JDK 15 EA build 13 and got same exception. PS: I found JMockit might not be compatible with JDK 15 EA build 13, Maven build will be ok only if Skip Tests option checked.
OpenJDK assigned bug id: JDK-8240908, RetransformClass does not know about MethodParameters attribute. https://bugs.openjdk.java.net/browse/JDK-8240908
Version of JMockit that was used: 1.49
Description of the problem or enhancement request: after
@Injectable
a mybatis mapper interface which method has multiple parameters without@Param,
following test classes which@Autowired
the same mapper will throw BindingException when calling those methods.Reproduce Step GitHub Repo: https://github.com/zrlw/jmockit-mybatis-bindingexception-sample.git IDE: Eclipse 4.11.0 Tool integration: Maven Jdk: 1.8
Expected Result the second test class should pass arguments name 'firstName', 'lastName' to mybatis just like test it alone.
Actual Result the second test class pass arguments name arg0, arg1, param1, param2 to mybatis after the first class which used @Injectable tested.