Skip to content

Commit

Permalink
Merge pull request #126 from openzipkin/safe-encoder
Browse files Browse the repository at this point in the history
Fixes unsafe use of CharsetEncoder
  • Loading branch information
adriancole committed Mar 25, 2016
2 parents 94e7365 + d0ddcbb commit 7a50886
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
import zipkin.BinaryAnnotation;
import zipkin.QueryRequest;
import zipkin.Span;
import zipkin.internal.Util;

import static zipkin.internal.Util.UTF_8;

final class CassandraUtil {
static final CharsetEncoder UTF8_ENCODER = Util.UTF_8.newEncoder();
static final ThreadLocal<CharsetEncoder> UTF8_ENCODER = new ThreadLocal<CharsetEncoder>() {
@Override protected CharsetEncoder initialValue() {
return UTF_8.newEncoder();
}
};

/**
* Returns keys that concatenate the serviceName associated with an annotation, a binary
Expand Down Expand Up @@ -84,7 +87,7 @@ private static List<ByteBuffer> toByteBuffers(Collection<String> strings) {
List<ByteBuffer> result = new ArrayList<>(strings.size());
for (String string : strings) {
try {
result.add(UTF8_ENCODER.encode(CharBuffer.wrap(string)));
result.add(UTF8_ENCODER.get().encode(CharBuffer.wrap(string)));
} catch (CharacterCodingException ignored) {
// don't die if the encoding is unknown
}
Expand Down

0 comments on commit 7a50886

Please sign in to comment.