Reflection.getCallerClass() and @CallerSensitive for a constructor?
tom.hawtin at oracle.com
Mon Mar 24 13:28:35 UTC 2014
On 24/03/2014 08:41, Wang Weijun wrote:
> Calling Reflection.getCallerClass() needs the @CallerSensitive annotation, but it cannot be applied to a constructor.
Ah, I see your message from 2012-11-26 05:46.
> This is very nice but it does not mention Constructor.newInstance().
> In fact, I do see the following entries if I'm creating an object
> thru reflection:
And Class.newInstance. Which gives a clue to a problem. Any code that is
using Constructor.newInstance has to be as careful with it as they are
with Method.invoke. Slightly more so, as constructors lean on
overloading rather than having names like all self-respecting methods.
As we know from experience, existing code does automatically take into
account bizarre new requirements. I think we have a sufficient quantity
of caller-sensitive stuff without taking it into new directions.
(From reading the HotSpot sources some time ago (may have changed), in
particular circumstances some, but not all, constructor reflection
frames may disappear.)
More information about the core-libs-dev