Bug 90414 - [content assist] Content Assist fails when escape sequence present
Summary: [content assist] Content Assist fails when escape sequence present
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.1 M7   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 91780 93877 96448 101804 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-04-06 05:03 EDT by andrew CLA
Modified: 2005-06-27 22:32 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description andrew CLA 2005-04-06 05:03:20 EDT
Content assist fails when there is a string token beginning with an
escape sequence *below* the content assist point.

Given the following class:

class Test {
  void foo() {
    // content assist here fails
  }

  String X = "\n";

  void bar() {
    // content assist here succeeds
  }
}

When triggering content assist inside foo() with Ctrl+Space, Eclipse displays
the "Error Executing Command" popup ("The command for the key you pressed
failed"). The stack trace from .log is shown at the end of this report. Doing
the same inside bar() produces the expected selection box. 

Note that:
 - Moving the declaration of X above foo() in the file makes it succeed in both
   places.
 - Moving the declaration of X below bar() in the file makes it fail in both
   places.
 - Adding more escape sequences to X (e.g. "\n\n") makes it succeed regardless
   of location.
 - Changing the first character of X to something other than an escape sequence
   (e.g. "x\n") makes it succeed regardless of location.
 - Adding more characters after the escape sequence (other than more escapes,
   e.g. "\nabc") has no effect.
 - Changing the context in which the string token is used (e.g. Integer X =
   Integer.parseInt("\n");) has no effect.
 - Changing the scope of X such that foo() can't see it (e.g. putting it inside
   a static block, or inside bar()) makes it succeed regardless of location.

Platform(s):
 - Eclipse 3.1M6
 - Java 1.4.2_03-b02
 - Windows XP Pro SP2 and Solaris 8 (Motif)

I checked the same case in 3.1M5a on both platforms, and neither produced this
behaviour.

Stack Trace from .log:
!ENTRY org.eclipse.ui 4 4 2005-04-06 18:39:52.968
!MESSAGE The command for the key you pressed failed

!ENTRY org.eclipse.ui 4 0 2005-04-06 18:39:52.968
!MESSAGE The command for the key you pressed failed
!STACK 0
java.lang.NegativeArraySizeException
	at
org.eclipse.jdt.internal.compiler.parser.Scanner.getCurrentTokenSourceString(Scanner.java:501)
	at org.eclipse.jdt.internal.compiler.parser.Parser.consumeToken(Parser.java:6793)
	at
org.eclipse.jdt.internal.codeassist.impl.AssistParser.consumeToken(AssistParser.java:666)
	at
org.eclipse.jdt.internal.codeassist.complete.CompletionParser.consumeToken(CompletionParser.java:2235)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:8377)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:8560)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:8525)
	at org.eclipse.jdt.internal.compiler.parser.Parser.dietParse(Parser.java:7343)
	at
org.eclipse.jdt.internal.codeassist.complete.CompletionParser.dietParse(CompletionParser.java:2905)
	at
org.eclipse.jdt.internal.codeassist.CompletionEngine.complete(CompletionEngine.java:1057)
	at org.eclipse.jdt.internal.core.Openable.codeComplete(Openable.java:119)
	at
org.eclipse.jdt.internal.core.CompilationUnit.codeComplete(CompilationUnit.java:300)
	at
org.eclipse.jdt.internal.core.CompilationUnit.codeComplete(CompilationUnit.java:293)
	at
org.eclipse.jdt.internal.ui.text.java.JavaCompletionProcessor.internalComputeCompletionProposals(JavaCompletionProcessor.java:335)
	at
org.eclipse.jdt.internal.ui.text.java.JavaCompletionProcessor.computeCompletionProposals(JavaCompletionProcessor.java:313)
	at
org.eclipse.jface.text.contentassist.ContentAssistant.computeCompletionProposals(ContentAssistant.java:1470)
	at
org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals(CompletionProposalPopup.java:250)
	at
org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$7(CompletionProposalPopup.java:247)
	at
org.eclipse.jface.text.contentassist.CompletionProposalPopup$1.run(CompletionProposalPopup.java:206)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
	at
org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals(CompletionProposalPopup.java:201)
	at
org.eclipse.jface.text.contentassist.ContentAssistant.showPossibleCompletions(ContentAssistant.java:1319)
	at
org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer.doOperation(CompilationUnitEditor.java:183)
	at org.eclipse.ui.texteditor.ContentAssistAction$1.run(ContentAssistAction.java:82)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
	at org.eclipse.ui.texteditor.ContentAssistAction.run(ContentAssistAction.java:80)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:996)
	at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:182)
	at
org.eclipse.ui.internal.handlers.LegacyHandlerWrapper.execute(LegacyHandlerWrapper.java:108)
	at org.eclipse.core.commands.Command.execute(Command.java:331)
	at
org.eclipse.core.commands.ParameterizedCommand.execute(ParameterizedCommand.java:396)
	at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:452)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:741)
	at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:784)
	at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:543)
	at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:486)
	at
org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:110)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:777)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:841)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:866)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:851)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:879)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:875)
	at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1182)
	at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:3126)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:3029)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:3466)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1625)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2525)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1570)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1534)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:306)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143)
	at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:103)
	at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:228)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:156)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.core.launcher.Main.invokeFramework(Main.java:315)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:268)
	at org.eclipse.core.launcher.Main.run(Main.java:942)
	at org.eclipse.core.launcher.Main.main(Main.java:926)
Comment 1 Olivier Thomann CLA 2005-04-06 08:36:47 EDT
Seems to be a bug in the scanner.
I will investigate.
Comment 2 Olivier Thomann CLA 2005-04-06 11:56:59 EDT
The problem comes from the handling of escape characters in string literal.
Comment 3 Olivier Thomann CLA 2005-04-12 22:54:16 EDT
*** Bug 91221 has been marked as a duplicate of this bug. ***
Comment 4 Olivier Thomann CLA 2005-04-14 15:00:42 EDT
With the fix for bug 91221, it will look like it works, but the escape handling
is boggus as soon as it is using unicodes. Without unicode it should work.
The current support is using the unicode support even if there is no unicode.
This is boggus and needs to be fixed.
Comment 5 Olivier Thomann CLA 2005-04-14 15:03:14 EDT
The boggus part is escape characters inside string literal.
Comment 6 Olivier Thomann CLA 2005-04-14 15:28:38 EDT
For example, the following code doesn't produce the expected result:

public class Test {
  static String C = "\u005Cn";
  
  public static void main(String[] args) {
  	System.out.print(C.length());
  	System.out.println(C.charAt(0) == '\n');
  } 	
}

It returns:
1false

instead of:
1true
Comment 7 Olivier Thomann CLA 2005-04-15 09:49:06 EDT
Fixed and released in HEAD.
Regression tests added in ScannerTest.test027-035.
Comment 8 David Audel CLA 2005-04-19 06:39:01 EDT
*** Bug 91780 has been marked as a duplicate of this bug. ***
Comment 9 David Audel CLA 2005-05-06 07:50:25 EDT
*** Bug 93877 has been marked as a duplicate of this bug. ***
Comment 10 Maxime Daniel CLA 2005-05-13 06:47:29 EDT
Verified for 3.1 M7 using build I20050512-2035 + jdt.core HEAD.
Comment 11 Olivier Thomann CLA 2005-05-24 14:46:54 EDT
*** Bug 96448 has been marked as a duplicate of this bug. ***
Comment 12 Danny Stevens CLA 2005-06-27 22:32:53 EDT
*** Bug 101804 has been marked as a duplicate of this bug. ***