简体   繁体   English

如何找出在项目中调用System.getProperty()方法的位置?

[英]How to find out where System.getProperty() method is invoked in the project?

I have no control of where System.getProperty is called in the project. 我无法控制在项目中调用System.getProperty的位置。 I want to log some information in the console whenever System.getProperty("SomeProperty"); 每当System.getProperty(“ SomeProperty”);我想在控制台中记录一些信息。 is called. 叫做。

How to achieve this. 如何实现这一目标。

You could try creating a java.lang.SecurityManager that throws an exception or prints some stuff out in the checkPropertyAccess(String) method . 您可以尝试创建一个抛出异常或在checkPropertyAccess(String)方法中打印出一些东西的java.lang.SecurityManager It gets called when something accesses System properties. 当某些人访问系统属性时,它将被调用。

More info about Security Managers: 有关安全管理器的更多信息:

http://docs.oracle.com/javase/tutorial/essential/environment/security.html http://docs.oracle.com/javase/tutorial/essential/environment/security.html
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed2.html http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed2.html

You would like to use AspectJ and its pointcut . 您想使用AspectJ及其pointcut Take a look here for more. 在这里看看更多。

Here is an example adapted from the tutorial mentioned above. 这是改编自上述教程的示例。

 @Aspect
 public class Foo {

   @Pointcut("call(* java.lang.System.getProperty(..))")
   void anyUtilityCall() {
       // do whatever you need
   }

 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM