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

Conversion of loops to functional notation in this example fails

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 12.0
    • 12.0
    • None
    • None
    • Windows 10, Java 14, NB 12.0

    Description

      When NB recommends converting certain loops into functional notation things go very wrong.

      This is the original code:
      for (String emailAddress : mailBean.getToField())

      { email.to(emailAddress); }

      mailBean.getToField() is returning an ArrayList of Strings.

      This is the conversion to functional notation done by hand:
      mailBean.getToField().forEach(emailAddress -> { email.to(emailAddress); }

      );
      This code does work and my program correctly adds email address to the 'to' field. I am using the Jodd email library.

      NB wants to convert the first loop to functional notation. This is what it produces:
      mailBean.getToField())

      { email.to(em.forEach(emailAddress ->ilAddress); }

      );

      As you can see the conversion has intertwined code like a tangled earphone cable.

      Given a simpler problem such as:
      for(String stuff : al)

      { System.out.println(stuff); }
      where al is an ArrayList of 100 Strings NB correctly converts this to
      al.forEach(stuff -> { System.out.println(stuff); }

      );

      Thinking that it could be the method call to access the ArrayList I rewrote the code as:
      ArrayList<String> al = mailBean.getToField();

      for (String emailAddress : al)

      { email.to(emailAddress); }

      Now when I let NB convert the loop to functional notation I received:
      al.fotring emailAddress :->{ email.to(emailAddress); }

      );

      What am I doing wrong?

      Attachments

        Activity

          People

            Unassigned Unassigned
            omniprof Kenneth Fogel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: