-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ClassLoader issue in test mode with Multipart in multi-module project #19068
Conversation
// call the populator | ||
injectMethod.visitMethodInsn(Opcodes.INVOKESTATIC, populatorName.replace('.', '/'), | ||
DotNames.POPULATE_METHOD_NAME, | ||
String.format("(%s%s)V", thisDescriptor, INJECTION_CONTEXT_DESCRIPTOR), false); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I debated whether to keep this around for launch modes that are not test, but I think there isn't too much benefit in doing so...
injectMethod.visitMethodInsn(Opcodes.INVOKESTATIC, THREAD_BINARY_NAME, "currentThread", "()Ljava/lang/Thread;", | ||
false); | ||
injectMethod.visitMethodInsn(Opcodes.INVOKEVIRTUAL, THREAD_BINARY_NAME, "getContextClassLoader", | ||
"()Ljava/lang/ClassLoader;", false); | ||
injectMethod.visitLdcInsn(populatorName); | ||
injectMethod.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/ClassLoader", "loadClass", | ||
"(Ljava/lang/String;)Ljava/lang/Class;", false); | ||
injectMethod.visitLdcInsn("populate"); | ||
injectMethod.visitInsn(Opcodes.ICONST_2); | ||
injectMethod.visitTypeInsn(Opcodes.ANEWARRAY, CLASS_BINARY_NAME); | ||
injectMethod.visitInsn(Opcodes.DUP); | ||
injectMethod.visitInsn(Opcodes.ICONST_0); | ||
injectMethod.visitVarInsn(Opcodes.ALOAD, 0); | ||
injectMethod.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false); | ||
injectMethod.visitInsn(Opcodes.AASTORE); | ||
injectMethod.visitInsn(Opcodes.DUP); | ||
injectMethod.visitInsn(Opcodes.ICONST_1); | ||
injectMethod.visitLdcInsn(Type.getType(INJECTION_CONTEXT_DESCRIPTOR)); | ||
injectMethod.visitInsn(Opcodes.AASTORE); | ||
injectMethod.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CLASS_BINARY_NAME, "getMethod", | ||
"(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;", false); | ||
injectMethod.visitInsn(Opcodes.ACONST_NULL); | ||
injectMethod.visitInsn(Opcodes.ICONST_2); | ||
injectMethod.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object"); | ||
injectMethod.visitInsn(Opcodes.DUP); | ||
injectMethod.visitInsn(Opcodes.ICONST_0); | ||
injectMethod.visitVarInsn(Opcodes.ALOAD, 0); | ||
injectMethod.visitInsn(Opcodes.AASTORE); | ||
injectMethod.visitInsn(Opcodes.DUP); | ||
injectMethod.visitInsn(Opcodes.ICONST_1); | ||
injectMethod.visitVarInsn(Opcodes.ALOAD, 1); | ||
injectMethod.visitInsn(Opcodes.AASTORE); | ||
injectMethod.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Method", "invoke", | ||
"(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I obviously didn't come up with all this myself... I used the Bytecode Viewer plugin (on a sample class I wrote) in IntelliJ which has the capability to "ASM-ify" bytecode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me have a look at what is going on here before we go down this route.
Superseded by #19070 |
Fixes: #19037