Painless scripting error illegal_argument_exception "unexpected token ['('] was expecting one of [{<EOF>, ';'}]"


#1

Running the following painless script against 6.2.4 returns an illegal_argument_exception "unexpected token ['('] was expecting one of [{, ';'}]".

def someVariable = "";

void someFunction(def arg) {
    def someVariable2 = "";
}

someFunction("");

It doesn't error if you use the following script:

void someFunction(def arg) {
    def someVariable2 = "";
}

def someVariable = "";

someFunction("");

I tried searching both the open and closed GitHub issues and the forum here but can't find anything similar mentioned. I was wondering if anyone could:

  • point out my error
  • confirm this is a bug (by reproducing it) and or
  • point me to the bug report

I'm happy to open a new bug report on Github if this turns out to be a real issue.

Thank you for your time.


#2

It seems that all variables need to be declared and defined after all functions. In this case if someVariable is desired inside someFunction then you must pass it in as a parameter. For example:

String someFunction(def arg, String someVariable) {
  return arg + someVariable;
}

String someVariable = "";

someFunction("", someVariable);

(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.