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

SpotBugs analysis: Possible NPE dereference in matchesParameters(List) #201

Closed
ghost opened this issue Jan 10, 2023 · 0 comments
Closed

Comments

@ghost
Copy link

ghost commented Jan 10, 2023

While running SpotBugs on our code, the tool noted:

Possible null pointer dereference
There is a branch of statement that, if executed, guarantees that a null value will be dereferenced, which would generate a NullPointerException when the code is executed. Of course, the problem might be that the branch or statement is infeasible and that the null pointer exception cannot ever be executed; deciding that is beyond the ability of SpotBugs.

Bug kind and pattern: NP - NP_NULL_ON_SOME_PATH

Apologies for the screenshot, the tool doesn't allow selecting the text:

dbus-npe

The problem appears to be with the following lines:

 public boolean matchesParameters(List<Class<?>> _wantedArgs) {
            if (parameterTypes != null && _wantedArgs == null) {
                return false;
            }
            if (parameterTypes.size() != _wantedArgs.size()) {
                return false;
            }

The parameterTypes != null is a null guard that can be skipped, resulting in an NPE when _wantedArgs isn't null (due to dereferencing the size at parameterTypes.size()). It may be safer to write this as follows:

 public boolean matchesParameters(List<Class<?>> _wantedArgs) {
    if( parameterTypes == null || _wantedArgs == null ) {
      return false;
    }
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

No branches or pull requests

0 participants