4

I have encountered a strange bug in Netbeans 8.2.

When declaring an object with a lambda expression, autocomplete for variables inside the lambda does not seem to work, and instead I see global variables, suggestions for keywords amongst other things as shown in the screenshot.

As you can see, testString and testString2 are nowhere in sight.

I have tried other objects and the result is always the same.

Now if we do the same with an anonymous inner class, we can see that our variables testString and testString2 do appear. enter image description here

Here is the sample code for you to try on your IDEs. I have also included an ActionListener to demonstrate that the problem doesn't lie with just one interface.

public class SOInner {

    private ActionListener listenerExampleLambda = e -> {
        //autocomplete DOES NOT work for these vars
        int testVarInner = 2;
        int testVarInner2 = 4;

    };

    private ActionListener listenerExampleClass = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //autocomplete works for these vars
            int testVarInner = 2;
            int testVarInner2 = 4;
        }
    };

    private Comparable<SOInner> comparableExampleLambda = o -> {
        //autocomplete DOES NOT work for these vars        
        String testString = "Hello";
        String testString2 = "Hi";        
        return 0;
    };

    private Comparable<SOInner> comparableExampleClass = new Comparable<SOInner>() {
        @Override
        public int compareTo(SOInner o) {
            //autocomplete works for these vars
            String testString = "Hello";
            String testString2 = "Hi";
            return 0;
        }
    };
}

Is there a solution for this bug or has it been recorded already?

Morgan
  • 907
  • 1
  • 13
  • 35
  • What is your question? –  Jan 24 '18 at 13:57
  • I have added the question now. – Morgan Jan 24 '18 at 13:59
  • 2
    Did you file a bug report? https://issues.apache.org/jira/projects/NETBEANS –  Jan 24 '18 at 14:00
  • Will do now. Thanks for providing a link, the Bugzilla section on the Netbeans website is a mess. – Morgan Jan 24 '18 at 14:09
  • I have reported this bug here: https://issues.apache.org/jira/browse/NETBEANS-326 – Morgan Jan 24 '18 at 14:18
  • Yes, I see the same problem in NetBeans8.2 with your declarations for listenerExampleLambda and comparableExampleLambda. And +1 for actually creating a bug report. – skomisa Jan 24 '18 at 18:50
  • 1
    Something worth noting for your two failing examples is that if you break them up into declarations and assignments within an initializer block then they also work fine. For example, autocomplete works for this: _private Comparable comparableExampleLambda; { comparableExampleLambda = o -> { yadda, yadda }};_ – skomisa Jan 24 '18 at 18:58

0 Answers0