You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Artyom Kravchenko (JIRA)" <ji...@apache.org> on 2017/03/09 10:49:37 UTC
[jira] [Created] (GROOVY-8113) Groovy script/template engine
produce memory leak
Artyom Kravchenko created GROOVY-8113:
-----------------------------------------
Summary: Groovy script/template engine produce memory leak
Key: GROOVY-8113
URL: https://issues.apache.org/jira/browse/GROOVY-8113
Project: Groovy
Issue Type: Bug
Components: GroovyScriptEngine, Templating
Affects Versions: 2.4.8
Environment: Groovy 2.4.8, Oracle Java JDK 8u121
Reporter: Artyom Kravchenko
There is a simple way to produce OutOfMemoryException if run infinite numbers of groovy scripts or evaluate groovy templates.
Simple test to reproduce a memory leak:
{code:java}
import javax.script.*;
import java.util.HashMap;
import java.util.Map;
public class OutOfMemoryTest {
private static String TEMPLATE = "Dear ${fullName} please go away at ${time}";
private static String SCRIPT = "def run(args) {\n" +
"def bindings = ['fullName' : 'Ali Baba', 'time' : new Date()]\n" +
"println args.templateEngine.createTemplate(args.template).make(bindings).toString()\n" +
"}";
public static void main(String... args) {
// GroovySystem.getMetaClassRegistry().getMetaClassCreationHandler().setDisableCustomMetaClassLookup(true);
while(true) {
ScriptEngineManager engineManager = new ScriptEngineManager();
ScriptEngine engine = engineManager.getEngineByName("groovy");
try {
engine.eval(SCRIPT);
} catch (ScriptException e) {
throw new RuntimeException(e);
}
groovy.text.SimpleTemplateEngine templateEngine = new groovy.text.SimpleTemplateEngine();
Invocable inv = (Invocable) engine;
Map<String, Object> params = new HashMap<>();
params.put("template", TEMPLATE);
params.put("templateEngine", templateEngine);
Object[] runArgs = { params };
try {
inv.invokeFunction("run", runArgs);
} catch (ScriptException | NoSuchMethodException e) {
e.printStackTrace();
}
}
}
}
{code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)