Skip to content

Commit 4336bf6

Browse files
committed
Change some error messages to format with Locale.ROOT
The Assert utility used for checking conditions and throwing exceptions was using the default locale, causing the message to change based on the default locale for the JVM. This caused SchemaTemplateSerDeTests to fail in the nightly build. This resolves: #3247
1 parent 2d5235a commit 4336bf6

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

fdb-relational-api/src/main/java/com/apple/foundationdb/relational/util/Assert.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
package com.apple.foundationdb.relational.util;
2222

2323
import com.apple.foundationdb.annotation.API;
24-
2524
import com.apple.foundationdb.relational.api.exceptions.ErrorCode;
26-
import com.apple.foundationdb.relational.api.exceptions.UncheckedRelationalException;
2725
import com.apple.foundationdb.relational.api.exceptions.RelationalException;
26+
import com.apple.foundationdb.relational.api.exceptions.UncheckedRelationalException;
2827

2928
import javax.annotation.Nonnull;
29+
import java.util.Locale;
3030
import java.util.function.Supplier;
3131

3232
/**
@@ -58,13 +58,13 @@ public static void that(boolean mustBeTrue, @Nonnull final ErrorCode errorCodeIf
5858

5959
public static void that(boolean mustBeTrue, @Nonnull final ErrorCode errorCodeIfNotTrue, @Nonnull final String messageFormat, @Nonnull Object messageValue) throws RelationalException {
6060
if (!mustBeTrue) {
61-
throw new RelationalException(String.format(messageFormat, messageValue), errorCodeIfNotTrue);
61+
throw new RelationalException(String.format(Locale.ROOT, messageFormat, messageValue), errorCodeIfNotTrue);
6262
}
6363
}
6464

6565
public static void that(boolean mustBeTrue, @Nonnull final ErrorCode errorCodeIfNotTrue, @Nonnull final String messageFormat, @Nonnull Object messageValue1, @Nonnull Object messageValue2) throws RelationalException {
6666
if (!mustBeTrue) {
67-
throw new RelationalException(String.format(messageFormat, messageValue1, messageValue2), errorCodeIfNotTrue);
67+
throw new RelationalException(String.format(Locale.ROOT, messageFormat, messageValue1, messageValue2), errorCodeIfNotTrue);
6868
}
6969
}
7070

@@ -132,13 +132,13 @@ public static void thatUnchecked(boolean mustBeTrue, @Nonnull final ErrorCode er
132132

133133
public static void thatUnchecked(boolean mustBeTrue, @Nonnull final ErrorCode errorCodeIfNotTrue, @Nonnull final String messageTemplate, @Nonnull final Object messageValue) {
134134
if (!mustBeTrue) {
135-
throw new RelationalException(String.format(messageTemplate, messageValue), errorCodeIfNotTrue).toUncheckedWrappedException();
135+
throw new RelationalException(String.format(Locale.ROOT, messageTemplate, messageValue), errorCodeIfNotTrue).toUncheckedWrappedException();
136136
}
137137
}
138138

139139
public static void thatUnchecked(boolean mustBeTrue, @Nonnull final ErrorCode errorCodeIfNotTrue, @Nonnull final String messageTemplate, @Nonnull final Object messageValue1, @Nonnull final Object messageValue2) {
140140
if (!mustBeTrue) {
141-
throw new RelationalException(String.format(messageTemplate, messageValue1, messageValue2), errorCodeIfNotTrue).toUncheckedWrappedException();
141+
throw new RelationalException(String.format(Locale.ROOT, messageTemplate, messageValue1, messageValue2), errorCodeIfNotTrue).toUncheckedWrappedException();
142142
}
143143
}
144144

@@ -168,7 +168,7 @@ public static <T> T notNullUnchecked(T object, @Nonnull final ErrorCode errorCod
168168

169169
public static <T> T notNullUnchecked(T object, @Nonnull final ErrorCode errorCodeIfNull, @Nonnull final String messageTemplate, @Nonnull final Object messageValue) {
170170
if (object == null) {
171-
throw new RelationalException(String.format(messageTemplate, messageValue), errorCodeIfNull).toUncheckedWrappedException();
171+
throw new RelationalException(String.format(Locale.ROOT, messageTemplate, messageValue), errorCodeIfNull).toUncheckedWrappedException();
172172
} else {
173173
return object;
174174
}

fdb-relational-core/src/test/java/com/apple/foundationdb/relational/recordlayer/metadata/SchemaTemplateSerDeTests.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.apple.foundationdb.relational.api.exceptions.UncheckedRelationalException;
3030
import com.apple.foundationdb.relational.api.metadata.DataType;
3131
import com.google.protobuf.DescriptorProtos;
32+
import org.hamcrest.MatcherAssert;
33+
import org.hamcrest.Matchers;
3234
import org.junit.jupiter.api.Assertions;
3335
import org.junit.jupiter.api.Test;
3436
import org.junit.jupiter.params.ParameterizedTest;
@@ -260,7 +262,7 @@ public void testBadSchemaTemplateGenerations(Map<String, List<NonnullPair<Intege
260262
final var schemaTemplate = getTestRecordLayerSchemaTemplate(testcase);
261263
schemaTemplate.toRecordMetadata();
262264
});
263-
Assertions.assertTrue(thrown.getMessage().contains(message));
265+
MatcherAssert.assertThat(thrown.getMessage(), Matchers.containsString(message));
264266
}
265267

266268
@Test

0 commit comments

Comments
 (0)