未验证 提交 a45f615b 编写于 作者: K kezhenxu94 提交者: GitHub

Use explicit charset instead of default charset (#5601)

Implicit use of the platform default charset, which can result in differing behaviour between JVM executions or incorrect behavior if the encoding of the data source doesn't match expectations.
Co-authored-by: Nzhang-wei <pknfe@outlook.com>
Co-authored-by: wu-sheng's avatar吴晟 Wu Sheng <wu.sheng@foxmail.com>
上级 2b737e24
...@@ -25,6 +25,7 @@ import org.apache.skywalking.apm.agent.core.context.ContextCarrier; ...@@ -25,6 +25,7 @@ import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.ContextManager;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
/** /**
* A SkyWalking tracing plugin for Avro Client. Inject CarrierItems into RPC's metadata from cross-process propagation. * A SkyWalking tracing plugin for Avro Client. Inject CarrierItems into RPC's metadata from cross-process propagation.
...@@ -39,7 +40,7 @@ public class SWClientRPCPlugin extends RPCPlugin { ...@@ -39,7 +40,7 @@ public class SWClientRPCPlugin extends RPCPlugin {
CarrierItem items = carrier.items(); CarrierItem items = carrier.items();
while (items.hasNext()) { while (items.hasNext()) {
items = items.next(); items = items.next();
context.requestCallMeta().put(items.getHeadKey(), ByteBuffer.wrap(items.getHeadValue().getBytes())); context.requestCallMeta().put(items.getHeadKey(), ByteBuffer.wrap(items.getHeadValue().getBytes(StandardCharsets.UTF_8)));
} }
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.apache.skywalking.apm.plugin.avro; package org.apache.skywalking.apm.plugin.avro;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
import org.apache.avro.ipc.RPCContext; import org.apache.avro.ipc.RPCContext;
import org.apache.avro.ipc.RPCPlugin; import org.apache.avro.ipc.RPCPlugin;
...@@ -50,7 +51,7 @@ public class SWServerRPCPlugin extends RPCPlugin { ...@@ -50,7 +51,7 @@ public class SWServerRPCPlugin extends RPCPlugin {
while (items.hasNext()) { while (items.hasNext()) {
items = items.next(); items = items.next();
ByteBuffer buffer = (ByteBuffer) meta.get(new Utf8(items.getHeadKey())); ByteBuffer buffer = (ByteBuffer) meta.get(new Utf8(items.getHeadKey()));
items.setHeadValue(new String(buffer.array())); items.setHeadValue(new String(buffer.array(), StandardCharsets.UTF_8));
} }
String operationName = prefix + context.getMessage().getName(); String operationName = prefix + context.getMessage().getName();
......
...@@ -37,6 +37,7 @@ import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; ...@@ -37,6 +37,7 @@ import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
...@@ -74,10 +75,10 @@ public class HTableInterceptor implements InstanceMethodsAroundInterceptor, Inst ...@@ -74,10 +75,10 @@ public class HTableInterceptor implements InstanceMethodsAroundInterceptor, Inst
while (next.hasNext()) { while (next.hasNext()) {
next = next.next(); next = next.next();
if (operation != null) { if (operation != null) {
operation.setAttribute(next.getHeadKey(), next.getHeadValue().getBytes()); operation.setAttribute(next.getHeadKey(), next.getHeadValue().getBytes(StandardCharsets.UTF_8));
} else { } else {
for (OperationWithAttributes o : operations) { for (OperationWithAttributes o : operations) {
o.setAttribute(next.getHeadKey(), next.getHeadValue().getBytes()); o.setAttribute(next.getHeadKey(), next.getHeadValue().getBytes(StandardCharsets.UTF_8));
} }
} }
} }
......
...@@ -35,6 +35,7 @@ import org.apache.skywalking.apm.plugin.kafka.define.Constants; ...@@ -35,6 +35,7 @@ import org.apache.skywalking.apm.plugin.kafka.define.Constants;
import org.apache.skywalking.apm.plugin.kafka.define.KafkaContext; import org.apache.skywalking.apm.plugin.kafka.define.KafkaContext;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -88,7 +89,7 @@ public class KafkaConsumerInterceptor implements InstanceMethodsAroundIntercepto ...@@ -88,7 +89,7 @@ public class KafkaConsumerInterceptor implements InstanceMethodsAroundIntercepto
next = next.next(); next = next.next();
Iterator<Header> iterator = record.headers().headers(next.getHeadKey()).iterator(); Iterator<Header> iterator = record.headers().headers(next.getHeadKey()).iterator();
if (iterator.hasNext()) { if (iterator.hasNext()) {
next.setHeadValue(new String(iterator.next().value())); next.setHeadValue(new String(iterator.next().value(), StandardCharsets.UTF_8));
} }
} }
ContextManager.extract(contextCarrier); ContextManager.extract(contextCarrier);
......
...@@ -32,6 +32,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceM ...@@ -32,6 +32,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceM
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
public class KafkaProducerInterceptor implements InstanceMethodsAroundInterceptor { public class KafkaProducerInterceptor implements InstanceMethodsAroundInterceptor {
...@@ -57,7 +58,7 @@ public class KafkaProducerInterceptor implements InstanceMethodsAroundIntercepto ...@@ -57,7 +58,7 @@ public class KafkaProducerInterceptor implements InstanceMethodsAroundIntercepto
CarrierItem next = contextCarrier.items(); CarrierItem next = contextCarrier.items();
while (next.hasNext()) { while (next.hasNext()) {
next = next.next(); next = next.next();
record.headers().add(next.getHeadKey(), next.getHeadValue().getBytes()); record.headers().add(next.getHeadKey(), next.getHeadValue().getBytes(StandardCharsets.UTF_8));
} }
//when use lambda expression, not to generate inner class, //when use lambda expression, not to generate inner class,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册