0

I'm using GroovyConsole to evaluate scripts I get from external sources. So the code to evaluate is dynamic and I don't have control over it. Actually is written into a database and I have to read it as a String. Not perfect, but that's how it is.

What I'm doing right now:

private GroovyShell shell

def processScript( def script){
    if (script) {
        try{
            shell.evaluate (script, 'some_random_name')
        }catch( e ){
            log.warn "Could not process script: $e"
        }
    }   
}

This usually works. But now we got a large script (~3000 LOC) and it throws java.lang.RuntimeException: Method code too large! because the script is larger than 64K.

I tried to dump the script into a file and use a BufferedReader, but it throws the same Exception.

So is there a better way to evaluate dynamic Groovy code from within a Groovy method?

moeTi
  • 3,884
  • 24
  • 37

1 Answers1

1

The problem is your script reach the java limit for a method. I think the only solution is to split your script in many scripts in some way. See this answer

Community
  • 1
  • 1
Fabiano Taioli
  • 5,270
  • 1
  • 35
  • 49
  • As I mentioned in the question: I have no control over the script, I get it from an external source – moeTi Oct 16 '13 at 10:52
  • 1
    @moeTi I don't think there's anything you can do if you can't change the script, it's a JVM limit on method size, and this script goes into a `run` method of a Groovy `Script` based class – tim_yates Oct 16 '13 at 12:59
  • Well you can split the script in an automated way after you read it from the external source. I don't think it's easy think to do, bat I don't see any other solution because of the java intrinsic limit. – Fabiano Taioli Oct 16 '13 at 13:06
  • @tim_yates yeah I actually thought so... well ok then I'll have to find a workaround – moeTi Oct 16 '13 at 14:24