Class Guard

java.lang.Object
org.codehaus.commons.compiler.sandbox.Guard

public final class Guard extends Object
Enforces the SandboxLimits of an execution by a SandboxExecutor.

When a SandboxPolicy is set, JANINO inserts calls to tick() at the beginning of every loop body and of every method and constructor body, wraps the dimension of one-dimensional array creations in calls to arrayLength(int, int), and replaces multi-dimensional array creations with calls to newArray(Class, int[]). Sandboxed code may also call these methods itself; that is harmless.

Outside of a SandboxExecutor, these methods do nothing. If the policy requires an executor, then JANINO inserts calls to the "strict" variants tickStrict(), arrayLengthStrict(int, int) and newArrayStrict(Class, int[]) instead, which throw an IllegalStateException outside of a SandboxExecutor.

Once a limit is exceeded, the guard stays tripped: Every subsequent call throws a SandboxLimitExceededError again, so that code cannot continue by catching the error.

  • Method Details