Skip to content

incompatible code with jdk14 in okhttp3 plugin #5197

@liudantop

Description

@liudantop

Please answer these questions before submitting your issue.

  • Why do you submit this issue?
  • Question or discussion
  • [ 1 ] Bug
  • Requirement
  • Feature or performance improvement

Question

  • What do you want to know?

Bug

  • Which version of SkyWalking, OS and JRE?
    6.0

  • Which company or project?

  • What happen?
    I run agent in jdk14, it occurs error:

[ERROR][InstMethodsInter]class[class okhttp3.RealCall] before method[execute] intercept failure
java.lang.NoSuchFieldException: modifiers
at java.base/java.lang.Class.getDeclaredField(Class.java:2489)

find this code in okhttp plugin:

   Request request = (Request) objInst.getSkyWalkingDynamicField();

    ContextCarrier contextCarrier = new ContextCarrier();
    HttpUrl requestUrl = request.url();
    AbstractSpan span = ContextManager.createExitSpan(requestUrl.uri()
                                                                .getPath(), contextCarrier, requestUrl.host() + ":" + requestUrl
        .port());
    span.setComponent(ComponentsDefine.OKHTTP);
    Tags.HTTP.METHOD.set(span, request.method());
    Tags.URL.set(span, requestUrl.uri().toString());
    SpanLayer.asHttp(span);

    Field headersField = Request.class.getDeclaredField("headers");
    **Field modifiersField = Field.class.getDeclaredField("modifiers");**
    modifiersField.setAccessible(true);
    modifiersField.setInt(headersField, headersField.getModifiers() & ~Modifier.FINAL);

    headersField.setAccessible(true);
    Headers.Builder headerBuilder = request.headers().newBuilder();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        headerBuilder.add(next.getHeadKey(), next.getHeadValue());
    }
    headersField.set(request, headerBuilder.build());

Already remove this field in jdk14
Field modifiersField = Field.class.getDeclaredField("modifiers");


Requirement or improvement

  • Please describe about your requirements or improvement suggestions.

Metadata

Metadata

Labels

agentLanguage agent related.bugSomething isn't working and you are sure it's a bug!pluginPlugin for agent or collector. Be used to extend the capabilities of default implementor.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions