Skip to content

Commit 6d7b133

Browse files
committed
Merge pull request aeron-io#319 from DevFactory/release/reliance-on-default-encoding-fix-1
Classes and methods that rely on default system encoding should not be used
2 parents 32623fa + a8984c8 commit 6d7b133

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

sbe-samples/src/main/java/uk/co/real_logic/sbe/examples/ExampleUsingGeneratedStub.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.UnsupportedEncodingException;
2424
import java.nio.ByteBuffer;
2525
import java.nio.channels.FileChannel;
26+
import java.nio.charset.Charset;
2627

2728
public class ExampleUsingGeneratedStub
2829
{
@@ -154,7 +155,7 @@ public static int encode(final CarEncoder car, final UnsafeBuffer directBuffer,
154155
.next().mph(60).seconds(7.1f)
155156
.next().mph(100).seconds(11.8f);
156157

157-
car.make(new String(MAKE));
158+
car.make(new String(MAKE, Charset.forName("UTF-8")));
158159
car.putModel(MODEL, srcOffset, MODEL.length);
159160
car.putActivationCode(ACTIVATION_CODE, 0, ACTIVATION_CODE.capacity());
160161

@@ -239,7 +240,7 @@ public static void decode(
239240

240241
final UnsafeBuffer tempBuffer = new UnsafeBuffer(buffer);
241242
final int tempBufferLength = car.getActivationCode(tempBuffer, 0, tempBuffer.capacity());
242-
sb.append("\ncar.activationCode=").append(new String(buffer, 0, tempBufferLength));
243+
sb.append("\ncar.activationCode=").append(new String(buffer, 0, tempBufferLength, Charset.forName("UTF-8")));
243244

244245
sb.append("\ncar.encodedLength=").append(car.encodedLength());
245246

sbe-samples/src/main/java/uk/co/real_logic/sbe/examples/ExampleUsingGeneratedStubExtension.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.UnsupportedEncodingException;
2323
import java.nio.ByteBuffer;
2424
import java.nio.channels.FileChannel;
25+
import java.nio.charset.Charset;
2526

2627
import static extension.CarEncoder.cupHolderCountNullValue;
2728

@@ -247,7 +248,7 @@ public static void decode(
247248

248249
final UnsafeBuffer tempBuffer = new UnsafeBuffer(buffer);
249250
final int tempBufferLength = car.getActivationCode(tempBuffer, 0, tempBuffer.capacity());
250-
sb.append("\ncar.activationCode=").append(new String(buffer, 0, tempBufferLength));
251+
sb.append("\ncar.activationCode=").append(new String(buffer, 0, tempBufferLength, Charset.forName("UTF-8")));
251252

252253
sb.append("\ncar.encodedLength=").append(car.encodedLength());
253254

sbe-tool/src/main/java/uk/co/real_logic/sbe/PrimitiveValue.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.UnsupportedEncodingException;
1919
import java.math.BigInteger;
20+
import java.nio.charset.Charset;
2021
import java.util.Arrays;
2122

2223
import static java.lang.Double.doubleToLongBits;
@@ -154,7 +155,7 @@ public static PrimitiveValue parse(final String value, final PrimitiveType primi
154155
{
155156
throw new IllegalArgumentException("Constant char value malformed: " + value);
156157
}
157-
return new PrimitiveValue((long)value.getBytes()[0], 1);
158+
return new PrimitiveValue((long)value.getBytes(Charset.forName("UTF-8"))[0], 1);
158159

159160
case INT8:
160161
return new PrimitiveValue(Byte.parseByte(value), 1);

0 commit comments

Comments
 (0)