Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to determine type initializer existence? #1752

Open
eaglemartin opened this issue Jan 17, 2025 · 2 comments
Open

How to determine type initializer existence? #1752

eaglemartin opened this issue Jan 17, 2025 · 2 comments
Assignees
Labels
Milestone

Comments

@eaglemartin
Copy link

Does bytebuddy have API to determine TypeInitializer method exists? So I could check it before instrument TypeInitializer as below,

new AgentBuilder.Transformer.ForAdvice().advice( isTypeInitializer(), "TypeInitializerAdvice" );

@raphw
Copy link
Owner

raphw commented Jan 17, 2025

This is more tricky than it might seem. If there is a type initializer from before, the above code will work. If not, you will need to add another transformation as:

builder
  .invokable(isTypeInitializer())
  .intercept(StubMethod.INSTANCE)

This will define an empty type initializer. This does however count as changing the method structure, and a redefinition will fail, as the JVM does not allow for that.

@raphw raphw self-assigned this Jan 17, 2025
@raphw raphw added the question label Jan 17, 2025
@raphw raphw added this to the 1.15.11 milestone Jan 17, 2025
@eaglemartin
Copy link
Author

I does not want to add a type intializer which will change the class layout, and just need to know there is a type initializer for a type.

I think bytebuddy might add a method such as hasTypeInitializer() to LazyTypeDescription since it is easy to determine this when visiting method in TypeExtractor via ASM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants