java 7 40,Java 7u40 Java SE 8 sun.reflect.Reflection.getCallerClass

i have read the following post

i was wondering what this change really means.

1). Means that this class sun.reflect.Reflection.getCallerClass will be rewritten to provide more security in Java reflection?

2). Means this class will no more be needed? maybe another approach?

3). Reflection will be over in Java 8. method.invoke will throw UnsupportedOperationException.??

4). this will affect anything related to Spring or AspectJ Aspect Oriented Programming?

i was wondering because we use Reflection method.invoke to provide some flags to the class before being send to the DB. this raises another question if reflection is over what approach can i use to provide my behavior above. i think AOP is a way to go.

thanks a lot.

解决方案

Short answer: you only need to worry if you use sun.reflect.Reflection.getCallerClass. (And it is ludicrous to suggest that Java reflection is being withdrawn.)

A longer answer is that the functionality provided by that method is being reworked in JEP 176. The old method is actually being removed ... not just deprecated. It is a method in the sun.* tree, and application code should not be calling it directly. The current plan seems to be:

to remove this functionality entirely if no valid use cases can be identified, or

provide a replacement API, or at least defer the hard removal of the current method from Java 7

The original primary use-case for this private API was for security managers and the like that needed to know who called them. Unfortunately, this approach has proven to be fragile. A new approach to that problem (using message handles) has been designed. Rather than leaving this API in place for application code to use willy-nilly for dubious purposes, they have decided to force the issue.

However, there are signs of push-back on this issue because it is causing breakages in things like Groovy and JRuby.

References:

Your specific questions:

1). Means that this class sun.reflect.Reflection.getCallerClass will be rewritten to provide more security in Java reflection?

See above. I suspect that there is a security related motivation for this.

2). Means this class will no more be needed? maybe another approach?

See above. They haven't yet determined whether the functionality is needed.

3). Reflection will be over in Java 8. method.invoke will throw UnsupportedOperationException.??

No to both of these. This is just about a specific method of a specific class in the sun.* packages.

It does not impact on reflection in general or on method.invoke().

4). this will affect anything related to Spring or AspectJ Aspect Oriented Programming?

Probably not. It would only affect those technologies if they relied on that particular method. If they do, then the respective library maintainers will need to ensure that the Java team are aware of the use-cases that require this. I imagine the maintainers are tracking this.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值