Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Jul 28, 2021

Fixes: #19037

Comment on lines -82 to -86
// call the populator
injectMethod.visitMethodInsn(Opcodes.INVOKESTATIC, populatorName.replace('.', '/'),
DotNames.POPULATE_METHOD_NAME,
String.format("(%s%s)V", thisDescriptor, INJECTION_CONTEXT_DESCRIPTOR), false);

Copy link
Contributor Author

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...

Comment on lines +90 to +123
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);
Copy link
Contributor Author

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

Copy link
Member

@stuartwdouglas stuartwdouglas left a 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.

@stuartwdouglas
Copy link
Member

Superseded by #19070

@quarkus-bot quarkus-bot bot added triage/invalid This doesn't seem right and removed triage/backport? labels Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest triage/invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multipart Class Defined Outside Resource Implementation Fails with CNFE "Populator"
2 participants