raphw / byte-buddy

Runtime code generation for the Java virtual machine.
https://bytebuddy.net
Apache License 2.0
6.23k stars 804 forks source link

Strange interaction with method implementations for methods from composite interfaces #1582

Closed superyuuki closed 8 months ago

superyuuki commented 8 months ago

I posted this on #949 but to give it a name, i'll repost it again below:

I think i've accidentally revived this issue. I have

interface IndividualMotorComponent {
   int id();
} 
interface OtherMotorComponent {
  int someotherId();
}
interface MotorComponent extends OtherMotorComponent, IndividualMotorComponent {

}

I go to parse the methods on MotorComponent like so

for (Method method : useClass.getMethods()) {
  //add to a list
}
for (Method method : list) {
   builder = builder
                        .method(ElementMatchers.named(values.getKey().getName()))
                        .intercept(supplierInvoke);
}

where supplierInvoke is a MethodCall. This works for all interfaces that do not extend other interfaces (If i did this with IndividualMotorComponent it seemed to work okay), but when I use the MotorComponent interface i get the following:

Error at xyz.auriium.mattlib2.rev.HardwareREV.createSparkmax(HardwareREV.java:16): Unhandled exception: java.lang.AbstractMethodError: Receiver class xyz.auriium.mattlib2.hardware.config.MotorComponent$Delegated_e4d225ef does not define or inherit an implementation of the resolved method 'int id()' of interface xyz.auriium.mattlib2.hardware.config.MotorComponent.

Testing reveals that the method.intercept code is being called for the method id(), but when printed the Method displays as so:

public abstract int xyz.auriium.mattlib2.hardware.config.IndividualMotorComponent.id() implemented with 0

I do not know why this occurs but maybe bytebuddy is looking for a Method id specifically defined on MotorComponent, but isn't recognizing that IndividualMotorComponent defines id and so therefore MotorComponent should inherit that implementation?

superyuuki commented 8 months ago

solved the issue