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

PatternSyntaxException: GraphServiceClient constructor fails on Android with sdk 6.x #1851

Closed
slowcar opened this issue Feb 26, 2024 · 2 comments · Fixed by microsoft/kiota-java#1090
Assignees
Labels

Comments

@slowcar
Copy link

slowcar commented Feb 26, 2024

I am trying to update the graph sdk from 5.80.0 to 6.3.0 on Android following the upgrade guide.

When trying to initialize the GraphServiceClient i get an exception.
This is my (simplified) code:

OkHttpClient okHttpClient = new OkHttpClient();
BaseBearerTokenAuthenticationProvider authProvider = new BaseBearerTokenAuthenticationProvider(new AccessTokenProvider() {
	@NonNull
	@Override
	public String getAuthorizationToken(@NonNull URI uri, Map<String, Object> additionalAuthenticationContext) {
		return "";
	}
	@NonNull
	@Override
	public AllowedHostsValidator getAllowedHostsValidator() {
		//list of allowed hosts from AzureIdentityAccessTokenProvider
		return new AllowedHostsValidator("graph.microsoft.com", "graph.microsoft.us", "dod-graph.microsoft.us", "graph.microsoft.de", "microsoftgraph.chinacloudapi.cn", "canary.graph.microsoft.com");
	}
});
GraphServiceClient graphServiceClient = new GraphServiceClient(authProvider, okHttpClient);

Expected behavior

I get a GraphServiceClient instance

Actual behavior

java.util.concurrent.ExecutionException: java.lang.ExceptionInInitializerError[...] Caused by: java.lang.ExceptionInInitializerError at com.microsoft.graph.serviceclient.GraphServiceClient.<init>(GraphServiceClient.java:60) [...] Caused by: java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 11 \{\?[^\}]+} ^ at java.util.regex.Pattern.compileImpl(Native Method) at java.util.regex.Pattern.compile(Pattern.java:1433) at java.util.regex.Pattern.<init>(Pattern.java:1408) at java.util.regex.Pattern.compile(Pattern.java:992) at com.microsoft.kiota.http.OkHttpRequestAdapter.<clinit>(OkHttpRequestAdapter.java:243)

@baywet
Copy link
Member

baywet commented Feb 26, 2024

Thanks for reporting this.
It's interesting the regex compiler behaves differently on Java vs android runtimes.
This is caused by this regex and most likely because the last closing curly is not escaped, and the compiler is looking for an open curly to create a cardinality it's not finding.
PR following soon.

@baywet
Copy link
Member

baywet commented Feb 26, 2024

Pull request submitted #1851

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants