1. Stacktrace method
One of the hints which I got was our exception class, whenever an exception is thrown we get the whole stack strace, which includes the invoking classes.
Throwable t = new Throwable();
StackTraceElement callerClass = t.getStackTrace()[1];
System.out.println(callerClass.getClassName());
Gets the class name :)
2. Security Manager method
class SM extends SecurityManager {
@Override
public Class[] getClassContext() {
return super.getClassContext();
}
}
SM sm = new SM();
Class[] classContext = sm.getClassContext();
System.out.println(classContext[2].getName());
Bingo, got the class name. getClassContext() is a protected method, to use it we need to extend security manager or use it as I've done above.