Skip to content
Open
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 @@ -65,7 +65,7 @@ public class LocalDatastoreHelper extends BaseEmulatorHelper<DatastoreOptions> {
// Downloadable emulator settings
private static final String BIN_NAME = "cloud-datastore-emulator/cloud_datastore_emulator";
private static final String FILENAME = "cloud-datastore-emulator-" + MIN_VERSION + ".zip";
private static final String MD5_CHECKSUM = "e0d1170519cf52e2e5f9f93892cdf70c";
private static final String MD5_CHECKSUM = "7c1f5a3276241a8f78cb1a837daaaa47";
private static final String BIN_CMD_PORT_FLAG = "--port=";
private static final URL EMULATOR_URL;
private static final String EMULATOR_URL_ENV_VAR = "DATASTORE_EMULATOR_URL";
Expand Down Expand Up @@ -176,7 +176,7 @@ private LocalDatastoreHelper(Builder builder) {
} else {
// At most one of --consistency | --use-firestore-in-datastore-mode can be specified.
// --consistency will be ignored with --use-firestore-in-datastore-mode.
gcloudCommand.add(CONSISTENCY_FLAG + builder.consistency);
gcloudCommand.add(CONSISTENCY_FLAG + getConsistency());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Calling the overridable instance method getConsistency() inside the constructor is risky. If LocalDatastoreHelper is subclassed, the subclass's version of getConsistency() could be invoked before the subclass is fully initialized, which violates the general Java practice of not calling overridable methods in constructors (Effective Java, Item 19). To avoid this, resolve the consistency value directly from the builder using the DEFAULT_CONSISTENCY constant.

Suggested change
gcloudCommand.add(CONSISTENCY_FLAG + getConsistency());
gcloudCommand.add(CONSISTENCY_FLAG + (builder.consistency == 0.0 ? DEFAULT_CONSISTENCY : builder.consistency));

}
if (!builder.storeOnDisk) {
gcloudCommand.add("--no-store-on-disk");
Expand Down
Loading