Skip to content

Java: Nullness: LGTM.com - false positive #3176

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

Open
ChrisKujawa opened this issue Mar 31, 2020 · 1 comment
Open

Java: Nullness: LGTM.com - false positive #3176

ChrisKujawa opened this issue Mar 31, 2020 · 1 comment

Comments

@ChrisKujawa
Copy link

ChrisKujawa commented Mar 31, 2020

Description of the false positive

 if (!channel.isActive()) {
              CompletableFuture<Channel> currentFuture;
              synchronized (channelPool) {
                currentFuture = channelPool.get(offset);
                if (currentFuture == finalFuture) { // final future is not null since it is used also before
                  channelPool.set(offset, null);
                } else if (currentFuture == null) {
                  currentFuture = factory.apply(address); // <== assigned here
                  currentFuture.whenComplete(this::logConnection); // <== used here
                  channelPool.set(offset, currentFuture);
                }
              }

              if (currentFuture == finalFuture) {
                getChannel(address, messageType)
                    .whenComplete(
                        (recursiveResult, recursiveError) -> {
                          completeFuture(future, recursiveResult, recursiveError);
                        });
              } else {
                currentFuture.whenComplete( // <== can't be null here

We can see that if currentFuture is null then it is assigned a new value, which is used directly afterwards, which means it cant be null later.
URL to the alert on the project page on LGTM.com
https://lgtm.com/projects/g/zeebe-io/zeebe/snapshot/e722021d676bdbeee3366fa1c10a915f031bbf0c/files/atomix/cluster/src/main/java/io/atomix/cluster/messaging/impl/ChannelPool.java?sort=name&dir=ASC&mode=heatmap#xa937c5d4af2d26c1:1

@aschackmull
Copy link
Contributor

Thank you for your report. You are correct that this is a FP, and for now I'd suggest suppressing the alert with an alert suppression comment.

@aschackmull aschackmull changed the title LGTM.com - false positive Java: Nullness: LGTM.com - false positive Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants