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

Unable to intercept the inner class sun. Management. VMManagementImpl,it doesn't work !!! #1741

Open
phpdragon opened this issue Dec 27, 2024 · 1 comment
Assignees
Labels
Milestone

Comments

@phpdragon
Copy link

public static void premain(String args, Instrumentation inst) {
    System.out.println("=========premain method run========");
    AgentBuilder.Default.of(ClassFileVersion.JAVA_V8)
            .type(ElementMatchers.named("sun.management.VMManagementImpl"))
            .transform((builder, typeDescription, classLoader, module, protectionDomain) -> builder
                    .visit(Advice.to(VMManagementImplAdvice.class)
                            .on(ElementMatchers.named("getVmArguments"))))
            .installOn(inst);
    premain(args, inst, false);
}

@Advice.OnMethodExit
public static void intercept(@Advice.Return List<String> vmArgs) {
    vmArgs.add("something");
}

The sun.management.VMManagementImpl replacement for their implementation of the inner classes org.test.Sample , it's work !!!

class Sample {
    public List<String> getVmArguments(List<String> vmArgs){
        return vmArgs;
    }
}
@raphw
Copy link
Owner

raphw commented Dec 27, 2024

Unfortunately, I cannot follow. Do you have a question?

@raphw raphw self-assigned this Dec 27, 2024
@raphw raphw added the question label Dec 27, 2024
@raphw raphw added this to the 1.15.11 milestone Dec 27, 2024
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