Interface Privilege

  • public interface Privilege
    Clean interface to the doPrivileged... methods on AccessController.

    This interface must remain non-exported from org.postgresql.pljava.internal.

    The reason, of course, is that the real methods on AccessController end up getting called from these wrappers, and will therefore apply the permissions granted to this module. As long as these methods are only accessible within this module, that isn't a problem.

    It would be great to develop this into an exportable API so user code could benefit, but that would be a much trickier undertaking, with editing of AccessControlContexts to snag the correct caller's context, and not for the faint of heart.

    Each method here comes in a flavor accepting a Checked.Supplier, matching any lambda that returns a reference type, and a flavor accepting a Checked.Runnable for void lambdas, because the compiler will not match those up with Supplier<Void>.

    Fuss no more with PrivilegedExceptionAction and catching PrivilegedActionException: just pass any of these methods a lambda. If the lambda throws a checked exception, so does the method. If the lambda throws some checked exceptions, the method throws their least common supertype, which is not as nice as throwing their union, and climbs all the way up to Exception if they are unrelated. But even so, you can now simply catch it, rather than catching a PrivilegedActionException and having to unwrap it first.