Source:
public int main(List<String> args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) { this.stdin = new BufferedInputStream(stdin); this.stdout = stdout; this.stderr = stderr; this.locale = locale; registerOptionHandlers(); CmdLineParser p = getCmdLineParser(); SecurityContext sc = null; Authentication old = null; Authentication auth; try { sc = SecurityContextHolder.getContext(); old = sc.getAuthentication(); sc.setAuthentication(auth = getTransportAuthentication()); if (!(this instanceof HelpCommand || this instanceof WhoAmICommand)) Jenkins.get().checkPermission(Jenkins.READ); p.parseArgument(args.toArray(new String[0])); LOGGER.log(Level.FINE, "Invoking CLI command {0}, with {1} arguments, as user {2}.", new Object[] {getName(), args.size(), auth.getName()}); int res = run(); LOGGER.log(Level.FINE, "Executed CLI command {0}, with {1} arguments, as user {2}, return code {3}", new Object[] {getName(), args.size(), auth.getName(), res}); return res; } catch (CmdLineException e) { logAndPrintErrorWithDefaultValues(args, e); printUsage(stderr, p); return 2; } catch (IllegalStateException e) { logAndPrintErrorWithDefaultValues(args, e); return 4; } catch (IllegalArgumentException e) { logAndPrintErrorWithDefaultValues(args, e); return 3; } catch (AbortException e) { logAndPrintErrorWithDefaultValues(args, e); return 5; } catch (AccessDeniedException e) { logAndPrintErrorWithDefaultValues(args, e); return 6; } catch (BadCredentialsException e) { String id = UUID.randomUUID().toString(); logAndPrintError(e, "Bad Credentials. Search the server log for " + id + " for more details.", "CLI login attempt failed: " + id, Level.INFO); return 7; } catch (Throwable e) { logAndPrintError(e, "Unexpected exception occurred while performing "+getName()+" command.", "Unexpected exception occurred while performing "+getName()+" command.", Level.WARNING); Functions.printStackTrace(e, stderr); return 1; } finally { if(sc != null) sc.setAuthentication(old); } }

Target:
public int main(List<String> args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) { this.stdin = new BufferedInputStream(stdin); this.stdout = stdout; this.stderr = stderr; this.locale = locale; registerOptionHandlers(); CmdLineParser p = getCmdLineParser(); SecurityContext sc = null; Authentication old = null; Authentication auth; try { sc = SecurityContextHolder.getContext(); old = sc.getAuthentication(); sc.setAuthentication(auth = getTransportAuthentication()); if (!(this instanceof HelpCommand || this instanceof WhoAmICommand)) Jenkins.get().checkPermission(Jenkins.READ); p.parseArgument(args.toArray(new String[0])); LOGGER.log(Level.FINE, "Invoking CLI command {0}, with {1} arguments, as user {2}.", new Object[] {getName(), args.size(), auth.getName()}); int res = run(); LOGGER.log(Level.FINE, "Executed CLI command {0}, with {1} arguments, as user {2}, return code {3}", new Object[] {getName(), args.size(), auth.getName(), res}); return res; } catch (CmdLineException e) { logFailedCommandAndPrintExceptionErrorMessage(args, e); printUsage(stderr, p); return 2; } catch (IllegalStateException e) { logFailedCommandAndPrintExceptionErrorMessage(args, e); return 4; } catch (IllegalArgumentException e) { logFailedCommandAndPrintExceptionErrorMessage(args, e); return 3; } catch (AbortException e) { logFailedCommandAndPrintExceptionErrorMessage(args, e); return 5; } catch (AccessDeniedException e) { logFailedCommandAndPrintExceptionErrorMessage(args, e); return 6; } catch (BadCredentialsException e) { String id = UUID.randomUUID().toString(); logAndPrintError(e, "Bad Credentials. Search the server log for " + id + " for more details.", "CLI login attempt failed: " + id, Level.INFO); return 7; } catch (Throwable e) { String errorMsg = "Unexpected exception occurred while performing " + getName() + " command."; logAndPrintError(e, errorMsg, errorMsg, Level.WARNING); Functions.printStackTrace(e, stderr); return 1; } finally { if(sc != null) sc.setAuthentication(old); } }