Class SystemExitManager


  • public class SystemExitManager
    extends java.lang.SecurityManager
    A special security manager (SM) passing on permission checks to the original SM it replaces, except for checkExit(int)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.SecurityManager originalSecurityManager  
      • Fields inherited from class java.lang.SecurityManager

        inCheck
    • Constructor Summary

      Constructors 
      Constructor Description
      SystemExitManager​(java.lang.SecurityManager originalSecurityManager)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void checkExit​(int status)
      Always throws a SystemExitException when System.exit(int) is called, instead of terminating the JVM.
      void checkPermission​(java.security.Permission perm)  
      • Methods inherited from class java.lang.SecurityManager

        checkAccept, checkAccess, checkAccess, checkAwtEventQueueAccess, checkConnect, checkConnect, checkCreateClassLoader, checkDelete, checkExec, checkLink, checkListen, checkMemberAccess, checkMulticast, checkMulticast, checkPackageAccess, checkPackageDefinition, checkPermission, checkPrintJobAccess, checkPropertiesAccess, checkPropertyAccess, checkRead, checkRead, checkRead, checkSecurityAccess, checkSetFactory, checkSystemClipboardAccess, checkTopLevelWindow, checkWrite, checkWrite, classDepth, classLoaderDepth, currentClassLoader, currentLoadedClass, getClassContext, getInCheck, getSecurityContext, getThreadGroup, inClass, inClassLoader
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • originalSecurityManager

        private final java.lang.SecurityManager originalSecurityManager
    • Constructor Detail

      • SystemExitManager

        public SystemExitManager​(java.lang.SecurityManager originalSecurityManager)
    • Method Detail

      • checkExit

        public void checkExit​(int status)
        Always throws a SystemExitException when System.exit(int) is called, instead of terminating the JVM.

        The exception is meant to be handled in the exec:java goal. On the one hand, this avoids that Java code called in process can terminate the JVM and the whole Maven build process with it. On the other hand, the exception handler can also differentiate between exit status 0 (OK) and non-0 (error) by inspecting SystemExitException.getExitCode():

        • Exit status 0 (OK): Just log the fact that System.exit(int) was called.
        • Exit status non-0 (error): In addition to logging, the exception is also passed on, failing the mojo execution as if the called Java code had terminated with an exception instead of trying to terminate the JVM with an error code.
        Overrides:
        checkExit in class java.lang.SecurityManager
        Parameters:
        status - the exit status
      • checkPermission

        public void checkPermission​(java.security.Permission perm)
        Overrides:
        checkPermission in class java.lang.SecurityManager