You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2020/09/30 15:31:55 UTC

[skywalking] branch muse-bug-bash/Defaultcharset created (now 84ccd99)

This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a change to branch muse-bug-bash/Defaultcharset
in repository https://gitbox.apache.org/repos/asf/skywalking.git.


      at 84ccd99  Use explicit charset instead of default charset

This branch includes the following new commits:

     new 84ccd99  Use explicit charset instead of default charset

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[skywalking] 01/01: Use explicit charset instead of default charset

Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch muse-bug-bash/Defaultcharset
in repository https://gitbox.apache.org/repos/asf/skywalking.git

commit 84ccd994c1c083d846b297e0aa72500a1cc2309f
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Wed Sep 30 23:31:15 2020 +0800

    Use explicit charset instead of default charset
    
    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.
---
 .../org/apache/skywalking/apm/plugin/avro/SWClientRPCPlugin.java     | 3 ++-
 .../org/apache/skywalking/apm/plugin/avro/SWServerRPCPlugin.java     | 3 ++-
 .../org/apache/skywalking/apm/plugin/hbase/HTableInterceptor.java    | 5 +++--
 .../apache/skywalking/apm/plugin/kafka/KafkaConsumerInterceptor.java | 3 ++-
 .../apache/skywalking/apm/plugin/kafka/KafkaProducerInterceptor.java | 3 ++-
 5 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/apm-sniffer/apm-sdk-plugin/avro-plugin/src/main/java/org/apache/skywalking/apm/plugin/avro/SWClientRPCPlugin.java b/apm-sniffer/apm-sdk-plugin/avro-plugin/src/main/java/org/apache/skywalking/apm/plugin/avro/SWClientRPCPlugin.java
index 70d08db..0af6d0d 100644
--- a/apm-sniffer/apm-sdk-plugin/avro-plugin/src/main/java/org/apache/skywalking/apm/plugin/avro/SWClientRPCPlugin.java
+++ b/apm-sniffer/apm-sdk-plugin/avro-plugin/src/main/java/org/apache/skywalking/apm/plugin/avro/SWClientRPCPlugin.java
@@ -25,6 +25,7 @@ import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
 import org.apache.skywalking.apm.agent.core.context.ContextManager;
 
 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.
@@ -39,7 +40,7 @@ public class SWClientRPCPlugin extends RPCPlugin {
         CarrierItem items = carrier.items();
         while (items.hasNext()) {
             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)));
         }
     }
 
diff --git a/apm-sniffer/apm-sdk-plugin/avro-plugin/src/main/java/org/apache/skywalking/apm/plugin/avro/SWServerRPCPlugin.java b/apm-sniffer/apm-sdk-plugin/avro-plugin/src/main/java/org/apache/skywalking/apm/plugin/avro/SWServerRPCPlugin.java
index d4014ed..41f6cf5 100644
--- a/apm-sniffer/apm-sdk-plugin/avro-plugin/src/main/java/org/apache/skywalking/apm/plugin/avro/SWServerRPCPlugin.java
+++ b/apm-sniffer/apm-sdk-plugin/avro-plugin/src/main/java/org/apache/skywalking/apm/plugin/avro/SWServerRPCPlugin.java
@@ -19,6 +19,7 @@
 package org.apache.skywalking.apm.plugin.avro;
 
 import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
 import java.util.Map;
 import org.apache.avro.ipc.RPCContext;
 import org.apache.avro.ipc.RPCPlugin;
@@ -50,7 +51,7 @@ public class SWServerRPCPlugin extends RPCPlugin {
         while (items.hasNext()) {
             items = items.next();
             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();
diff --git a/apm-sniffer/apm-sdk-plugin/hbase-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTableInterceptor.java b/apm-sniffer/apm-sdk-plugin/hbase-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTableInterceptor.java
index cf3fdbe..6e96eb2 100644
--- a/apm-sniffer/apm-sdk-plugin/hbase-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTableInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/hbase-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTableInterceptor.java
@@ -37,6 +37,7 @@ import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -74,10 +75,10 @@ public class HTableInterceptor implements InstanceMethodsAroundInterceptor, Inst
             while (next.hasNext()) {
                 next = next.next();
                 if (operation != null) {
-                    operation.setAttribute(next.getHeadKey(), next.getHeadValue().getBytes());
+                    operation.setAttribute(next.getHeadKey(), next.getHeadValue().getBytes(StandardCharsets.UTF_8));
                 } else {
                     for (OperationWithAttributes o : operations) {
-                        o.setAttribute(next.getHeadKey(), next.getHeadValue().getBytes());
+                        o.setAttribute(next.getHeadKey(), next.getHeadValue().getBytes(StandardCharsets.UTF_8));
                     }
                 }
             }
diff --git a/apm-sniffer/apm-sdk-plugin/kafka-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/KafkaConsumerInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/KafkaConsumerInterceptor.java
index 4c70c00..ed5e566 100644
--- a/apm-sniffer/apm-sdk-plugin/kafka-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/KafkaConsumerInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/kafka-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/KafkaConsumerInterceptor.java
@@ -35,6 +35,7 @@ import org.apache.skywalking.apm.plugin.kafka.define.Constants;
 import org.apache.skywalking.apm.plugin.kafka.define.KafkaContext;
 
 import java.lang.reflect.Method;
+import java.nio.charset.StandardCharsets;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -88,7 +89,7 @@ public class KafkaConsumerInterceptor implements InstanceMethodsAroundIntercepto
                         next = next.next();
                         Iterator<Header> iterator = record.headers().headers(next.getHeadKey()).iterator();
                         if (iterator.hasNext()) {
-                            next.setHeadValue(new String(iterator.next().value()));
+                            next.setHeadValue(new String(iterator.next().value(), StandardCharsets.UTF_8));
                         }
                     }
                     ContextManager.extract(contextCarrier);
diff --git a/apm-sniffer/apm-sdk-plugin/kafka-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/KafkaProducerInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/KafkaProducerInterceptor.java
index 7a00a15..0eddc3e 100644
--- a/apm-sniffer/apm-sdk-plugin/kafka-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/KafkaProducerInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/kafka-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/KafkaProducerInterceptor.java
@@ -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.network.trace.component.ComponentsDefine;
 import java.lang.reflect.Method;
+import java.nio.charset.StandardCharsets;
 
 public class KafkaProducerInterceptor implements InstanceMethodsAroundInterceptor {
 
@@ -57,7 +58,7 @@ public class KafkaProducerInterceptor implements InstanceMethodsAroundIntercepto
         CarrierItem next = contextCarrier.items();
         while (next.hasNext()) {
             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,