As a quick hack, it was much easier to do than I thought. Since this is a quick hack, I did not do such things as making sure that the stack trace is deep enough to dereference the array, etc. I pasted the following into my signed applet constructor:
log.info("Old security manager = " + System.getSecurityManager()); System.setSecurityManager(new SecurityManager() { @Override public void checkAccess(final Thread t) { StackTraceElement[] list = Thread.currentThread().getStackTrace(); StackTraceElement element = list[3]; if (element.getMethodName().equals("interrupt")) { log.info("CheckAccess to interrupt(Thread = " + t.getName() + ") - " + element.getMethodName()); dumpThreadStack(Thread.currentThread()); } super.checkAccess(t); } });
and the dumpThreadStack method is as follows:
public static void dumpThreadStack(final Thread thread) { StringBuilder builder = new StringBuilder('\n'); try { for (StackTraceElement element : thread.getStackTrace()) { builder.append(element.toString()).append('\n'); } } catch (SecurityException e) { } log.info(builder.toString()); }
I could never, of course, leave this in production code, but it was enough for me to say which particular thread calls interrupt() , which I did not expect. That is, with this code in place, I get a stack dump for every call to Thread.interrupt() .
Eddie
source share