Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-4680

No code completion in Stream#map() function's lambda expression body unless there is a return statement already

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 12.4
    • java - Hints
    • None

    Description

      For the given code:

      import java.util.Arrays;
      import java.util.List;
      import java.util.stream.Collectors;
      
      public class Test {
      
          static class Student {
      
              private Integer id;
              private Integer age;
              private String gender;
              private String firstName;
              private String lastName;
      
              public Integer getId() {
                  return id;
              }
      
              public void setId(Integer id) {
                  this.id = id;
              }
      
              public Integer getAge() {
                  return age;
              }
      
              public void setAge(Integer age) {
                  this.age = age;
              }
      
              public String getGender() {
                  return gender;
              }
      
              public void setGender(String gender) {
                  this.gender = gender;
              }
      
              public String getFirstName() {
                  return firstName;
              }
      
              public void setFirstName(String firstName) {
                  this.firstName = firstName;
              }
      
              public String getLastName() {
                  return lastName;
              }
      
              public void setLastName(String lastName) {
                  this.lastName = lastName;
              }
      
              public Student(Integer id, Integer age, String gender, String firstName, String lastName) {
                  this.id = id;
                  this.age = age;
                  this.gender = gender;
                  this.firstName = firstName;
                  this.lastName = lastName;
              }
      
          }
      
          public static void main(String[] args) {
              Student e1 = new Student(1, 23, "M", "Rick", "Beethoven");
              Student e2 = new Student(2, 13, "F", "Martina", "Hengis");
              Student e3 = new Student(3, 43, "M", "Ricky", "Martin");
              Student e4 = new Student(4, 26, "M", "Jon", "Lowman");
              Student e5 = new Student(5, 19, "F", "Cristine", "Maria");
      
              List<Student> students = Arrays.asList(e1, e2, e3, e4, e5);
              students.stream()
                      .map(s -> {
                          s.setAge(s.getAge() + 1);
                          return s;                                                             
                      })
                      .collect(Collectors.toList());
          }
      }
      
      

      if I comment the the return statement in Stream#map() function, there will be no code completion in map function and after map function.

      students.stream()
      	.map(s -> {
      	    s.setAge(s.getAge() + 1); // no code completion for getter and setter here
      	    // return s;                                                             
      	})
      	.collect(Collectors.toList()); // no code completion here
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              humphrey gao KoKo
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: