Class SandboxPolicy.Builder

java.lang.Object
org.codehaus.commons.compiler.sandbox.SandboxPolicy.Builder
Enclosing class:
SandboxPolicy

public static final class SandboxPolicy.Builder extends Object
Creates SandboxPolicys. All class names are binary names in the format of Class.getName(), e.g. "java.util.Map$Entry".
  • Method Details

    • allowMethod

      public SandboxPolicy.Builder allowMethod(String className, String name, String descriptor)
      Allows one method or constructor.
      Parameters:
      name - The method name, or "<init>" for a constructor
      descriptor - The method descriptor, e.g. "(Ljava/lang/String;)V"
    • allowMethods

      public SandboxPolicy.Builder allowMethods(String className, String... names)
      Allows all overloads of the named methods of the class.
    • allowField

      public SandboxPolicy.Builder allowField(String className, String name)
      Allows reading and writing the named field of the class. (Writing a final field fails anyway.)
    • allowConstructors

      public SandboxPolicy.Builder allowConstructors(String... classNames)
      Allows all constructors of the given classes, except the never-allowed ones.
    • allowAllMembers

      public SandboxPolicy.Builder allowAllMembers(String... classNames)
      Allows all fields, methods and constructors that the given classes declare, except the never-allowed ones.
    • allowSubclassing

      public SandboxPolicy.Builder allowSubclassing(String... classNames)
      Allows sandboxed code to declare classes that extend or implement the given classes or interfaces.
    • requireExecutor

      public SandboxPolicy.Builder requireExecutor()
      Requires that code that JANINO compiles with this policy is executed only by a SandboxExecutor.

      By default, the resource limit checks that JANINO inserts do nothing outside of a SandboxExecutor. That concerns e.g. static initializers and constructors that run when the host instantiates a generated class, and methods like toString() that the host calls on an object that the sandboxed code returned. With this option, these checks throw an IllegalStateException instead, so that sandboxed code cannot run without limits.

      This option has no effect on the JDK back end (commons-compiler-jdk), which does not insert resource limit checks.

    • include

      public SandboxPolicy.Builder include(SandboxPolicy policy)
      Adds all rules of the given policy, e.g. of SandboxPolicy.JAVA_LANG_BASIC, and requires an executor if the policy does.
    • build

      public SandboxPolicy build()