Am 03.09.2013 19:16, schrieb Peter Levart:
[...]
What about a simple restriction on methods returning such instances that
Class objects are only returned when they are resolvable from the
ClassLoader of client code. If they are not resolvable, null is
returned. For example, the equivalent of:

public class StackTraceFrame {

     private final Class<?> declaringClass;

     @CallerSensitive
     public Class<?> getDeclaringClass() {
         try {
             return Class.forName(declaringClass.getName(),
                                  false,
Reflection.getCallerClass().getClassLoader())
                    == declaringClass ? declaringClass : null;
             }
         } catch (ClassNotFoundException ignore) {}
         return null;
     }

     // the name can be exposed without fear...
     public String getDeclaringClassName() {
         return declaringClass.getName();
     }


This example could be implemented more efficiently then above code
(using private Class/ClassLoader API).

for us it is the standard case, that the client code is not able to resolve the caller class. The code making the call to the method, that needs the information in the end is usually in a sub loader of the loader in which the declaring class of the method making use of the information is. Not always, but usually. Thus this would be useless to us

bye Jochen

--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

Reply via email to