Skip to content

Datastore - call to setNamespace fails under certain Locales  #1957

@sai-pullabhotla

Description

@sai-pullabhotla

When the JVM is running under certain locales (e.g. new Locale("hi", "IN"), the call to setNamespace fails. with the below Exception:

Exception in thread "main" java.lang.ExceptionInInitializerError
	at com.google.cloud.datastore.DatastoreOptions$Builder.setNamespace(DatastoreOptions.java:96)
	at com.example.test.App.main(App.java:21)
Caused by: java.util.regex.PatternSyntaxException: Unclosed counted closure near index 19
[0-9A-Za-z\._\-]{0,१००}
                   ^
	at java.util.regex.Pattern.error(Pattern.java:1955)
	at java.util.regex.Pattern.closure(Pattern.java:3141)
	at java.util.regex.Pattern.sequence(Pattern.java:2134)
	at java.util.regex.Pattern.expr(Pattern.java:1996)
	at java.util.regex.Pattern.compile(Pattern.java:1696)
	at java.util.regex.Pattern.<init>(Pattern.java:1351)
	at java.util.regex.Pattern.compile(Pattern.java:1028)
	at com.google.cloud.datastore.Validator.<clinit>(Validator.java:34)
	... 2 more

Sample Code

public static void main(String[] args) {
  Locale.setDefault(new Locale("hi", "IN")); //Hindi/India
  Datastore datastore = DatastoreOptions.newBuilder().setProjectId("myproject").setNamespace("mynamespace").build().getService();
}

The issue is with the below Pattern in the Validator class:

  private static final Pattern NAMESPACE_PATTERN =
      Pattern.compile(String.format("[0-9A-Za-z\\._\\-]{0,%d}", MAX_NAMESPACE_LENGTH));

String.format uses the JVM's Locale and MAX_NAMESPACE_LENGTH 100 becomes "१००" (equivalent of 100 in Hindi/India Locale), which makes the Pattern invalid.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions