byte-buddy
byte-buddy copied to clipboard
IllegalStateException: Cannot define abstract method '...' for non-abstract class when defining a native method
I'm trying to create a subclass where I override some methods with a native implementation. Here is my attempt :
Class<?> dynamicType = new ByteBuddy()
.subclass(Block.class)
.name("fr.supersurviveur.rustcraftmod.DynamicBlock")
.defineMethod("onUse", ActionResult.class, Modifier.NATIVE | Modifier.PUBLIC)
.withoutCode()
.make()
.load(getClass().getClassLoader())
.getLoaded();
But it gives me this exception :
java.lang.IllegalStateException: Cannot define abstract method 'onUse' for non-abstract class
It seems that withoutCode defines the method as abstract. Is it possible to prevent this?
This looks like a BUG, you may need to bypass TypeValidation
now
new ByteBuddy().with(TypeValidation.DISABLED)
With new ByteBuddy().with(TypeValidation.DISABLED)
, I have an exception when i the method is used :
java.lang.AbstractMethodError: Receiver class fr.supersurviveur.rustcraftmod.DynamicBlock does not define or inherit an implementation of the resolved method 'net.minecraft.util.ActionResult onUse(net.minecraft.block.BlockState, net.minecraft.world.World, net.minecraft.util.math.BlockPos, net.minecraft.entity.player.PlayerEntity, net.minecraft.util.Hand, net.minecraft.util.hit.BlockHitResult)' of abstract class net.minecraft.block.AbstractBlock. Selected method is 'abstract net.minecraft.util.ActionResult fr.supersurviveur.rustcraftmod.DynamicBlock.onUse(net.minecraft.block.BlockState, net.minecraft.world.World, net.minecraft.util.math.BlockPos, net.minecraft.entity.player.PlayerEntity, net.minecraft.util.Hand, net.minecraft.util.hit.BlockHitResult)'.
This is a bug in the modifier resolution for new native methods indeed. Very little used feature, it seems. I just fixed this on master. Could you build Byte Buddy and test with the snapshot?
This is a bug in the modifier resolution for new native methods indeed. Very little used feature, it seems. I just fixed this on master. Could you build Byte Buddy and test with the snapshot?
It works well with the snapshot, thank you !