Comments (7)
It is because Byte Buddy figured out that another method defined on the Object
type is more suitable for binding. You can restrain this by defining:
MethodDelegation.to(new GeneralInterceptor(new ProxyedInterfaceDelegate(10L)))
.filter(not(isDeclaredBy(Object.class)))
to tell the method delegation not to consider the Object
type's methods. However, this default behavior is a little bit unintuitive. I'll see if I find a more intuitive default for a future version without breaking the general idea of the MethodDelegation
's binding algorithm.
from byte-buddy.
Awesome! I was thinking .method(isDeclaredBy(type)) would filter out object methods.
Thanks for the quick turnarounds and this fantastic library.
from byte-buddy.
For clarification: There are two filters involved:
- The filter for the methods of the dynamically generated type. Saying: When you define that you want to
subclass(type)
, you are further saying you want to override methods that matchisDeclaredBy(type)
and let the others alone. - The filter for the
MethodDelegation
where you are constraining to methods of yourGeneralInterceptor
that arenot(isDeclaredBy(Object.class))
, i.e. theintercept
method.
In Byte Buddy 0.5, I added an additional AmbiguityResolver
that automatically selects the method out of two that is declared by the most specific type which is a better default. This behavior bothered me before, I think this is a better approach for the future. Expect a release of this version sometime the year-shift.
PS: There is a bug fix release 0.4.1 available that allows you to use the InvocationHandlerAdapter
if you want to. Its now also on Maven Central.
from byte-buddy.
Got it. I am already using the latest 0.4.1 release. Thank you so much.
from byte-buddy.
I just want to add that having to exclude Object class methods is quite problematic. It is preventing me from delegating calls to equals(...) method to an underlying implementation. Hopefully the new solution will allow me to delegate methods like equals.
from byte-buddy.
It does! It just prefers methods of a subtype without discarding them. You are also always free to configure your own AmbiguityResolver
or to rearrange the existing ones. If you want to delegate to equals(Object)
, it however sounds like you might be able to use the more efficient Forwarding
instrumentation which always delegates to a method with identical signature.
When filtering, you can always include the equals method by for example specifying not(isDeclaredBy(Object.class)).or(named("equals"))
.
from byte-buddy.
Excellent!
from byte-buddy.
Related Issues (20)
- Release missing of version 1.14.15 HOT 1
- java.lang.NoSuchMethodError when using the agent for method instrumentation HOT 2
- Cannot invoke public constructor HOT 5
- ByteBuddyAgent, Java 21 - A Java agent has been loaded dynamically HOT 2
- include method does not exist for Method Delegation approach HOT 6
- Having trouble delegating added instance method to static method HOT 2
- Setting value in constructor aliases collections HOT 5
- Is it possible to lazily instantiate AllArguments?
- install transformer takes too long time HOT 3
- Example that could be used in documentation HOT 6
- Issues attaching to Solaris Hotspot on Solaris 10 and 11. HOT 1
- How to generate multi-level generic code ? HOT 2
- java.lang.IllegalAccessError HOT 15
- InjectionStrategy.UsingUnsafe.OfFactory HOT 1
- java.lang.IncompatibleClassChangeError: Interface method reference: java.util.stream.Sink.begin(J)V HOT 1
- defineField not working well HOT 1
- JDK class enhancements HOT 3
- ByteBuddy is incompatible with CDS due to the Java 6 baseline HOT 3
- No JPMS module-info or Automatic-Module-Name in byte-buddy-dep HOT 2
- How to call method self when use Advice HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from byte-buddy.