# Wrapped java.lang.ArrayIndexOutOfBoundsException

**URL:** <https://forum.servoy.com/t/wrapped-java-lang-arrayindexoutofboundsexception/11233>\
**Category:** Classic Servoy\
**Created:** [October 2, 2009, 6:44am UTC](https://forum.servoy.com/t/wrapped-java-lang-arrayindexoutofboundsexception/11233 "2009-10-02T06:44:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [October 2, 2009, 6:44am UTC](https://forum.servoy.com/t/wrapped-java-lang-arrayindexoutofboundsexception/11233/1 "2009-10-02T06:44:22Z")

</div>

Sometimes I get an ArrayIndexOutOfBounds exception which outputs the quoted error in the java console

I’ve been looking at line 19 of this method, but there’s nothing around there which point to an array.  
Does anyone have a clue? The code is below as well…

Thnkx a lot!

> org.mozilla.javascript.WrappedException: Wrapped java.lang.ArrayIndexOutOfBoundsException: -1 (nav\_showNavTabs#19)  
> at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1828)  
> at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:199)  
> at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:347)  
> at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:65)  
> at org.mozilla.javascript.gen.c251.\_c0(nav\_showNavTabs:19)  
> at org.mozilla.javascript.gen.c251.call(nav\_showNavTabs)  
> at org.mozilla.javascript.optimizer.OptRuntime.callProp0(OptRuntime.java:111)  
> at org.mozilla.javascript.gen.c51.\_c0(nav\_callbackTree:127)  
> at org.mozilla.javascript.gen.c51.call(nav\_callbackTree)  
> at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:387)  
> at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3125)  
> at org.mozilla.javascript.gen.c51.call(nav\_callbackTree)  
> at com.servoy.j2db.scripting.ScriptEngine.executeFunction(ScriptEngine.java:37)  
> at com.servoy.j2db.plugins.ClientPluginAccessProvider$MethodExecutor.run(ClientPluginAccessProvider.java:23)  
> at com.servoy.j2db.plugins.ClientPluginAccessProvider.executeMethod(ClientPluginAccessProvider.java:38)  
> at com.servoy.extensions.beans.dbtreeview.FunctionDef.exec(FunctionDef.java:28)  
> at com.servoy.extensions.beans.dbtreeview.SwingDBTreeView.callMethod(SwingDBTreeView.java:850)  
> at com.servoy.extensions.beans.dbtreeview.SwingDBTreeView.valueChanged(SwingDBTreeView.java:829)  
> at javax.swing.JTree.fireValueChanged(Unknown Source)  
> at javax.swing.JTree$TreeSelectionRedirector.valueChanged(Unknown Source)  
> at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(Unknown Source)  
> at javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(Unknown Source)  
> at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(Unknown Source)  
> at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(Unknown Source)  
> at javax.swing.JTree.setSelectionPath(Unknown Source)  
> at javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(Unknown Source)  
> at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection(Unknown Source)  
> at javax.swing.plaf.basic.BasicTreeUI$Handler.mousePressed(Unknown Source)  
> at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)  
> at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)  
> at java.awt.Component.processMouseEvent(Unknown Source)  
> at javax.swing.JComponent.processMouseEvent(Unknown Source)  
> at java.awt.Component.processEvent(Unknown Source)  
> at java.awt.Container.processEvent(Unknown Source)  
> at java.awt.Component.dispatchEventImpl(Unknown Source)  
> at java.awt.Container.dispatchEventImpl(Unknown Source)  
> at java.awt.Component.dispatchEvent(Unknown Source)  
> at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)  
> at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)  
> at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)  
> at java.awt.Container.dispatchEventImpl(Unknown Source)  
> at java.awt.Window.dispatchEventImpl(Unknown Source)  
> at java.awt.Component.dispatchEvent(Unknown Source)  
> at java.awt.EventQueue.dispatchEvent(Unknown Source)  
> at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)  
> at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)  
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)  
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)  
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)  
> at java.awt.EventDispatchThread.run(Unknown Source)  
> Caused by: java.lang.ArrayIndexOutOfBoundsException: -1  
> at java.util.ArrayList.get(Unknown Source)  
> at com.servoy.j2db.dataui.SpecialTabPanel.Za(SpecialTabPanel.java:121)  
> at com.servoy.j2db.dataui.SpecialTabPanel.stateChanged(SpecialTabPanel.java:36)  
> at com.servoy.j2db.dataui.Zzd.setSelectedIndex(Zzd.java:3)  
> at com.servoy.j2db.dataui.Zzd.addTab(Zzd.java:89)  
> at com.servoy.j2db.dataui.SpecialTabPanel.addTab(SpecialTabPanel.java:198)  
> at com.servoy.j2db.dataui.SpecialTabPanel.js\_addTab(SpecialTabPanel.java:95)  
> at sun.reflect.GeneratedMethodAccessor190.invoke(Unknown Source)  
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)  
> at java.lang.reflect.Method.invoke(Unknown Source)  
> at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:179)  
> … 48 more

```auto
function nav_showNavTabs()
{
	var $program	= globals.nav_program; //current program the application is in
	var $treeId = globals.k_current_button_id; //current dbTreeView record id
	var $obj = globals.nav.menu[$treeId]; //get part of the object for this tree to get properties
	var $tabForm	= $program + '_dtl_tab'; //define tabform
	
	var $body = forms.nav_menu_body.elements.tp_Body;

	if($obj.tabsArr.length > 0 && forms[$tabForm]) //see if there's a tabArray in de object with length > 0
	{
		var $tabs = forms.nav_tabs.elements.tp_navTab; 
		globals.nav_reset_tab(true); //initialize the form on tp_navTab

		if($body.getTabFormNameAt(1) != $tabForm) //see if the current form on the bodytab is what it should be
		{
			globals.nav_bodyform = $tabForm; 
			$body.removeAllTabs();
			$body.addTab(forms[globals.nav_bodyform]);
			
			var $ds = databaseManager.convertToDataSet(globals.nav_cur_pk);
			forms[globals.nav_bodyform].controller.loadRecords($ds);
		}

		for ( var i = 0; i < $obj.tabsArr.length ; i++)
		{
			var $id = $obj.tabsArr[i];
			var $name = globals.nav.menu[$id].i18n_trans;
			$tabs.addTab(forms.Dummy, $id, $name, null, null, null, null, null,i+1);	
		}

		var $newIndex = $obj.lasttab;

		if($tabs.tabIndex != $newIndex) globals.nav.noTabCallback = 1;

		$tabs.tabIndex = $newIndex;
		globals.nav.tabindex = $newIndex //save for historyupdate
	}
	etc.etc.etc........

```

---

<div class="post-metadata">

**Author:** ![lvostinar](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/lvostinar/32/5248_2.png) [@lvostinar](https://forum.servoy.com/u/lvostinar)\
**Post date:** [October 2, 2009, 7:04am UTC](https://forum.servoy.com/t/wrapped-java-lang-arrayindexoutofboundsexception/11233/2 "2009-10-02T07:04:49Z")

</div>

It seems the java.lang.ArrayIndexOutOfBoundsException is in our code. It seems the faulty line is: var $ds = databaseManager.convertToDataSet(globals.nav\_cur\_pk); ? Do you know what value is passed there when it fails ?

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [October 2, 2009, 7:24am UTC](https://forum.servoy.com/t/wrapped-java-lang-arrayindexoutofboundsexception/11233/3 "2009-10-02T07:24:13Z")

</div>

> lvostinar:  
> Do you know what value is passed there when it fails ?

Nope… normally this should be a UUID. There’s only 4 places in our code on which this variable get’s set and all of them should set the UUID.

The nasty thing of this error is that it is not consistently reproducable. I will try clicking around and get the error occur.

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [October 2, 2009, 7:43am UTC](https://forum.servoy.com/t/wrapped-java-lang-arrayindexoutofboundsexception/11233/4 "2009-10-02T07:43:47Z")

</div>

I think I had a problem like that, too. Have you tried to pass that global in an array as in

```auto
var $ds = databaseManager.convertToDataSet([globals.nav_cur_pk]);

```

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [October 2, 2009, 9:38am UTC](https://forum.servoy.com/t/wrapped-java-lang-arrayindexoutofboundsexception/11233/5 "2009-10-02T09:38:34Z")

</div>

> patrick:  
> Have you tried to pass that global in an array

should this solve it or is it the cause?

Anyway, the ‘globals.nav\_cur\_pk’ is just a string.

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [October 2, 2009, 10:15am UTC](https://forum.servoy.com/t/wrapped-java-lang-arrayindexoutofboundsexception/11233/6 "2009-10-02T10:15:10Z")

</div>

Yes, I know. But convertToDataSet expects an array of IDs… Have you tried?

---

<div class="post-metadata">

**Author:** ![lvostinar](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/lvostinar/32/5248_2.png) [@lvostinar](https://forum.servoy.com/u/lvostinar)\
**Post date:** [October 2, 2009, 10:27am UTC](https://forum.servoy.com/t/wrapped-java-lang-arrayindexoutofboundsexception/11233/7 "2009-10-02T10:27:46Z")

</div>

> patrick:  
> Yes, I know. But convertToDataSet expects an array of IDs… Have you tried?

It can also receive a list of Strings so I think is not a wrong call; anyway definitely a good idea to try with array.

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [October 2, 2009, 11:16am UTC](https://forum.servoy.com/t/wrapped-java-lang-arrayindexoutofboundsexception/11233/8 "2009-10-02T11:16:19Z")

</div>

> lvostinar:  
> anyway definitely a good idea to try with array.

ok,thnkx Laurian & Patrick will try if this works…

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [October 12, 2009, 10:01am UTC](https://forum.servoy.com/t/wrapped-java-lang-arrayindexoutofboundsexception/11233/9 "2009-10-12T10:01:14Z")

</div>

convertToDataSet doesnt seem to be the problem  
It is something in the addTab() that goes wrong.

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [October 12, 2009, 11:04am UTC](https://forum.servoy.com/t/wrapped-java-lang-arrayindexoutofboundsexception/11233/10 "2009-10-12T11:04:13Z")

</div>

> jcompagner:  
> It is something in the addTab() that goes wrong.

That is correct, I can confirm that.  
Unfortunately it is just ‘.addTab(forms[$form])’, where $form is a string, with valid formname.

This only occurs when Servoy can’t keep up with the users navigation requests \> which will do various ‘addTab’ commands in a short time…  
Unfortunately I don’t have a stack trace or consistent way to reproduce this…
