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

Bug 331100

Summary: ArrayIndexOutOfBoundsException on TableItem.fontHandle
Product: [Eclipse Project] Platform Reporter: Willem Duminy <willem.duminy>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: craighewetson, eclipse.felipe
Version: 4.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard: stalebug

Description Willem Duminy CLA 2010-11-25 04:45:28 EST
Build Identifier: M20090917-0800

Here is the stack trace.
java.lang.ArrayIndexOutOfBoundsException: -1
	at org.eclipse.swt.widgets.TableItem.fontHandle(TableItem.java:151)
	at org.eclipse.swt.widgets.Table.wmNotifyToolTip(Table.java:6801)
	at org.eclipse.swt.widgets.Table.wmNotify(Table.java:6268)
	at org.eclipse.swt.widgets.Control.WM_NOTIFY(Control.java:4507)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4000)
	at org.eclipse.swt.widgets.Table.windowProc(Table.java:5521)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4589)
	at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)
	at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:2313)
	at org.eclipse.swt.widgets.Table.callWindowProc(Table.java:334)
	at org.eclipse.swt.widgets.Table.callWindowProc(Table.java:200)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4036)
	at org.eclipse.swt.widgets.Table.windowProc(Table.java:5521)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4602)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2410)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3471)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at com.vastech.ngmc.zeus.core.Application.start(Application.java:46)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	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.equinox.launcher.Main.invokeFramework(Main.java:559)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
	at org.eclipse.equinox.launcher.WebStartMain.basicRun(WebStartMain.java:79)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
	at org.eclipse.equinox.launcher.WebStartMain.main(WebStartMain.java:57)
	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.sun.javaws.Launcher.executeApplication(Unknown Source)
	at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
	at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
	at com.sun.javaws.Launcher.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)



Reproducible: Sometimes

Steps to Reproduce:
Cannot reproduce consistently ... seems to be related to tooltips.
Comment 1 Willem Duminy CLA 2010-12-09 01:01:58 EST
I get this error too often.

Look at the code in 
"org.eclipse.swt.widgets.Table.wmNotifyToolTip"  

It seems that the windows call OS.LVM_SUBITEMHITTEST sometimes places a -1 in "iSubItem" which is used to determine the font.  If the logic changes to accept tha a -1 in this field is possible, things should be fine.

i.e code at line 151 now reads
---
int /*long*/ hFont = item.fontHandle (pinfo.iSubItem);
if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
---

Maybe it should be changed to:
---
int /*long*/ hFont = -1
if (pinfo.iSubItem != -1) hFont = item.fontHandle (pinfo.iSubItem);
if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
---
Comment 2 Felipe Heidrich CLA 2010-12-13 13:04:33 EST
(In reply to comment #1)
> Maybe it should be changed to:
> ---
> int /*long*/ hFont = -1
> if (pinfo.iSubItem != -1) hFont = item.fontHandle (pinfo.iSubItem);
> if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
> ---

First I'd like to know why is the OS returning -1 in pinfo.iSubItem ?
Is the value in pinfo.iItem correct  ? What it is ?
Is there other invalid values happening for pinfo.iSubItem. (i.e -4) ?

Note that your fix is not complete, pinfo.iSubItem is used in other places in the same method and it would cause problems elsewhere. The best fix is probably to return without doing any work when pinfo.iSubItem==-1, but first we should try to know why it this is happening.
Comment 3 Craig CLA 2010-12-15 03:17:04 EST
Can't we use the proposed patch and therefore solve effects of this bug and then create a new case that will address the deeper cause of the problem?
Comment 4 Felipe Heidrich CLA 2010-12-15 11:42:09 EST
(In reply to comment #3)
> Can't we use the proposed patch and therefore solve effects of this bug and
> then create a new case that will address the deeper cause of the problem?

Rather not, I still don't understand why the problem happens and I'm not sure the patch is correct. I think it is premature to release any code at this point.

Unfortunately the problem doesn't happen to me (I tried), so it is hard for me work on this problem. Can you guys add this code in and self host eclipse for debugging:

Table#wmNotifyToolTip line 7102.
TableItem item = _getItem (pinfo.iItem);
if (pinfo.iSubItem != -1) {
	System.out.println(pinfo.iItem + " columnCount="+getColumnCount() + " itemCount="+getItemCount() + "  style="+getStyle());
	System.out.println("pt " + pt.x + ", " + pt.y);
	for (int i = 0; i < getColumnCount(); i++) {
		System.out.println(i +"="+item.getBounds(i));
	}
} 
int /*long*/ hDC = OS.GetDC (handle);


Here is the snippet I was trying with:
public static void main2(String[] args) {
	Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setLayout(new FillLayout());
	Table table = new Table (shell, SWT.NONE);
	TableItem item = new TableItem(table, SWT.FULL_SELECTION);
	TableColumn c = new TableColumn(table, 0);
	c.setWidth(100);
	c = new TableColumn(table, 0);
	c.setWidth(100);
	item.setText("Item longer text for native tooltip");
	item.setText(1, "the other column with long text");
	table.setHeaderVisible(true);
	table.addListener(SWT.PaintItem, new Listener() {
		public void handleEvent(Event event) {
		}
	});
	table.addListener(SWT.MeasureItem, new Listener() {
		public void handleEvent(Event event) {
		}
	});
	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}

Never saw isubItem==-1
Comment 5 Eclipse Webmaster CLA 2019-09-06 15:36:00 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 6 Eclipse Genie CLA 2021-08-28 11:18:19 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.