package org.jboss.modules;

import java.security.AccessController;
import java.security.PrivilegedAction;

/**
 * Various methods for obtaining caller info.
 *
 * @author Jason T. Greene
 */
class CallerContext {
    private final static class Hack extends SecurityManager {
        @Override
        protected Class<?>[] getClassContext() {
            return super.getClassContext();
        }
    }

    private static Hack hack = AccessController.doPrivileged(new PrivilegedAction<Hack>() {
        @Override
        public Hack run() {
            return new Hack();
        }
    });

    static Class<?> getCallingClass() {
        return hack.getClassContext()[1];
    }
}

@@ -632,22 +632,34 @@
         
-return
+Class%3C?%3E stack%5B%5D =
  hack.ge
@@ -677,10 +677,221 @@
 xt()
-%5B1
+;%0A        int i = 3;%0A        while (stack%5Bi%5D == stack%5B2%5D) %7B%0A            // skip nested calls fromt the same class%0A            if (++i %3E= stack.length)%0A                return null;%0A        %7D%0A%0A        return stack%5Bi
 %5D;%0A 

Allow for nested calls from the same class