jmockit / jmockit1

Advanced Java library for integration testing, mocking, faking, and code coverage
Other
461 stars 239 forks source link

after @Injectable a mybatis mapper which method has multiple parameters without @Param, following test classes which @Autowired the same mapper will throw BindingException #659

Open zrlw opened 4 years ago

zrlw commented 4 years ago
zrlw commented 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); ....

zrlw commented 4 years ago

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.

zrlw commented 4 years ago

OpenJDK assigned bug id: JDK-8240908, RetransformClass does not know about MethodParameters attribute. https://bugs.openjdk.java.net/browse/JDK-8240908