StackTraceElement question (original) (raw)

David Holmes david.holmes at oracle.com
Sun Oct 7 23:27:27 UTC 2012


On Sat, Oct 6, 2012 at 3:04 AM, Christos Zoulas<christos at zoulas.com> wrote:

Hi,

I don't know if this belongs to this list, but if it does not, please point me to where it does. I think that it would be nice if StackTraceElement which currently contains: boolean equals(Object obj) String getClassName() String getFileName() int getLineNumber() String getMethodName() int hashCode() boolean isNativeMethod() String toString() It would be more useful for it to also contain: Class<?> getClass() The reason I am asking, is because I have an application where I would like to find the enclosing class from where the exception is thrown not the superclass, but I cannot deduce that from the class name. If STE contained the above method, I could do: Class<?> c = ste.getClass(); while (c.getEnclosingClass() != null) { c = c.getEnclosingClass(); } return c.getName();

Can't you just do Class.forName(getClassName()) and then find the enclosing class?

David

to find the class I want, and getClassName() could be just a wrapper:

String getClassName() { return getClass().getName(); } Is there any reason to store the name instead of the Class<?>? Is it possible to fix this in a future version of the jdk? thanks christos



More information about the core-libs-dev mailing list