Skip to content

Conversation

mkouba
Copy link
Contributor

@mkouba mkouba commented Mar 27, 2025

java.lang.ClassCastException: class io.github.dmlloyd.classfile.impl.AbstractPoolEntry$MethodRefEntryImpl cannot be cast to class io.github.dmlloyd.classfile.constantpool.InterfaceMethodRefEntry (io.github.dmlloyd.classfile.impl.AbstractPoolEntry$MethodRefEntryImpl and io.github.dmlloyd.classfile.constantpool.InterfaceMethodRefEntry are in module io.github.dmlloyd.classfile@24.0 of loader 'app')
	at io.github.dmlloyd.classfile@24.0/io.github.dmlloyd.classfile.impl.AbstractInstruction$UnboundInvokeInstruction.writeTo(AbstractInstruction.java:1056)
	at io.github.dmlloyd.classfile@24.0/io.github.dmlloyd.classfile.impl.DirectCodeBuilder.with(DirectCodeBuilder.java:125)
	at io.github.dmlloyd.classfile@24.0/io.github.dmlloyd.classfile.impl.DirectCodeBuilder.with(DirectCodeBuilder.java:47)
	at io.github.dmlloyd.classfile@24.0/io.github.dmlloyd.classfile.impl.BlockCodeBuilderImpl.with(BlockCodeBuilderImpl.java:87)
	at io.github.dmlloyd.classfile@24.0/io.github.dmlloyd.classfile.impl.BlockCodeBuilderImpl.with(BlockCodeBuilderImpl.java:37)
	at io.github.dmlloyd.classfile@24.0/io.github.dmlloyd.classfile.CodeBuilder.invoke(CodeBuilder.java:540)
	at io.github.dmlloyd.classfile@24.0/io.github.dmlloyd.classfile.CodeBuilder.invoke(CodeBuilder.java:557)
	at io.quarkus.gizmo2@2.0.1-SNAPSHOT/io.quarkus.gizmo2.impl.Invoke.writeCode(Invoke.java:59)
	at io.quarkus.gizmo2@2.0.1-SNAPSHOT/io.quarkus.gizmo2.impl.BlockCreatorImpl.lambda$writeCode$39(BlockCreatorImpl.java:1230)
	at io.github.dmlloyd.classfile@24.0/io.github.dmlloyd.classfile.CodeBuilder.block(CodeBuilder.java:210)
	at io.quarkus.gizmo2@2.0.1-SNAPSHOT/io.quarkus.gizmo2.impl.BlockCreatorImpl.writeCode(BlockCreatorImpl.java:1226)
	at io.quarkus.gizmo2@2.0.1-SNAPSHOT/io.quarkus.gizmo2.impl.ExecutableCreatorImpl.doCode(ExecutableCreatorImpl.java:169)
	at io.quarkus.gizmo2@2.0.1-SNAPSHOT/io.quarkus.gizmo2.impl.ExecutableCreatorImpl.lambda$doBody$6(ExecutableCreatorImpl.java:153)
	at io.github.dmlloyd.classfile@24.0/io.github.dmlloyd.classfile.impl.DirectCodeBuilder.build(DirectCodeBuilder.java:92)
	at io.github.dmlloyd.classfile@24.0/io.github.dmlloyd.classfile.impl.DirectMethodBuilder.withCode(DirectMethodBuilder.java:118)
	at io.github.dmlloyd.classfile@24.0/io.github.dmlloyd.classfile.impl.DirectMethodBuilder.withCode(DirectMethodBuilder.java:125)
	at io.quarkus.gizmo2@2.0.1-SNAPSHOT/io.quarkus.gizmo2.impl.ExecutableCreatorImpl.doBody(ExecutableCreatorImpl.java:152)
	at io.quarkus.gizmo2@2.0.1-SNAPSHOT/io.quarkus.gizmo2.impl.ExecutableCreatorImpl.lambda$body$7(ExecutableCreatorImpl.java:180)
	at io.github.dmlloyd.classfile@24.0/io.github.dmlloyd.classfile.impl.DirectMethodBuilder.run(DirectMethodBuilder.java:139)
	at io.github.dmlloyd.classfile@24.0/io.github.dmlloyd.classfile.impl.DirectClassBuilder.withMethod(DirectClassBuilder.java:117)
	at io.github.dmlloyd.classfile@24.0/io.github.dmlloyd.classfile.ClassBuilder.withMethod(ClassBuilder.java:313)
	at io.quarkus.gizmo2@2.0.1-SNAPSHOT/io.quarkus.gizmo2.impl.ExecutableCreatorImpl.body(ExecutableCreatorImpl.java:179)
	at io.quarkus.gizmo2@2.0.1-SNAPSHOT/io.quarkus.gizmo2.impl.InstanceMethodCreatorImpl.body(InstanceMethodCreatorImpl.java:16)
	at io.quarkus.gizmo2@2.0.1-SNAPSHOT/io.quarkus.gizmo2.impl.LambdaCreatorImpl.body(LambdaCreatorImpl.java:30)
	at io.quarkus.gizmo2@2.0.1-SNAPSHOT/io.quarkus.gizmo2.LambdaTest.lambda$5(LambdaTest.java:44)

@dmlloyd Have you come across this before?

@dmlloyd
Copy link
Member

dmlloyd commented Mar 27, 2025

No, that's new... I'll have to investigate to see whether it's a usage error or a bug in the classfile API itself.

@dmlloyd
Copy link
Member

dmlloyd commented Mar 27, 2025

BTW I was really lazy and put a basic lambda test under AnonClassTest. I guess it should be moved with the other one.

@mkouba
Copy link
Contributor Author

mkouba commented Mar 27, 2025

BTW I was really lazy and put a basic lambda test under AnonClassTest. I guess it should be moved with the other one.

Good point. I did not spot this test before. I will move it. Hm, no assert in a test, really? ;-)

@dmlloyd
Copy link
Member

dmlloyd commented Mar 27, 2025

BTW I was really lazy and put a basic lambda test under AnonClassTest. I guess it should be moved with the other one.

Good point. I did not spot this test before. I will move it. Hm, no assert in a test, really? ;-)

Well, it didn't crash, did it?? :-)

@mkouba
Copy link
Contributor Author

mkouba commented Mar 27, 2025

I fixed the test and the stack is different now, something like:

java.lang.IllegalArgumentException: Operand stack underflow at bytecode offset 8 of method runTest()
  - max stack: 65535
    max locals: 65535
    attributes: []
    //stack map frame @0: {locals: [], stack: []}
    0: {opcode: NEW, type: java/util/concurrent/atomic/AtomicInteger}
    3: {opcode: DUP}
    4: {opcode: INVOKESPECIAL, owner: java/util/concurrent/atomic/AtomicInteger, method name: <init>, method type: ()V}
    7: {opcode: ASTORE_0, slot: 0}
    8: {opcode: INVOKEDYNAMIC, name: yv66vgAAAD0AHgEAJ2lvL3F1YXJrdXMvZ2l6bW8yL1J1bm5hYmxlTGFtYmRhJGxhbWJkYQcAAQEAEGphdmEvbGFuZy9PYmplY3QHAAMBAANydW4BAAMoKVYBAANyZXQBACtMamF2YS91dGlsL2NvbmN1cnJlbnQvYXRvbWljL0F0b21pY0ludGVnZXI7DAAHAAgJAAIACQEAKWphdmEvdXRpbC9jb25jdXJyZW50L2F0b21pYy9BdG9taWNJbnRlZ2VyBwALAQAPaW5jcmVtZW50QW5kR2V0AQADKClJDAANAA4KAAwADwEABjxpbml0PgEALihMamF2YS91dGlsL2NvbmN1cnJlbnQvYXRvbWljL0F0b21pY0ludGVnZXI7KVYBAAR0aGlzAQApTGlvL3F1YXJrdXMvZ2l6bW8yL1J1bm5hYmxlTGFtYmRhJGxhbWJkYTsMABEABgoABAAVAQASamF2YS9sYW5nL1J1bm5hYmxlBwAXAQAEQ29kZQEAEE1ldGhvZFBhcmFtZXRlcnMBABJMb2NhbFZhcmlhYmxlVGFibGUBAAlTaWduYXR1cmUBACZMamF2YS9sYW5nL09iamVjdDtMamF2YS9sYW5nL1J1bm5hYmxlOxARAAIABAABABgAAQASAAcACAAAAAIAAQAFAAYAAQAZAAAAFQABAAEAAAAJKrQACrYAEFexAAAAAAAAABEAEgACABoAAAAFAQAHAAAAGQAAADIAAgACAAAACiq3ABYqK7UACrEAAAABABsAAAAWAAIAAAAKABMAFAAAAAAACgAHAAgAAQABABwAAAACAB0=, descriptor: (Ljava/util/concurrent/atomic/AtomicInteger;)Ljava/lang/Runnable;, bootstrap method: STATIC io/quarkus/gizmo2/RunnableLambda::defineLambdaCallSite, arguments: []}
    13: {opcode: INVOKEINTERFACE, owner: java/lang/Runnable, method name: run, method type: ()V}
    18: {opcode: ALOAD_0, slot: 0}
    19: {opcode: INVOKEVIRTUAL, owner: java/util/concurrent/atomic/AtomicInteger, method name: get, method type: ()I}
    22: {opcode: IRETURN}

@dmlloyd
Copy link
Member

dmlloyd commented Mar 27, 2025

This one I have a fix for. I forgot the small detail of passing the captures to the indy. Patch incoming.

@dmlloyd
Copy link
Member

dmlloyd commented Mar 27, 2025

There's still one more problem but I think it's a problem in the test.

@mkouba
Copy link
Contributor Author

mkouba commented Mar 27, 2025

There's still one more problem but I think it's a problem in the test.

Thanks, I'll take a look.

@mkouba
Copy link
Contributor Author

mkouba commented Mar 27, 2025

@dmlloyd I didn't find anything but I've added one more simple test for lambda param and captured value and it fails in the same way...

@dmlloyd
Copy link
Member

dmlloyd commented Mar 27, 2025

Found the problem, an off-by-one (of course). I also did a minor cleanup as well.

@mkouba mkouba marked this pull request as ready for review March 28, 2025 07:05
@mkouba mkouba merged commit c42def8 into quarkusio:2.x Mar 28, 2025
2 checks passed
@Ladicek Ladicek added the 2.x Issue applies to Gizmo 2.x label Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Issue applies to Gizmo 2.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants