# Maximum recursion depth exceeded (Java StackOverflowError)

**URL:** <https://forum.inductiveautomation.com/t/maximum-recursion-depth-exceeded-java-stackoverflowerror/79473>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [September 21, 2023, 7:20pm UTC](https://forum.inductiveautomation.com/t/maximum-recursion-depth-exceeded-java-stackoverflowerror/79473 "2023-09-21T19:20:42Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason.myers](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jason.myers](https://forum.inductiveautomation.com/u/jason.myers)\
**Post date:** [September 21, 2023, 7:20pm UTC](https://forum.inductiveautomation.com/t/maximum-recursion-depth-exceeded-java-stackoverflowerror/79473/1 "2023-09-21T19:20:42Z")

</div>

I'm using version 18.1.18. I have a table on a view which calls the onEditCellCommit and onSelectionChange component events. I am running the exact same script on both. It works perfectly on onEditCellCommit, but I get "maximum recursion depth exceeded (Java StackOverflowError)" error on line 3 when called by onSelectionChange. Here is the script:

```auto
def runAction(self, event):
	try:
		v_row = event['row']
		v_col = event['column']
		v_val = event['value'] 
		v_id = self.props.data[v_row].ID

		Resource_Limits.setDB(v_row, v_col, v_val, v_id)
	   
		self.refreshBinding("props.data")
	
	except Exception as e:
		Log.set_error(str(e), 'Resource Limits Table onSelectionChange')

```

I'm not sure what would cause it to run perfectly on one event and error on another.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 21, 2023, 7:28pm UTC](https://forum.inductiveautomation.com/t/maximum-recursion-depth-exceeded-java-stackoverflowerror/79473/2 "2023-09-21T19:28:16Z")

</div>

Because refreshing the table's data causes the selected data to be recomputed from the new table, causing onSelectionChange to happen again. Boom, infinite recursion.

---

<div class="post-metadata">

**Author:** ![jason.myers](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jason.myers](https://forum.inductiveautomation.com/u/jason.myers)\
**Post date:** [September 21, 2023, 7:39pm UTC](https://forum.inductiveautomation.com/t/maximum-recursion-depth-exceeded-java-stackoverflowerror/79473/3 "2023-09-21T19:39:10Z")

</div>

Commenting out self.refreshBinding("props.data") yeilds the same result. In fact, if I comment out everything except my try and line 3 I get the same result:

```auto
def runAction(self, event):
	try:
		v_row = event['row']
		'''v_col = event['column']
		v_val = event['value'] 
		v_id = self.props.data[v_row].ID

		Resource_Limits.setDB(v_row, v_col, v_val, v_id)
	   
		#self.refreshBinding("props.data")'''
	
	except Exception as e:
		Log.set_error(str(e), 'Resource Limits Table onSelectionChange')

```

---

<div class="post-metadata">

**Author:** ![jason.myers](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jason.myers](https://forum.inductiveautomation.com/u/jason.myers)\
**Post date:** [September 21, 2023, 7:42pm UTC](https://forum.inductiveautomation.com/t/maximum-recursion-depth-exceeded-java-stackoverflowerror/79473/4 "2023-09-21T19:42:56Z")

</div>

Just tested it; even getting rid of the exception handling does it. And commenting out line 3 moves the error to line 4: v\_col = event['column']

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 21, 2023, 7:49pm UTC](https://forum.inductiveautomation.com/t/maximum-recursion-depth-exceeded-java-stackoverflowerror/79473/5 "2023-09-21T19:49:42Z")

</div>

Why are you using subscript notation with your `event` variable? You should be using the documented attributes `event.selectedRow`, `event.selectedColumn`, and/or `event.data`.

[https://docs.inductiveautomation.com/display/DOC81/Perspective+-+Table+Scripting#PerspectiveTableScripting-onSelectionChange](https://docs.inductiveautomation.com/display/DOC81/Perspective+-+Table+Scripting#PerspectiveTableScripting-onSelectionChange)

That the misuse of subscript notation in this case produces infinite recursion is a bug worth reporting, though.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 21, 2023, 8:52pm UTC](https://forum.inductiveautomation.com/t/maximum-recursion-depth-exceeded-java-stackoverflowerror/79473/6 "2023-09-21T20:52:33Z")

</div>

I don't understand how it's not doing anything besides throwing KeyError. I certainly can't get it to do anything as bad as a stackoverflow.

---

<div class="post-metadata">

**Author:** ![jason.myers](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jason.myers](https://forum.inductiveautomation.com/u/jason.myers)\
**Post date:** [September 21, 2023, 8:55pm UTC](https://forum.inductiveautomation.com/t/maximum-recursion-depth-exceeded-java-stackoverflowerror/79473/7 "2023-09-21T20:55:13Z")

</div>

Because that's what ChatGPT told me to do. LOL Anyways, I can try those out.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 21, 2023, 8:57pm UTC](https://forum.inductiveautomation.com/t/maximum-recursion-depth-exceeded-java-stackoverflowerror/79473/8 "2023-09-21T20:57:04Z")

</div>

> [@jason.myers](#):
>
> what ChatGPT told me

Sigh. Just say **no** to ChatGPT.

---

<div class="post-metadata">

**Author:** ![jason.myers](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jason.myers](https://forum.inductiveautomation.com/u/jason.myers)\
**Post date:** [September 21, 2023, 8:57pm UTC](https://forum.inductiveautomation.com/t/maximum-recursion-depth-exceeded-java-stackoverflowerror/79473/9 "2023-09-21T20:57:31Z")

</div>

I'm a special case, PGriffith, a special case. I saw this case where you said it was a bug, but I figured it was handled since it was so old [Tag.configure max recursion depth exceeded](https://forum.inductiveautomation.com/t/tag-configure-max-recursion-depth-exceeded/54090) The weird thing is it works fine in onEditCellCommit

---

<div class="post-metadata">

**Author:** ![jason.myers](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jason.myers](https://forum.inductiveautomation.com/u/jason.myers)\
**Post date:** [September 21, 2023, 9:01pm UTC](https://forum.inductiveautomation.com/t/maximum-recursion-depth-exceeded-java-stackoverflowerror/79473/10 "2023-09-21T21:01:31Z")

</div>

I'm trying to get on the good side of our new electronic overlords.

---

<div class="post-metadata">

**Author:** ![jason.myers](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jason.myers](https://forum.inductiveautomation.com/u/jason.myers)\
**Post date:** [September 21, 2023, 9:41pm UTC](https://forum.inductiveautomation.com/t/maximum-recursion-depth-exceeded-java-stackoverflowerror/79473/11 "2023-09-21T21:41:30Z")

</div>

Ok, using event.selectedRow, event.selectedColumn doesn't cause an error, but I don't see how to get what I changed the cell value to. The event.data is the data before the edit. It kinda makes sense because my selected cell is now a different cell. Is there a way for me to commit the edit when a user selects a different cell. Can I fire the onEditCellCommit somehow?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [October 1, 2023, 4:00am UTC](https://forum.inductiveautomation.com/t/maximum-recursion-depth-exceeded-java-stackoverflowerror/79473/12 "2023-10-01T04:00:48Z")

</div>

So the real problem we are trying to solve is that when an edit is made, and a different cell is clicked on without first pressing the enter key, the cell edit is lost.

I found another thread in the forum about this problem, and this solution seems viable:

> [@Perspective table Commit Edit on loss of Focus](https://forum.inductiveautomation.com/t/perspective-table-commit-edit-on-loss-of-focus/31790/8):
>
> I was able to get this functionality by making a view that was just a text field, then making a column render that view, and then binding the text to the passed value. From there you can commit whatever you need to as a change script on the text or use system.perspective.sendMessage() to send the value back to the parent view. It took some time to get right but ends up working rather well.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [October 1, 2023, 4:44am UTC](https://forum.inductiveautomation.com/t/maximum-recursion-depth-exceeded-java-stackoverflowerror/79473/13 "2023-10-01T04:44:17Z")

</div>

Messing around with this problem, I don't see any way to gain this functionality from the selection change event that you were originally trying to use.

However, I was able to gain this functionality by adding a custom property to the table called `editString`. Then, using the onEditCellStart event, I could clear the value from the editString prop using `self.props.editString = ''`. I could then keep track of what was typed using the `onKeyPress` event and the following code:

```auto
key = event.key
startingString = self.props.editString
self.props.editString = startingString + key

```

To make the editString commit when another cell was selected, I ran the normal onEditCellCommit script from the onEditCellCancel event using the custom editString property for the value instead of the event's value.

Unfortunately, this approach only works if the entry is completely new because if a small edit is made to the existing text, all that gets saved when another cell is selected is the text typed during the small edit. Therefore, to ensure that the entire string doesn't get replaced by a partial entry, you would need to clear the text at the beginning of the edit. Sadly, the table doesn't have a clear text on entry option, so to get this functionality, you would have to render a view with a text field that is configured to do this.

...and if you're rendering a text field view in the column, you should probably just follow through with the change script message suggested in the previous post.
