Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove string format #3048

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.apple.foundationdb.relational.api.exceptions.RelationalException;

import javax.annotation.Nonnull;
import java.util.Locale;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -58,13 +59,13 @@ public static void that(boolean mustBeTrue, @Nonnull final ErrorCode errorCodeIf

public static void that(boolean mustBeTrue, @Nonnull final ErrorCode errorCodeIfNotTrue, @Nonnull final String messageFormat, @Nonnull Object messageValue) throws RelationalException {
if (!mustBeTrue) {
throw new RelationalException(String.format(messageFormat, messageValue), errorCodeIfNotTrue);
throw new RelationalException(String.format(Locale.ROOT, messageFormat, messageValue), errorCodeIfNotTrue);
}
}

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

Expand Down Expand Up @@ -132,13 +133,13 @@ public static void thatUnchecked(boolean mustBeTrue, @Nonnull final ErrorCode er

public static void thatUnchecked(boolean mustBeTrue, @Nonnull final ErrorCode errorCodeIfNotTrue, @Nonnull final String messageTemplate, @Nonnull final Object messageValue) {
if (!mustBeTrue) {
throw new RelationalException(String.format(messageTemplate, messageValue), errorCodeIfNotTrue).toUncheckedWrappedException();
throw new RelationalException(String.format(Locale.ROOT, messageTemplate, messageValue), errorCodeIfNotTrue).toUncheckedWrappedException();
}
}

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

Expand Down Expand Up @@ -168,7 +169,7 @@ public static <T> T notNullUnchecked(T object, @Nonnull final ErrorCode errorCod

public static <T> T notNullUnchecked(T object, @Nonnull final ErrorCode errorCodeIfNull, @Nonnull final String messageTemplate, @Nonnull final Object messageValue) {
if (object == null) {
throw new RelationalException(String.format(messageTemplate, messageValue), errorCodeIfNull).toUncheckedWrappedException();
throw new RelationalException(String.format(Locale.ROOT, messageTemplate, messageValue), errorCodeIfNull).toUncheckedWrappedException();
} else {
return object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,17 @@ public void saveSchema(@Nonnull final Transaction txn, @Nonnull final Schema sch
if (createDatabaseIfNecessary) {
createDatabase(recordStore, URI.create(schema.getDatabaseName()));
} else {
throw new RelationalException(String.format("Cannot create schema %s because database %s does not exist.", schema.getName(), schema.getDatabaseName()),
throw new RelationalException("Cannot create schema " + schema.getName() + " because database " + schema.getDatabaseName() + " does not exist.",
ErrorCode.UNDEFINED_DATABASE);
}
}
Assert.that(schema instanceof RecordLayerSchema, ErrorCode.UNDEFINED_SCHEMA, "Unexpected schema type %s", schema.getClass());
Assert.that(schemaTemplateCatalog.doesSchemaTemplateExist(txn, schema.getSchemaTemplate().getName(),
schema.getSchemaTemplate().getVersion()),
ErrorCode.UNKNOWN_SCHEMA_TEMPLATE,
() -> String.format("Cannot create schema %s because schema template %s version %d does not exist.",
schema.getName(), schema.getSchemaTemplate().getName(),
schema.getSchemaTemplate().getVersion()));
() -> "Cannot create schema " + schema.getName() + " because schema template " +
schema.getSchemaTemplate().getName() + " version " +
schema.getSchemaTemplate().getVersion() + " does not exist.");
try {
putSchema((RecordLayerSchema) schema, recordStore);
} catch (RecordCoreException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void queryFromSharedExtent() throws SQLException {
}

for (int group = 0; group < groupCount; group++) {
try (RelationalResultSet resultSet = statement.executeQuery(String.format("SELECT * FROM t1 WHERE group = %d", group))) {
try (RelationalResultSet resultSet = statement.executeQuery("SELECT * FROM t1 WHERE group = " + group)) {
ResultSetAssert.assertThat(resultSet).containsRowsExactly(List.of(
new Object[]{group, "t1_0", 0},
new Object[]{group, "t1_1", 10},
Expand Down