How do I prevent an error (java.lang.StackOverflowError: null) when a FileDocument specialation event handler calls a microflow and tries to pass the object when a file hasnt been uploaded?

How do I prevent an error (java.lang.StackOverflowError: null) when a FileDocument specialation event handler calls a microflow and tries to pass the object when a file hasn't been uploaded? Entity AttachmentAuditImage is a specialization of FileDocument.  It has two event handlers that trigger a microflow that does some stuff (what it does isn’t important) after a commit and after a delete and the event handlers pass a reference to the object.  The “Save & ___” buttons on the popup have the default Save action.  I get the StackOverflowError when I click either “Save & ___” button when I haven’t uploaded a document.  The microflow that’s supposed to be triggered by the handler doesn’t even get called (I checked) never makes it that far or if it does it errors before the first action which is basically a “hello world” show message action to tell me the flow got executed. Here’s the interesting thing….if I delete the event handlers I don’t get the error.  If I change “Save & ___” buttons action to call a microflow that commits the AttachmentAuditImage entity there are no errors.  This means that I’ve narrowed it down to a problem with the platform that tries to pass a reference to the AttachmentAuditImage object from the entity event handler when I haven’t uploaded a document. Oh, by the way, if I upload a document before clicking either save button it works as expect, no errors. So….what do I do about this?  Is there some technique to make the save buttons invisible if a document hasn’t been uploaded?  Is there some else that has to be done?  I could replace the save actions on the buttons with calling a microflow that commits and delete the entity event handlers but I’d rather not go down that road...unless someone can confirm that hey, there’s something in the platform that needs to be fixed. All advice appreciated.  Thank you!                  
2 answers

Look like you stumbled upon one of those wtf moments.

As you have discovered Mendix handles file objects slightly differently compared to all other objects. For example, when uploading a file the file object is committed at the moment the microflow is triggered. This is how the platform works and I am sure there is some reason why it works like that. 

What can you do?

Here is an idea: add a boolean flag to the file document entity. This flag is only set for the user-facing upload form. In the event handler if the flag is set skip the handling of the event. Explicitly commit the file document object again when the user clicks save (after some validation).

Hope this helps,


Hi Andrej, indeed, one of those moments!

I can’t see any place in the entity event handler to tell it skip calling the microflow based on a flag.  That is unless you mean to skip the handling within the microflow?  The thing is, none of the FileDocument and my specialization entity attributes changed when a file is uploaded so there’s really no way to know when to set or clear the flag...that can only be done when saving the object.

I’ve already made it work by committing explicitly from a mf as you suggested and do some validation but I’m trying to avoid means creating more mf’s and changing many buttons.  Not lazy, just trying to keep it simple when I have tendency to make things complicated when they don’t have to be :)

Thanks again for the advice!