diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java index 27266e642..b6bd21bb7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java @@ -127,34 +127,34 @@ public class Expression { ((Variable) invokable).value = values[i]; } - pushInstance(); - try { - Future result = evalThread.submit(new Callable() { - @Override - public Double call() throws Exception { + Future result = evalThread.submit(new Callable() { + @Override + public Double call() throws Exception { + pushInstance(); + try { return root.getValue(); + } finally { + popInstance(); } - }); - try { - return result.get(WorldEdit.getInstance().getConfiguration().calculationTimeout, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new RuntimeException(e); - } catch (ExecutionException e) { - Throwable cause = e.getCause(); - if (cause instanceof ReturnException) { - return ((ReturnException) cause).getValue(); - } - if (cause instanceof RuntimeException) { - throw (RuntimeException) cause; - } - throw new RuntimeException(cause); - } catch (TimeoutException e) { - result.cancel(true); - throw new EvaluationException(-1, "Calculations exceeded time limit."); } - } finally { - popInstance(); + }); + try { + return result.get(WorldEdit.getInstance().getConfiguration().calculationTimeout, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new RuntimeException(e); + } catch (ExecutionException e) { + Throwable cause = e.getCause(); + if (cause instanceof ReturnException) { + return ((ReturnException) cause).getValue(); + } + if (cause instanceof RuntimeException) { + throw (RuntimeException) cause; + } + throw new RuntimeException(cause); + } catch (TimeoutException e) { + result.cancel(true); + throw new EvaluationException(-1, "Calculations exceeded time limit."); } } diff --git a/worldedit-core/src/test/java/com/sk89q/worldedit/internal/expression/ExpressionTest.java b/worldedit-core/src/test/java/com/sk89q/worldedit/internal/expression/ExpressionTest.java index 1d0456d01..207bb4e56 100644 --- a/worldedit-core/src/test/java/com/sk89q/worldedit/internal/expression/ExpressionTest.java +++ b/worldedit-core/src/test/java/com/sk89q/worldedit/internal/expression/ExpressionTest.java @@ -24,13 +24,23 @@ import static java.lang.Math.sin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import org.junit.Before; +import org.junit.Test; + +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.event.platform.PlatformReadyEvent; import com.sk89q.worldedit.internal.expression.lexer.LexerException; import com.sk89q.worldedit.internal.expression.parser.ParserException; import com.sk89q.worldedit.internal.expression.runtime.EvaluationException; import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment; -import org.junit.Test; public class ExpressionTest { + @Before + public void setup() { + WorldEdit.getInstance().getPlatformManager().register(new ExpressionPlatform()); + WorldEdit.getInstance().getPlatformManager().handlePlatformReady(new PlatformReadyEvent()); + } + @Test public void testEvaluate() throws ExpressionException { // check