-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix perf issue when accessing fields by reflection (#7052)
Instead of relying on exception using `getDeclaredField(String)` we are using `getDeclaredFields()` and scanning the field by name.
- Loading branch information
Showing
2 changed files
with
37 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...p/src/test/java/datadog/trace/bootstrap/debugger/el/ReflectiveFieldValueResolverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package datadog.trace.bootstrap.debugger.el; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class ReflectiveFieldValueResolverTest { | ||
|
||
@Test | ||
void getFieldAsCapturedValue() { | ||
assertNull(ReflectiveFieldValueResolver.getFieldAsCapturedValue(null, "fieldName").getValue()); | ||
C c = new C(); | ||
assertEquals(3, ReflectiveFieldValueResolver.getFieldAsCapturedValue(c, "c1").getValue()); | ||
assertEquals(1, ReflectiveFieldValueResolver.getFieldAsCapturedValue(c, "a1").getValue()); | ||
assertEquals("2", ReflectiveFieldValueResolver.getFieldAsCapturedValue(c, "a2").getValue()); | ||
assertNull(ReflectiveFieldValueResolver.getFieldAsCapturedValue(c, "notExist").getValue()); | ||
} | ||
|
||
static class A { | ||
private int a1 = 1; | ||
private String a2 = "2"; | ||
} | ||
|
||
static class B extends A {} | ||
|
||
static class C extends A { | ||
private int c1 = 3; | ||
} | ||
} |