Script error: Can't unambiguously select between fixed arity signatures

Started by Xavier Mayeur, December 10, 2020, 07:39:18 AM

Previous topic - Next topic

Xavier Mayeur

Hello,

I used the following code to set the properties of a view ('theView') , from an external source returning a json string to the 'meta' variable. Then I parse the json string into the 'jmeta' object, and on the fly set the view properties:


   jmeta=JSON.parse(meta, function(key, value) {
      theView.prop(key, value);
      return value;
   });


The code executes well, properties are stored in the view. Nevertheless, I get the following error message, stopping the script execution:

Script Error: java.lang.RuntimeException: java.lang.NoSuchMethodException: Can't unambiguously select between fixed arity signatures [(java.lang.String, boolean), (java.lang.String, java.lang.String)] of the method com.archimatetool.script.dom.model.ArchimateDiagramModelProxy.prop for argument types [java.lang.String, jdk.nashorn.internal.scripts.JD]

What does it mean and what is wrong here ?

Xavier

Jean-Baptiste Sarrodie

HI,

Quote from: Xavier Mayeur on December 10, 2020, 07:39:18 AM
The code executes well, properties are stored in the view. Nevertheless, I get the following error message, stopping the script execution:

Script Error: java.lang.RuntimeException: java.lang.NoSuchMethodException: Can't unambiguously select between fixed arity signatures [(java.lang.String, boolean), (java.lang.String, java.lang.String)] of the method com.archimatetool.script.dom.model.ArchimateDiagramModelProxy.prop for argument types [java.lang.String, jdk.nashorn.internal.scripts.JD]

What does it mean and what is wrong here ?

Javascript is a clever language which automagically convert between types. In some occasions there might be multiple choices. In your case, if the value is 0, 1, true, false, null or some other, JS has to decide if it has to convert it to String, Boolean or something else. For this, it checks the signature of the methode or function being called: if you call a method which requires a string, it will know that it has to convert the value to a string. For this specific method prop() and some of your values, there is an ambiguity between prop(string, string) and prop(string, boolean), so the javascript engine doesn't know what to do... and stops.

To solve this, you simply have to force the right cast operation on use String(value) instead of simply value.

Regards,

JB
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Xavier Mayeur

Thanks. a complex error message for a simple solution. It works now  :)