javaeclipsecontent-assist

Eclipse content assist fails in loops after upgrade to 2021-06 (4.20.0)


A similar question was asked here, with no answer yet and less of a code sample. I found and tried the deletion solution for a similar problem, but to no avail.

After recently upgrading Eclipse to version 2021-06 (4.20.0), I noticed the content assist feature (ctrl-space) not working properly in many instances.

import java.util.HashSet;
import java.util.Set;

public class ContentAssist {

    public static void main(final String[] args) {
        final Set<String> storedSet = new HashSet<String>();
        for (int i = 0; i < 500; i++) {

            System.out.println(i);
        }
    }
}

If we now would like to access the storedSet, beginning by typing 's' we see that the out shows up as a compile error:

compilation error

Content Assist comes up short:

Content Assist fail 1

Also when providing more characters:

Content Assist fail 2

Comment out the System.out part and Content Assist once again works:

Content Assist works

Bug in or in front of the PC?

Edit: I just tested this for a fresh install of Eclipse 2021-06 (4.20.0) Build id 20210612-2011 on Windows x86_64, using Eclipse Installer 2021-06 R. Created a new Java project with the code above and the same behaviour occurred.


Solution

  • Unfortunately, that is indeed an issue of Eclipse 2021-06 (4.20) that has already been fixed in Eclipse 2021-09 (4.21) (released on September 15, 2021):

    Eclipse bug 574338 - [content assist] [regression] no content assist for variables in conditional blocks

    Please note, there is a similar bug that has not yet been fixed. As workaround you can add a ; after the location where to use the content assist.