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

@CheckForNull and @Nonnull not working within lambdas #95

Closed
dylanwatsonsoftware opened this issue Apr 27, 2016 · 2 comments
Closed

@CheckForNull and @Nonnull not working within lambdas #95

dylanwatsonsoftware opened this issue Apr 27, 2016 · 2 comments
Labels

Comments

@dylanwatsonsoftware
Copy link

dylanwatsonsoftware commented Apr 27, 2016

Null pointer de-reference checks do not appear to be working within Java 8 lambdas.

Anonymous classes work fine but converting these to lambdas effectively suppresses any warnings.

See below for an example test case:

package sfBugsNew;

import javax.annotation.CheckForNull;
import edu.umd.cs.findbugs.annotations.ExpectWarning;

/**
 */
public class Bug {

  /**
   * @return may be null
   */
  @CheckForNull
  public static String methodThatMightReturnNull() {
    if (Boolean.getBoolean("test")) {
      return null;
    }

    return "test";
  }

  /**
   */
  @ExpectWarning("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
  public void testNPLambda() {
    Runnable lambda = () -> {
      String maybeNull = methodThatMightReturnNull();

      // would expect findbugs warning about possible null dereferencing here
      boolean empty = maybeNull.isEmpty();
      System.out.println(empty);
    };
    lambda.run();
  }

}
@jsotuyod
Copy link
Contributor

jsotuyod commented Dec 6, 2016

@lotsabackscatter this one is fixed on master branch of Spotbugs, will be included in the next release (3.1.0).

Thanks for the report.

@iloveeclipse
Copy link
Member

This project continues development in a new home: https://github.com/spotbugs/spotbugs/

Please do not open new issues here anymore!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants