Class DenyAction

java.lang.Object
org.cojen.boxtin.DenyAction

public abstract sealed class DenyAction extends Object
Specifies the action to take when access to an operation is denied.
  • Method Details

    • standard

      public static DenyAction standard()
      Returns the standard deny action, which throws a SecurityException without a message.
    • exception

      public static DenyAction exception(String className)
      Returns a deny action which throws an exception without a message.
    • exception

      public static DenyAction exception(String className, String message)
      Returns a deny action which throws an exception with an optional message.
    • exception

      public static DenyAction exception(Class<?> clazz)
      Returns a deny action which throws an exception without a message.
    • exception

      public static DenyAction exception(Class<?> clazz, String message)
      Returns a deny action which throws an exception with an optional message.
    • value

      public static DenyAction value(Object value)
      Returns a deny action which returns a specific value, possibly null. If the value is incompatible with the actual value type, then null, 0, false, or void is returned instead.

      Note: This action has no effect for constructors, and if configured as such, the standard action is used instead.

      Throws:
      IllegalArgumentException - if the given value isn't null, a boxed primitive, or a string
    • empty

      public static DenyAction empty()
      Returns a deny action which returns an empty instance. Types supported are arrays, String, Optional, Iterable, Collection, Stream, and any of the empty variants supported by the Collections class. Otherwise, a new instance is created using a no-arg constructor, possibly resulting in a LinkageError at runtime. If the actual type is primitive, then 0, false or void is returned instead.

      Note: This action has no effect for constructors, and if configured as such, the standard action is used instead.

    • custom

      public static DenyAction custom(MethodHandleInfo mhi)
      Returns a deny action which performs a custom operation. The parameters given to the custom method are the Caller (optional), the non-null instance (if applicable), and the original method parameters. The return type must exactly match the original method's return type. If the custom method type is incompatible, then a SecurityException or WrongMethodTypeException can be thrown instead.

      Note: This action has no effect for constructors, unless the custom operation throws an exception. If it doesn't throw an exception, a SecurityException is thrown instead.

    • check

      public DenyAction check(MethodHandleInfo predicate)
      Returns this deny action but with a predicate check to determine if the operation should actually be allowed. The parameters given to the predicate are the Caller (optional), the non-null instance (if applicable), and the original method parameters. The return type must be boolean. If the predicate format is incompatible, then a SecurityException or WrongMethodTypeException can be thrown instead.
      Parameters:
      predicate - the predicate checking method which returns true when the operation is allowed
      Throws:
      IllegalArgumentException - if the predicate doesn't return a boolean
      IllegalStateException - if this action is already checked