mxsm commented on code in PR #3073:
URL:
https://github.com/apache/incubator-eventmesh/pull/3073#discussion_r1103484162
##########
eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigMonitorService.java:
##########
@@ -52,20 +52,16 @@ public void load() {
if (configInfo.getObject().equals(object)) {
continue;
}
-
Field field = configInfo.getObjectField();
- boolean isAccessible = field.isAccessible();
- try {
- field.setAccessible(true);
- field.set(configInfo.getInstance(), object);
- } finally {
- field.setAccessible(isAccessible);
- }
+ field.setAccessible(true);
+ field.set(configInfo.getInstance(), object);
configInfo.setObject(object);
log.info("config reload success: {}", object);
} catch (Exception e) {
log.error("config reload failed", e);
+ } finally {
+ configInfo.getObjectField().setAccessible(false);
Review Comment:
Hi @eight-nines Can my example below help answer your question?
```java
public class Student {
private int age;
public String name;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
```
test class:
```java
public class Test {
public static void main(String[] args) throws Exception{
Student student = new Student();
Field age = Student.class.getDeclaredField("age");
try {
age.set(student, 1);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
age.setAccessible(true);
age.set(student, 1);
Field name = Student.class.getDeclaredField("name");
name.set(student, "mxsm");
System.out.println(student.getName());
name.setAccessible(false);
name.set(student, "mxsm1");
System.out.println(student.getName());
}
}
```
run result:

explain:
Using the Student class as an example, the setAccessible method only sets a
flag to tell the Java Virtual Machine whether to check if the property is
private, public, or protected when executing. If set to true, it means no check
is required, while false means a check is needed. Setting a non-public property
to false using the setAccessible method does not change it to a private
property. Therefore, it is okay to directly set it to false.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]