PDA

View Full Version : ArrayIndexOutOfBoundsException: -1 with wrong AutoExpandColumn



Arno.Nyhm
27 Aug 2009, 6:21 AM
it would be nice if the autoexpandcolumn would be ignored or a good error message would appear if the autoexpandcolumn not match exactly the column id

if you have a indexoutofbounds exeption in some isHidden function then it is difficult to find out why.




// GridView.java
protected void autoExpand(boolean preventUpdate) {
if (!userResized && grid.getAutoExpandColumn() != null) {
int tw = cm.getTotalWidth(false);
int aw = grid.getWidth(true) - getScrollAdjust();
if (tw != aw) {
int ci = cm.getIndexById(grid.getAutoExpandColumn()); // <-- this returns -1 if the column is not found
if (cm.isHidden(ci)) { // <----- here it try to find if tis hidden cm.isHidden(-1)
return;
}


// ColumnModel.java
public boolean isHidden(int colIndex) {
return configs.get(colIndex).isHidden(); // <----- and here i get a index out of bound exception
}

to reproduce add this to any grid example:


grid.setAutoExpandColumn("unknowncolumnname");
[ERROR] Unable to load module entry point class org.yournamehere.client.MainEntryPoint (see associated exception for details)
java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.get(ArrayList.java:324)
at com.extjs.gxt.ui.client.widget.grid.ColumnModel.isHidden(ColumnModel.java:379)
at com.extjs.gxt.ui.client.widget.grid.GridView.autoExpand(GridView.java:680)
at com.extjs.gxt.ui.client.widget.grid.GridView.layout(GridView.java:502)
at com.extjs.gxt.ui.client.widget.grid.Grid.onResize(Grid.java:720)
at com.extjs.gxt.ui.client.widget.BoxComponent.setSize(BoxComponent.java:563)
at com.extjs.gxt.ui.client.widget.BoxComponent.afterRender(BoxComponent.java:635)
at com.extjs.gxt.ui.client.widget.grid.Grid.afterRender(Grid.java:611)
at com.extjs.gxt.ui.client.widget.Component.render(Component.java:961)
at com.extjs.gxt.ui.client.widget.Layout.renderComponent(Layout.java:258)
at com.extjs.gxt.ui.client.widget.Layout.renderAll(Layout.java:249)
at com.extjs.gxt.ui.client.widget.Layout.onLayout(Layout.java:230)
at com.extjs.gxt.ui.client.widget.layout.FitLayout.onLayout(FitLayout.java:58)
at com.extjs.gxt.ui.client.widget.Layout.layout(Layout.java:96)
at com.extjs.gxt.ui.client.widget.Layout$2.handleEvent(Layout.java:59)
at com.extjs.gxt.ui.client.util.DelayedTask$1.run(DelayedTask.java:30)
at com.extjs.gxt.ui.client.util.DelayedTask.delay(DelayedTask.java:52)
at com.extjs.gxt.ui.client.widget.Layout.onResize(Layout.java:240)
at com.extjs.gxt.ui.client.widget.Layout$1.handleEvent(Layout.java:52)
at com.extjs.gxt.ui.client.widget.Layout$1.handleEvent(Layout.java:1)
at com.extjs.gxt.ui.client.event.BaseObservable.callListener(BaseObservable.java:176)
at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:96)
at com.extjs.gxt.ui.client.widget.Component.fireEvent(Component.java:444)
at com.extjs.gxt.ui.client.widget.BoxComponent.setSize(BoxComponent.java:572)
at com.extjs.gxt.ui.client.widget.BoxComponent.afterRender(BoxComponent.java:635)
at com.extjs.gxt.ui.client.widget.ScrollContainer.afterRender(ScrollContainer.java:194)
at com.extjs.gxt.ui.client.widget.Component.render(Component.java:961)
at com.extjs.gxt.ui.client.widget.Layout.renderComponent(Layout.java:258)
at com.extjs.gxt.ui.client.widget.Layout.renderAll(Layout.java:249)
at com.extjs.gxt.ui.client.widget.Layout.onLayout(Layout.java:230)
at com.extjs.gxt.ui.client.widget.layout.RowLayout.onLayout(RowLayout.java:225)
at com.extjs.gxt.ui.client.widget.layout.FillLayout.onLayout(FillLayout.java:80)
at com.extjs.gxt.ui.client.widget.Layout.layout(Layout.java:96)
at com.extjs.gxt.ui.client.widget.Container.doLayout(Container.java:348)
at com.extjs.gxt.ui.client.widget.Container.layout(Container.java:444)
at com.extjs.gxt.ui.client.widget.LayoutContainer.layout(LayoutContainer.java:241)
at com.extjs.gxt.ui.client.widget.Container.doLayout(Container.java:364)
at com.extjs.gxt.ui.client.widget.Container.layout(Container.java:444)
at com.extjs.gxt.ui.client.widget.LayoutContainer.layout(LayoutContainer.java:241)
at com.extjs.gxt.ui.client.widget.Container.layout(Container.java:427)
at com.extjs.gxt.ui.client.widget.LayoutContainer.layout(LayoutContainer.java:236)
at com.extjs.gxt.ui.client.widget.Window.layout(Window.java:488)
at com.extjs.gxt.ui.client.widget.Window.afterShow(Window.java:816)
at com.extjs.gxt.ui.client.widget.Window.show(Window.java:791)
at org.yournamehere.client.MainEntryPoint.onModuleLoad(MainEntryPoint.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:326)
at com.google.gwt.dev.shell.BrowserWidget.attachModuleSpace(BrowserWidget.java:343)
at com.google.gwt.dev.shell.ie.BrowserWidgetIE6.access$300(BrowserWidgetIE6.java:37)
at com.google.gwt.dev.shell.ie.BrowserWidgetIE6$External.gwtOnLoad(BrowserWidgetIE6.java:77)
at com.google.gwt.dev.shell.ie.BrowserWidgetIE6$External.invoke(BrowserWidgetIE6.java:161)
at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294)
at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194)
at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:235)
at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:558)
at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)

Arno.Nyhm
27 Aug 2009, 6:30 AM
add this exception:


if (ci == -1) throw new RuntimeException("AutoExpandColumn '" + grid.getAutoExpandColumn() + "' not found in ColumnModel");or check the id:


if (ci == -1 || cm.isHidden(ci)) {
return;
}

sven
27 Aug 2009, 6:32 AM
Throwing an exception is a bad idea. This would be compiled down to javascript and would increase the filesize, which is uneeded.

Arno.Nyhm
27 Aug 2009, 8:20 AM
but throwing an ArrayIndexOutOfBoundsException is also not a good solution. so ignoring this autoexpand with "if (ci == -1 || cm.isHidden(ci)) {" is then the best solution... or not?

fother
27 Aug 2009, 9:05 AM
work as intend..

javadoc: The id of a column in this grid that should expand to fill unused space (pre-render). This id can not be 0.

if the id dont exist.. return an ArrayIndexOutOfBoundsException :)

Arno.Nyhm
27 Aug 2009, 9:57 AM
if you are new to grids and you make you first grid and you have this mistake in spelling then you spend hours of debugging just to find out its a spelling bug in this line...

so a better hint would be nice in this place.

would you realy guess from the stacktrace that this error comes from the missing autoexpandcolumn?

fother
28 Aug 2009, 3:51 AM
I agree if you because I pass for the same problem kkkk

if use assert?

Arno.Nyhm
28 Aug 2009, 11:08 AM
assert is also possible.

any message is welcome ;-)

sven
28 Aug 2009, 11:16 AM
An assert is the only way to go and i added it.

fother
28 Aug 2009, 11:51 AM
when java its compiled to javascript.. the assert "go to"?

sven
28 Aug 2009, 11:52 AM
Yes, they will be removed. The compiler has a flag to maintain them.