Hi Team,
I am trying to build a custom rule in which I want to identify the count of ObjectMapper constructor called.
@Override
public List<Kind> nodesToVisit() {
return Collections.singletonList(Kind.NEW_CLASS);
}
@Override
protected MethodMatchers getMethodInvocationMatchers() {
return MethodMatchers.create().ofTypes("com.fasterxml.jackson.databind.ObjectMapper").constructor().withAnyParameters().build();
}
@Override
protected void onConstructorFound(NewClassTree newClassTree) {
if (!isInConstructorOrStaticMain(newClassTree) && isUsedOnlyLocally(newClassTree)) {
reportIssue(newClassTree.identifier(), "new instance created with each invocation");
}
}
This is not working as it says “No issues Found. Expected one.” which I understand. But the same onConstructorFound is working with
java.util.Random or any jdk classes
Is there any other configuration of dependecies. I tried adding jackson dependency in plugin code as well but it did not work.
Does sonar support only jdk classes for constructor invocation check?
Regards,
Hetal