Skip to content

Commit f893274

Browse files
ouoou欧弟
andauthored
fix: NoSuchFieldException modifiers when jdk >= 12 (#113)
* fix: Spring 6.x.x NoSuchMethod getStatusCode * fix: NoSuchFieldException modifiers when jdk >= 12 --------- Co-authored-by: 欧弟 <[email protected]>
1 parent 51d107c commit f893274

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

agent-plugins/agent-feign-plugin/src/main/java/cloud/erda/agent/plugin/http/v9/DefaultHttpClientInterceptor.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
4444
import org.apache.skywalking.apm.agent.core.util.Strings;
4545

46-
import java.lang.reflect.Field;
47-
import java.lang.reflect.Modifier;
4846
import java.net.URL;
4947
import java.util.*;
5048

@@ -103,12 +101,7 @@ public void beforeMethod(IMethodInterceptContext context, MethodInterceptResult
103101

104102
tracer.inject(span.getContext(), carrier);
105103

106-
Field headersField = Request.class.getDeclaredField("headers");
107-
Field modifiersField = Field.class.getDeclaredField("modifiers");
108-
modifiersField.setAccessible(true);
109-
modifiersField.setInt(headersField, headersField.getModifiers() & ~Modifier.FINAL);
110-
headersField.setAccessible(true);
111-
Map<String, Collection<String>> headers = new LinkedHashMap<String, Collection<String>>(request.headers());
104+
Map<String, Collection<String>> headers = new LinkedHashMap<>(request.headers());
112105
for (Map.Entry<String, String> entry : carrier) {
113106
if (Strings.isEmpty(entry.getKey())) {
114107
continue;
@@ -121,7 +114,15 @@ public void beforeMethod(IMethodInterceptContext context, MethodInterceptResult
121114
contextCollection.add(entry.getValue());
122115
headers.put(entry.getKey(), contextCollection);
123116
}
124-
headersField.set(request, Collections.unmodifiableMap(headers));
117+
118+
Request newRequest = Request.create(
119+
request.method(),
120+
request.url(),
121+
headers,
122+
request.body(),
123+
request.charset()
124+
);
125+
allArguments[0] = newRequest;
125126

126127
TransactionMetricBuilder transactionMetricBuilder = TransactionMetricUtils.createHttpMetric(peerHost);
127128
transactionMetricBuilder.tag(Constants.Tags.SPAN_KIND, Constants.Tags.SPAN_KIND_CLIENT)

0 commit comments

Comments
 (0)