Bug 169682 - In class that compiles and runs when ctrl+space is pressed I get "No completions available"
Summary: In class that compiles and runs when ctrl+space is pressed I get "No completi...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M1   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-05 08:48 EST by Yevgeny CLA
Modified: 2008-08-06 12:19 EDT (History)
3 users (show)

See Also:


Attachments
project to use in order to reproduce the problem (138.37 KB, application/x-zip-compressed)
2007-01-05 08:55 EST, Yevgeny CLA
no flags Details
Potential fix (1.09 KB, patch)
2008-05-19 06:36 EDT, David Audel CLA
no flags Details | Diff
Proposed fix (7.42 KB, patch)
2008-07-17 05:55 EDT, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yevgeny CLA 2007-01-05 08:48:40 EST
Build ID:  I20050627-1435

Steps To Reproduce:
Hi,

In order you could reproduce this problem iseally. It would be best if I could send you my project. 
In my project there is a class GUIClass. In this class it has different attributes and methods.
It has also :
ActionListener actionListener = new ActionListener() 
{
  public void actionPerformed(ActionEvent buttonPressed) 
  {
     .
     .
     .
  }
};

actionPerformed(...) method is very long and complicated and when I press in other class methods ctrl+space I get for some reason "No completions available".
If I write simple actionPerformed(...) method than everything is working fine.
It is important to mention that the project is compiling and running without any problem.
Comment 1 Yevgeny CLA 2007-01-05 08:55:50 EST
Created attachment 56452 [details]
project to use in order to reproduce the problem

Hi,

This is the project on which you can reproduce the problem. If you open in IDE(Eclipse) GUIClass.java file and tru in constructor to write, "this." and press "ctrl+shift" you'll see the problem. 
If you swap:
 ActionListener actionListener = new ActionListener() 
 {
    public void actionPerformed(ActionEvent buttonPressed) 
    {...}
 };

with other one, which has a small or empty actionPerformed(...) method you will see that this problem does not occure.
Comment 2 Dani Megert CLA 2007-04-24 08:48:11 EDT
Can reproduce using I20070418-1012.

>GUIClass.java file and tru in constructor to write, "this." and
>press "ctrl+shift" you'll see the problem. 
Simply open the constructor and try "this.<code assist>"
==> no results.
Comment 3 Phil CLA 2008-05-15 00:29:11 EDT
Hello,
I have the same problem, i try extending a class to ActionListener and when i do ctrl + space it gives me the same error.
The interesting thing is, it only happens in one project of my workspace. I tried to remove the project and add it without any project's configuration files and still it gives the same error. I tried to remove the entire workspace and remove the .metadata folder and import it back again.. same problem occurs. I even formatted by computer and same problem occurs. 
I tried both Eclipse 3.3.2 and Eclipse Ganymede 3.4M7 and same problem occurs.
I remember installing Java EE and tried to program with eclipse with it.. i think the problems started happening ever since. But if that was the problem.. i think formatting or even removing the Java EE from my computer would fix the problem.
I think some configuration file was changed and keeps giveing the same error over and over again.

There was another time that this error occured, i dont remember much details but it was solved when i changed to an empty workspace.
Comment 4 Dani Megert CLA 2008-05-15 02:57:04 EDT
Did you eventually have Mylyin/Mylar installed? If so, go and reset the advanced content assist prefs to its defaults.
Comment 5 Yevgeny CLA 2008-05-17 13:20:44 EDT
(In reply to comment #2)
> Can reproduce using I20070418-1012.
> 
> >GUIClass.java file and tru in constructor to write, "this." and
> >press "ctrl+shift" you'll see the problem. 
> Simply open the constructor and try "this.<code assist>"
> ==> no results.
> 

Hi,

Although for me this problem is not relevant as I am not working on mentioned project (please see attached file) anymore. It will be great if this issue could be solved so other eclipse users won't have such problem. This message was opened about 1.5 years ago. It would be great if you could at least add some resolution plan when this problem will be solved.

Best regards,
Yevgeny 
Comment 6 David Audel CLA 2008-05-19 05:42:56 EDT
The original problem is caused by a bug in the CompletionParser.
The test case to reproduce it must contain an anonymous class in a field initializer. The anonymous class must contain a lot of 'if/else' statements with a variable in the last 'else' body.

eg:

package p;

public class X 
{
	public X() 
	{
		this.// do ctrl+space here
	}
	
	Object field = new Object() 
	{
		public void foo() {

			if(true)
			{}
			else if(true)
			{}
			else if(true)
			{}
			...
			else if(true)
			{}
			else if(true)
			{}
			else if(true)
			{
				if(true)
				{
					if(true)
					{
						boolean result[][];
					}
				}
			}	
		}
	};	
}

This test case cause an exception. This exception is caught and the completion operation fail silently and display "No completions available".

java.lang.ArrayIndexOutOfBoundsException: 50
	at org.eclipse.jdt.internal.codeassist.complete.CompletionParser.consumeEnterVariable(CompletionParser.java:2224)
	at org.eclipse.jdt.internal.compiler.parser.Parser.consumeRule(Parser.java:5346)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:9270)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:9498)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:9455)
	at org.eclipse.jdt.internal.compiler.parser.Parser.dietParse(Parser.java:8102)
	at org.eclipse.jdt.internal.codeassist.complete.CompletionParser.dietParse(CompletionParser.java:4120)



In the Yevgeny's test case there is 36 'else if(...)' statements and the problem do not appear with 35 or 37 of these statements.

This bug is not a regression and exists since 2002. As we are late in 3.4 release cycle then a fix for this bug is too dangerous for 3.4. We should fix it in 3.5.

The problem described in comment 3 seems to be different.
Phil - Could you enter a separate bug report for you problem ?
Comment 7 David Audel CLA 2008-05-19 06:36:26 EDT
Created attachment 100882 [details]
Potential fix
Comment 8 David Audel CLA 2008-05-19 06:38:42 EDT
Another symptom of this bug:

1) create X.java
public class X
{
	#
	int[] i;
	Obj| x; // do ctrl+space at |
}

2) do ctrl+space at | location
There is no proposal.
Comment 9 Phil CLA 2008-05-19 13:38:47 EDT
The comment i posted is wrong, i was using extends instead of implements (thats what happens when we program at night) after i used implements it showed the ActionListener interface.
I do agree that the "No completions available" should give more details about what exactly the problem is.
Sorry for any incovenience.
Comment 10 David Audel CLA 2008-07-17 05:55:50 EDT
Created attachment 107713 [details]
Proposed fix
Comment 11 David Audel CLA 2008-07-17 05:57:54 EDT
Released for 3.5M1

Tests added
  CompletionTests#testBug169682a() -> testBug169682b()
Comment 12 Olivier Thomann CLA 2008-08-06 12:19:29 EDT
Verified for 3.5M1 using I20080805-1307