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

Rule to prohibit local variables by specific type #2

Closed
dgroup opened this issue Jan 6, 2022 · 4 comments · Fixed by #17
Closed

Rule to prohibit local variables by specific type #2

dgroup opened this issue Jan 6, 2022 · 4 comments · Fixed by #17
Assignees
Milestone

Comments

@dgroup
Copy link
Owner

dgroup commented Jan 6, 2022

ObjectMapper is better to have as field than a local variable due to performance reasons

@dykov
Copy link
Collaborator

dykov commented Jan 6, 2022

//LocalVariableDeclaration/Type/ReferenceType/ClassOrInterfaceType
[pmd-java:typeIs('xxx')]
(: or for list of strings (property type="List[String]" name="classes"):
[some $class in $classes satisfies pmd-java:typeIs($class)]
:)

@dykov
Copy link
Collaborator

dykov commented Jan 7, 2022

@dgroup , should we check cases when a ObjectMapper comes as a method parameter? Or should it be a separate rule?

import com.fasterxml.jackson.databind.ObjectMapper;             
public class Foo {
    public void bar(ObjectMapper objectMapper) {}
}

@dykov
Copy link
Collaborator

dykov commented Jan 7, 2022

@dgroup , also, should we check the following cases?

String str = new ObjectMapper().writeValueAsString(obj);

@dgroup
Copy link
Owner Author

dgroup commented Jan 7, 2022

Yes, we need.

@dykov dykov linked a pull request Jan 7, 2022 that will close this issue
3 tasks
@rultor rultor closed this as completed in #17 Jan 7, 2022
@dgroup dgroup added this to the 0.1.0 milestone Jan 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants