Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8024696

Missing null check in bound method reference capture

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 8
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b110
    • Verification:
      Verified

      Description

      When a bound method reference is captured, we should do a null check on the result of the receiver:

          Sam mr = foo::bar;

      The expression "foo" is evaluated immediately, and if it is null, we should throw NPE.

      Relevant spec:

      If the expression is a method reference that begins with an ExpressionName or a Primary, this subexpression is first evaluated. [jsr335-15.28.2-30-A]
      If the subexpression evaluation completes abruptly, then the method reference evaluation completes abruptly for the same reason. [jsr335-15.28.2-30-A1]
      If the result of evaluation of the subexpression is null, then a NullPointerException is thrown. [jsr335-15.28.2-30-A2]



      Test case below:

      import java.util.function.*;

      public class Foo {
        public static void main(String[] args) {
          String s = null;
          Supplier<Boolean> ss = s::isEmpty;
        }
      }

        Attachments

          Activity

            People

            Assignee:
            vromero Vicente Arturo Romero Zaldivar
            Reporter:
            briangoetz Brian Goetz
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: