Note that there are some explanatory texts on larger screens.

plurals
  1. POPrevent System/exit in code I don't have access to
    primarykey
    data
    text
    <p>I'm playing with someone else's code by examining it in the repl.</p> <p>It keeps calling System/exit, which brings down my repl. This is infuriating.</p> <p>In all the code I have access to, I've mocked the calls out.</p> <p>But it's also calling some library code I don't have the source to, both java and clojure, and this occasionally causes exits too.</p> <p>Is there any way to catch these calls globally, so that an attempt to call them doesn't kill the repl thread? Ideally it would just throw an exception instead.</p> <p>I think in java I could install a new SecurityManager to get this effect, but I've never done it</p> <p>there seems to be something in that line here: <a href="http://jroller.com/ethdsy/entry/disabling_system_exit" rel="nofollow">http://jroller.com/ethdsy/entry/disabling_system_exit</a></p> <p>So I'm thinking something like:</p> <pre><code>(System/setSecurityManager (SecurityManager.)) </code></pre> <p>only I somehow need to attach</p> <pre><code> public void checkPermission( Permission permission ) { if( "exitVM".equals( permission.getName() ) ) { throw new ExitTrappedException() ; } } </code></pre> <p>My best shot so far is:</p> <pre><code>(System/setSecurityManager (proxy [SecurityManager] [] (checkPermission [p] (when (= "exitVM" (.getName p)) (throw (Exception. "exit")))))) </code></pre> <p>or maybe</p> <pre><code>(System/setSecurityManager (proxy [SecurityManager] [] (checkExit [n] false))) </code></pre> <p>But they both just destroy the repl</p> <p>Or is there a better way of doing this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload