Comments (1)
ByteBuddy does not directly provide an API for this operation. You need to leverage the visitors provided by ASM to achieve this. You can refer to the suggested approach here for specifics. How to copy method body of a particular method to another method in different class using ASM
Similarly, you may encounter the side effects mentioned therein.
If you're only dealing with the specific requirement described in the issue, you could consider achieving it through redefine
+ visit
, for example:
new ByteBuddy()
.redefine(Child.class)
.name("child2")
.visit(new AsmVisitorWrapper.AbstractBase() {
@Override
public ClassVisitor wrap(TypeDescription instrumentedType, ClassVisitor classVisitor, Implementation.Context implementationContext, TypePool typePool, FieldList<FieldDescription.InDefinedShape> fields, MethodList<?> methods, int writerFlags, int readerFlags) {
return new ClassVisitor(OpenedClassReader.ASM_API, classVisitor) {
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
super.visit(version, access, name, signature, Type.getInternalName(parentClass), interfaces);
}
};
}
});
However, it still cannot avoid the potential errors mentioned in the link above, so you must be clear about what you are doing and have the ability to handle those issues on your own.
from byte-buddy.
Related Issues (20)
- Can byte-buddy modify bytecode in parallel? HOT 4
- Java 17 reflection changes
- A lazy `TypePool` will change with type resolution and thus deviate from its initial configuration. HOT 2
- JDK 23 Valhalla-EA: IllegalState Illegal modifiers 33 for class HOT 2
- Multiple transformation issue with JMH benchmarks HOT 1
- [question] How can replace field access with another class? HOT 2
- Eclipse project compilation error using mockito and byte-buddy HOT 7
- Runtime attachment causing VerifyError during class transformation HOT 13
- not able to intercept java.lang package HOT 9
- Questions about alternatives to the LocalVariablesSorter class obsoletization HOT 5
- How to create a class with updated private field using ByteBuddy? HOT 2
- Byte buddy access to package protected class HOT 11
- mockito-android:5.12.0 cannot mock class HOT 1
- How to invoke the method of injecting objects into a class? HOT 2
- [Question] Why would a new field var2 be added after replace field access with method? HOT 3
- How to redefine dynamically created classes? HOT 5
- EntryPoint property breaks gradle build HOT 1
- Please help me check this issue. I use the inherited LaunchedURLClassLoader method in agentLauncher to load my lib package, and then inject the shared class into Bootstrap ClassLoader. HOT 7
- [Question] How to find all the member variables used in the method? HOT 2
- [Question] How do I call an intercepted method in an interceptor? HOT 5
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.