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

[java] Suggest a new rule for uninitialized non final member class/ class variable #1390

Open
jmetertea opened this issue Oct 15, 2018 · 0 comments
Labels
a:new-rule Proposal to add a new built-in rule

Comments

@jmetertea
Copy link

jmetertea commented Oct 15, 2018

Affects PMD Version:
Add new rule to next version
Rule:
I'm suggesting adding a new rule UnusedMemberClassVariableRule
Description:
Java compiler isn't warning on a non final private member class/ class variable that has no initialization code and is used (thus create a NullPointerException)
Relevant question: https://stackoverflow.com/questions/52810496/avoid-uninitialized-non-final-member-class-class-variable

**Code Sample demonstrating the issue:**
private static Map<String, String> mapStatic; // Missing compile/warning
private Map<String, String> map; // Missing compile/warning
public void  put() {
    map.put("x", "1"); // NullPointerException
    //Map<String, String> mapVar;
    //mapVar.put("x", "1"); // Compile The local variable mapVar may not have been initialized
}
static {
    mapStatic.put("x", "1"); // NullPointerException        
}

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]

@oowekyala oowekyala added the a:new-rule Proposal to add a new built-in rule label Oct 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:new-rule Proposal to add a new built-in rule
Projects
None yet
Development

No branches or pull requests

2 participants