microsoftgraph / msgraph-sdk-java

Microsoft Graph SDK for Java
https://docs.microsoft.com/en-us/graph/sdks/sdks-overview
MIT License
403 stars 134 forks source link

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

Closed slowcar closed 9 months ago

slowcar commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

Pull request submitted https://github.com/microsoftgraph/msgraph-sdk-java/issues/1851