Groovy gives error expecting EOF, found '?' @ line 9, column 25

11,696

You have some extra unicode characters in line 4. If you convert it to hex you will get:

64 65 66 20 72 61 6e 20 3d 20 4d 61 74 68 2e 61 62 73 28 e2 80 8b 72 61 6e 49 6e 74 29 e2 80 8b 25 32 30 e2 80 8b 30 3b

Now if you convert this hex back to ascii, you will get:

def ran = Math.abs(​ranInt)​%20​0;

There is a character ​ added after first (, after ) and after first 0. If you remove it, your code will compile correctly.

Here is the hex of curated line:

64 65 66 20 72 61 6e 20 3d 20 4d 61 74 68 2e 61 62 73 28 72 61 6e 49 6e 74 29 25 32 30 30 3b

And the line itself:

def ran = Math.abs(ranInt)%200;
Share:
11,696

Related videos on Youtube

Buddhi
Author by

Buddhi

Updated on June 04, 2022

Comments

  • Buddhi
    Buddhi almost 2 years

    I'm using following code to generate random number in Groovy. I can run it in e.g. Groovy Web Console (https://groovyconsole.appspot.com/) and it works, however it fails when I try to run it in Mule. Here is the code I use:

    log.info ">>run"
    Random random = new Random()
    def ranInt = random.nextInt()
    def ran = Math.abs(​ranInt)​%20​0;
    log.info ">>sleep counter:"+flowVars.counter+" ran: "+ran
    sleep(ran)
    

    And here is an exception that gets thrown:

    Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script26.groovy: 9: expecting EOF, found '?' @ line 9, column 25. def ran = Math.abs(?400)?%20?0; ^

    1 error

  • Buddhi
    Buddhi about 6 years
    you are a genius :)
  • Szymon Stepniak
    Szymon Stepniak about 6 years
    @Buddhi Nah, I just experienced similar problems a few times before :)
  • Buddhi
    Buddhi about 6 years
    now i get new issue, when the ranInt is negative number for ex: -139709715, the Math.abs fails
  • Buddhi
    Buddhi about 6 years
    also I tried to use a code like int absVal = (ranInt>0) ? ranInt : (-1*ranInt) log.info ">>absVal: " + absVal it also fails when ranInt is negative