Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 427882

Summary: [Cocoa]StyledText: IME-related "Argument not valid" error handling keyDown
Product: [Eclipse Project] Platform Reporter: Thomas Singer <eclipse>
Component: SWTAssignee: Alexandr Miloslavskiy <alexandr.miloslavskiy>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: alexandr.miloslavskiy, karsten.thoms, loskutov, niraj.modi, ts-swt
Version: 4.3Keywords: triaged
Target Milestone: 4.18 M3   
Hardware: PC   
OS: All   
See Also: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/170823
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=2a9595e067812151c4c2b3df2bbcba7c10ddf3ae
Whiteboard:
Attachments:
Description Flags
Repro snippet
none
Repro snippet
none
Native repro snippet none

Description Thomas Singer CLA 2014-02-11 06:17:28 EST
A customer gets following exception:

java.lang.IllegalArgumentException: Argument not valid
	at org.eclipse.swt.SWT.error(SWT.java:4378)
	at org.eclipse.swt.SWT.error(SWT.java:4312)
	at org.eclipse.swt.SWT.error(SWT.java:4283)
	at org.eclipse.swt.custom.DefaultContent.error(DefaultContent.java:670)
	at org.eclipse.swt.custom.DefaultContent.getLineAtOffset(DefaultContent.java:564)
	at org.eclipse.swt.custom.StyledText.getBoundsAtOffset(StyledText.java:3633)
	at org.eclipse.swt.custom.StyledText.showCaret(StyledText.java:10140)
	at org.eclipse.swt.custom.StyledText.handleCompositionChanged(StyledText.java:5818)
	at org.eclipse.swt.custom.StyledText$8.handleEvent(StyledText.java:5662)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4164)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1466)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1489)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1474)
	at org.eclipse.swt.widgets.IME.setMarkedText_selectedRange(IME.java:486)
	at org.eclipse.swt.widgets.Canvas.setMarkedText_selectedRange(Canvas.java:574)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5795)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
	at org.eclipse.swt.internal.cocoa.NSResponder.interpretKeyEvents(NSResponder.java:68)
	at org.eclipse.swt.widgets.Composite.keyDown(Composite.java:594)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5556)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:221)
	at org.eclipse.swt.widgets.Widget.windowSendEvent(Widget.java:2104)
	at org.eclipse.swt.widgets.Shell.windowSendEvent(Shell.java:2318)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5618)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Display.applicationSendEvent(Display.java:5055)
	at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5204)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
	at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(NSApplication.java:128)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3646)

Unfortunately, I have no further informations.
Comment 1 Niraj Modi CLA 2014-02-12 02:26:39 EST
Hi Thomas,
Seeing the stacktrace, exception is thrown from method DefaultContent.getLineAtOffset()
- As per Java doc of DefaultContent.getLineAtOffset(int lineIndex), this method throws IllegalArgumentException when lineIndex is out of range, which is the case here.

Any set of steps/Snippet that can be used to reproduce this issue would be needed ?

Also note, the stacktrace you shared is generated from cocoa code(MAC).
Comment 2 Thomas Singer CLA 2014-02-12 12:22:22 EST
(In reply to Niraj Modi from comment #1)
> Any set of steps/Snippet that can be used to reproduce this issue would be
> needed ?

Unfortunately, no.

> Also note, the stacktrace you shared is generated from cocoa code(MAC).

Yes, I forgot to change the OS X default (reported on Windows).
Comment 3 Thomas Singer CLA 2014-06-06 06:55:44 EDT
A similar exception was also reported on Windows 7 32-bit:

java.lang.IllegalArgumentException: Argument not valid
	at org.eclipse.swt.SWT.error(SWT.java:4378)
	at org.eclipse.swt.SWT.error(SWT.java:4312)
	at org.eclipse.swt.SWT.error(SWT.java:4283)
	at org.eclipse.swt.custom.DefaultContent.replaceTextRange(DefaultContent.java:768)
	at org.eclipse.swt.custom.StyledText.handleCompositionChanged(StyledText.java:5805)
	at org.eclipse.swt.custom.StyledText$8.handleEvent(StyledText.java:5662)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1057)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1081)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1066)
	at org.eclipse.swt.widgets.IME.WM_IME_COMPOSITION(IME.java:505)
	at org.eclipse.swt.widgets.Canvas.WM_IME_COMPOSITION(Canvas.java:367)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4637)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:340)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4977)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2549)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
	at com.syntevo.q.gui.QSwt.dispatchEvents(SourceFile:251)
	at com.syntevo.smartgit.SaApplicationStarter.openGui(SourceFile:294)
	at com.syntevo.smartgit.SaApplicationStarter.parse(SourceFile:187)
	at com.syntevo.sc.application.ScParsingApplicationStarter.start(SourceFile:62)
	at SmartGit.main(SourceFile:11)
	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 QBootLoader.main(SourceFile:114)
	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 com.exe4j.runtime.LauncherEngine.launch(Unknown Source)
	at com.exe4j.runtime.WinLauncher.main(Unknown Source)
Comment 4 Thomas Singer CLA 2014-07-07 07:55:51 EDT
Another similar error has been reported for SmartGit 6 on Windows 8:

java.lang.IllegalArgumentException
	at org.eclipse.swt.SWT.error(SWT.java:4378)
	at org.eclipse.swt.SWT.error(SWT.java:4312)
	at org.eclipse.swt.SWT.error(SWT.java:4283)
	at org.eclipse.swt.custom.DefaultContent.error(DefaultContent.java:670)
	at org.eclipse.swt.custom.DefaultContent.getLineAtOffset(DefaultContent.java:564)
	at org.eclipse.swt.custom.StyledText.getBoundsAtOffset(StyledText.java:3633)
	at org.eclipse.swt.custom.StyledText.showCaret(StyledText.java:10140)
	at org.eclipse.swt.custom.StyledText.handleCompositionChanged(StyledText.java:5818)
	at org.eclipse.swt.custom.StyledText$8.handleEvent(StyledText.java:5662)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1057)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1081)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1066)
	at org.eclipse.swt.widgets.IME.WM_IME_COMPOSITION(IME.java:505)
	at org.eclipse.swt.widgets.Canvas.WM_IME_COMPOSITION(Canvas.java:367)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4637)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:340)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4977)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2549)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
Comment 5 Thomas Singer CLA 2016-12-22 06:48:05 EST
We have 285 bug reports regarding this exception.
Comment 6 Andrey Loskutov CLA 2016-12-22 07:23:30 EST
(In reply to Thomas Singer from comment #5)
> We have 285 bug reports regarding this exception.

... and still no idea how it can be reproduced?
Comment 7 Thomas Singer CLA 2016-12-22 10:04:11 EST
Unfortunately, not steps how to reproduce - just the stacktraces.

Maybe you could add some early assertions?
Comment 8 Alexandr Miloslavskiy CLA 2019-11-11 10:11:13 EST
Created attachment 280593 [details]
Repro snippet
Comment 9 Alexandr Miloslavskiy CLA 2019-11-11 10:12:57 EST
According to quick debugging, this is the bug of macOS itself: it sends 'setMarkedText:selectedRange:' [1] with:

markedText = "modifi"
selectedRange.location = 8

Where 'selectedRange.location' is obviously outside the text.

The bug is also visible in macOS terminal: upon typing the final 'd' caret suddenly jumps 2 lines down. When another character is typed, caret returns.

[1] https://developer.apple.com/documentation/uikit/uitextinput/1614465-setmarkedtext?language=objc
Comment 10 Karsten Thoms CLA 2019-11-11 10:38:19 EST
(In reply to Alexandr Miloslavskiy from comment #8)
> Created attachment 280593 [details]
> Repro snippet

Could not reproduce with the instructions. Here is a short screencast. What am I missing?
https://share.getcloudapp.com/wbuex6N7
Comment 11 Alexandr Miloslavskiy CLA 2019-11-11 13:17:28 EST
From your screencast it looks like you didn't switch to keyboard layout. With every character typed you should see IME window with changing hieroglyph suggestions.
Comment 12 Karsten Thoms CLA 2019-11-11 19:01:59 EST
Thought that selecting this in the keyboard layout was enough. Never worked with Pinyin ;) However, still don't get IAEs. I would expect them in the console log.
https://share.getcloudapp.com/12uElWbg
Comment 13 Alexandr Miloslavskiy CLA 2019-11-12 05:24:53 EST
Did you enable "Use Halfwidth punctuation" in keyboard layout menu?
Comment 14 Karsten Thoms CLA 2019-11-12 05:44:01 EST
(In reply to Alexandr Miloslavskiy from comment #13)
> Did you enable "Use Halfwidth punctuation" in keyboard layout menu?

Yes. You mean the checkbox in the Mac keyboard layout setting dialog.
Comment 15 Alexandr Miloslavskiy CLA 2019-11-12 06:57:47 EST
Indeed there's something else required. The problem reproduces reliably for me and one other guy, but I can't reproduce it on 2 other machines.

For me the problem didn't reproduce at all until I enabled "Use Halfwidth punctuation", but I also did some other things in between, and now after disabling "Use Halfwidth punctuation" the problem still reproduces for me.

I'll try to figure what other step is required here.
Comment 16 Alexandr Miloslavskiy CLA 2019-11-12 12:25:55 EST
Created attachment 280610 [details]
Repro snippet

Improved repro scenario
Comment 17 Alexandr Miloslavskiy CLA 2019-11-12 12:27:04 EST
I think I found it. Please refer to improved snippet. This also explains what the macOS bug is...

The same problem occurs with words like 'glorified', 'amplified'.
Comment 18 Alexandr Miloslavskiy CLA 2019-11-12 12:30:34 EST
As a reminder, the same bug is visible when typing in default Terminal, especially with these steps:
1) Type 'xyz'
2) Set caret to beginning of string
3) Type 'modified'
4) Notice where caret is
Comment 19 Karsten Thoms CLA 2019-11-13 09:31:43 EST
Thanks, with the new snippet I can reproduce it.
Comment 20 Alexandr Miloslavskiy CLA 2019-11-14 12:20:30 EST
Created attachment 280648 [details]
Native repro snippet

Use this snippet with the same steps as described inside Java snippet.

This snippet shows that the same problem occurs in native (also see previous comments about Terminal).

Compile with:
clang -Wno-deprecated-declarations -framework Cocoa "SWT_427882_macOS_IME_IAE.m" -o "SWT_427882_macOS_IME_IAE" && "./SWT_427882_macOS_IME_IAE"
Comment 21 Alexandr Miloslavskiy CLA 2020-10-06 03:41:33 EDT
Still reproducible on macOS 10.15; test snippet from Comment 16 gives:

Exception in thread "main" java.lang.IllegalArgumentException: Argument not valid
	at org.eclipse.swt.SWT.error(SWT.java:4850)
	at org.eclipse.swt.SWT.error(SWT.java:4784)
	at org.eclipse.swt.SWT.error(SWT.java:4755)
	at org.eclipse.swt.custom.DefaultContent.error(DefaultContent.java:682)
	at org.eclipse.swt.custom.DefaultContent.getLineAtOffset(DefaultContent.java:575)
	at org.eclipse.swt.custom.StyledText.getBoundsAtOffset(StyledText.java:3673)
	at org.eclipse.swt.custom.StyledText.showCaret(StyledText.java:10786)
	at org.eclipse.swt.custom.StyledText.handleCompositionChanged(StyledText.java:5973)
	at org.eclipse.swt.custom.StyledText.lambda$installListeners$2(StyledText.java:5825)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4385)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1512)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1535)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1520)
	at org.eclipse.swt.widgets.IME.setMarkedText_selectedRange(IME.java:502)
	at org.eclipse.swt.widgets.Canvas.setMarkedText_selectedRange(Canvas.java:602)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:6422)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
	at org.eclipse.swt.internal.cocoa.NSResponder.interpretKeyEvents(NSResponder.java:59)
	at org.eclipse.swt.widgets.Composite.keyDown(Composite.java:606)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:6016)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:235)
	at org.eclipse.swt.widgets.Widget.windowSendEvent(Widget.java:2150)
	at org.eclipse.swt.widgets.Shell.windowSendEvent(Shell.java:2401)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:6136)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Display.applicationSendEvent(Display.java:5386)
	at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5522)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
	at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(NSApplication.java:117)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3786)
	at Bug427882_StyledText_IME_IllegalArgument.main(Bug427882_StyledText_IME_IllegalArgument.java:55)
Comment 22 Eclipse Genie CLA 2020-10-15 08:49:23 EDT
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/170823