Special Character causes Overflow

hi team, i have an entity with an attribute "Name" of type String of length 5. I am trying to place a string abcád into this field. Please note the special character. Now this is causing an exception that field length is 5 but you are trying to save 6! How is this possible? Because if i keep the breakpoint and see the variable name and count the character its still 5! Why mendix Change object is taking it as 6? How can this be turned around?
2 answers

I just did a small test project to confirm this. A simple setup where I put an on change microflow on a text field which calculates and displays the attribute length. áááá gives a length of 8. áááább gives a length of 10.

I wondered whether a java action to return the string length would return the same result, and unfortunately it does - it also sees á as 2 characters. Perhaps there is another java function that can take account of the character set that might return the correct length.


OK I managed to get my java action to return the correct character count by first Normalizing the string. In my java action I import the class java.text.Normalizer then use

   public static String stripAccents(String s) {
        return Normalizer.normalize(s, Normalizer.Form.NFD)
        .replaceAll("[^\p{ASCII}]", "");
The length function on this cleaned string then returns the expected length.

Ganesh, so to solve your issue you should make the following changes:

  • Increase the size of your attribute to at least 10 to allow for up to 5 double-byte characters
    • Add on-change or before-commit microflows to call a java action using the above to check the number of mormalized characters, and if it is more than 5, throw an error or take other appropriate action.

I would say it is a bit different. If the character is in the UTF-8 charset, then Mendix handles it properly. Try any of the UTF-8 special characters and copy them from this site:

UTF-8 Character Set

To see that the Mendix max field length for String does adhere to UTF-8. So, also the character you mention above will work within Mendix and will be seen as a single character. This means adding to the length of the limited String in the Mendix database is NOT necessary for UTF-8 chars.