aws-amplify / aws-amplify/amplify-android

NullPointerException on isReadRestrictingStaticGroup when using dynamic group authorization

Open
#1,574 5 comments 3 reactions 0 assignees View on GitHub
api feature-request GraphQL API
Dominant language
Java
Stars
287
Forks
132
Avg merge
2d 2h
Merged PRs (30d)
45

Description

### Before opening, please confirm:

- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-android/issues?q=is%3Aissue+) and [discussions](https://github.com/aws-amplify/amplify-android/discussions).

### Language and Async Model

Kotlin

### Amplify Categories

DataStore

### Gradle script dependencies

I'm not really sure. Dependencies are transient via amplify-flutter.

pubspec.yaml
```
amplify_flutter: ^0.2.8
amplify_api: ^0.2.8
amplify_datastore: ^0.2.8
```

### Environment information

```
Welcome to Gradle 6.7!

Here are the highlights of this release:
- File system watching is ready for production use
- Declare the version of Java your build requires
- Java 15 support

For more details see https://docs.gradle.org/6.7/release-notes.html

------------------------------------------------------------
Gradle 6.7
------------------------------------------------------------

Build time: 2020-10-14 16:13:12 UTC
Revision: 312ba9e0f4f8a02d01854d1ed743b79ed996dfd3

Kotlin: 1.3.72
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM: 1.8.0_302 (Oracle Corporation 25.302-b08)
OS: Linux 5.13.19-2-MANJARO amd64
```

### Please include any relevant guides or documentation you're referencing

https://docs.amplify.aws/cli/graphql-transformer/auth/#dynamic-group-authorization

### Describe the bug

I'm trying to use Datastore via Amplify Flutter on a schema with a dynamic group authorization rule. After configuration the app immediately throws a `NullPointerException` on [`isReadRestrictingStaticGroup`](https://github.com/aws-amplify/amplify-android/blob/5eace8336ab4691cf8257af892dc5f5a87eaf1a2/aws-api/src/main/java/com/amplifyframework/api/aws/auth/AuthRuleRequestDecorator.java#L147). I'm opening the issue in this repo because it seems to be coming from this codebase.

```
W/amplify:aws-datastore(14059): An error occurred on the remote ON_UPDATE subscription for model Todo
W/amplify:aws-datastore(14059): java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.isEmpty()' on a null object reference
W/amplify:aws-datastore(14059): at com.amplifyframework.api.aws.auth.AuthRuleRequestDecorator.isReadRestrictingStaticGroup(AuthRuleRequestDecorator.java:147)
W/amplify:aws-datastore(14059): at com.amplifyframework.api.aws.auth.AuthRuleRequestDecorator.decorate(AuthRuleRequestDecorator.java:103)
W/amplify:aws-datastore(14059): at com.amplifyframework.api.aws.AWSApiPlugin.buildSubscriptionOperation(AWSApiPlugin.java:628)
W/amplify:aws-datastore(14059): at com.amplifyframework.api.aws.AWSApiPlugin.subscribe(AWSApiPlugin.java:308)
W/amplify:aws-datastore(14059): at com.amplifyframework.api.aws.AWSApiPlugin.subscribe(AWSApiPlugin.java:288)
W/amplify:aws-datastore(14059): at com.amplifyframework.api.ApiCategory.subscribe(ApiCategory.java:91)
W/amplify:aws-datastore(14059): at com.amplifyframework.datastore.appsync.AppSyncClient.subscription(AppSyncClient.java:332)
```

### Reproduction steps (if applicable)

_No response_

### Code Snippet

[Repo with minimal repro](https://github.com/ObeA/amplify-flutter-custom-oidc/tree/datastore-issue) (Flutter required)

### Log output

```
I/amplify:flutter:api(14059): Added API plugin
I/amplify:aws-datastore(14059): Creating table: PersistentModelVersion
I/amplify:aws-datastore(14059): Creating table: LastSyncMetadata
I/amplify:aws-datastore(14059): Creating table: Todo
I/amplify:aws-datastore(14059): Creating table: PersistentRecord
I/amplify:aws-datastore(14059): Creating table: ModelMetadata
I/amplify:aws-datastore(14059): Creating index for table: PersistentRecord
I/amplify:flutter:datastore(14059): Unhandled DataStoreHubEvent: SUCCEEDED
I/amplify:flutter:datastore(14059): com.amplifyframework.core.category.CategoryInitializationResult@69374e1
I/amplify:aws-datastore(14059): Orchestrator lock acquired.
I/amplify:aws-datastore(14059): Orchestrator transitioning from STOPPED to SYNC_VIA_API
I/amplify:aws-datastore(14059): Starting to observe local storage changes.
I/amplify:aws-datastore(14059): Now observing local storage. Local changes will be enqueued to mutation outbox.
I/amplify:aws-datastore(14059): Setting currentState to LOCAL_ONLY
I/amplify:aws-datastore(14059): Setting currentState to SYNC_VIA_API
I/amplify:aws-datastore(14059): Starting API synchronization mode.
I/amplify:flutter:datastore(14059): Established a new stream form flutter com.amplifyframework.datastore.storage.sqlite.-$$Lambda$coxN3FV0myAqN-gpZfZvj7bzSOI@bb578af
I/amplify:aws-datastore(14059): Orchestrator lock released.
I/amplify:aws-datastore(14059): Starting processing subscription events.
W/amplify:aws-datastore(14059): An error occurred on the remote ON_UPDATE subscription for model Todo
W/amplify:aws-datastore(14059): java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.isEmpty()' on a null object reference
W/amplify:aws-datastore(14059): at com.amplifyframework.api.aws.auth.AuthRuleRequestDecorator.isReadRestrictingStaticGroup(AuthRuleRequestDecorator.java:147)
W/amplify:aws-datastore(14059): at com.amplifyframework.api.aws.auth.AuthRuleRequestDecorator.decorate(AuthRuleRequestDecorator.java:103)
W/amplify:aws-datastore(14059): at com.amplifyframework.api.aws.AWSApiPlugin.buildSubscriptionOperation(AWSApiPlugin.java:628)
W/amplify:aws-datastore(14059): at com.amplifyframework.api.aws.AWSApiPlugin.subscribe(AWSApiPlugin.java:308)
W/amplify:aws-datastore(14059): at com.amplifyframework.api.aws.AWSApiPlugin.subscribe(AWSApiPlugin.java:288)
W/amplify:aws-datastore(14059): at com.amplifyframework.api.ApiCategory.subscribe(ApiCategory.java:91)
W/amplify:aws-datastore(14059): at com.amplifyframework.datastore.appsync.AppSyncClient.subscription(AppSyncClient.java:332)
```

### amplifyconfiguration.json

```json
{
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"api": {
"plugins": {
"awsAPIPlugin": {
"amplifyoidcissue": {
"endpointType": "GraphQL",
"endpoint": "https://xxxxxx.appsync-api.eu-west-1.amazonaws.com/graphql",
"region": "eu-west-1",
"authorizationType": "OPENID_CONNECT"
}
}
}
}
}
```

### GraphQL Schema

```graphql
type Todo @model @auth(rules: [
{ allow: owner, ownerField: "owner", provider: oidc, identityClaim: "sub" },
{ allow: groups, provider: oidc, groupsField: "groupsCanEdit", groupClaim: "groups", groups: [] },
{ allow: groups, provider: oidc, groupsField: "groupsCanAccess", groupClaim: "groups", operations: [read], groups: [] }
]) {
id: ID!
name: String!
description: String

groupsCanAccess: [String]!
groupsCanEdit: [String]!
owner: String
}
```

### Additional information and screenshots

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in aws-api/src/main/java/com/amplifyframework/api/aws/auth/AuthRuleRequestDecorator.java at isReadRestrictingStaticGroup, following the call from decorate and AWSApiPlugin.buildSubscriptionOperation. Reproduce with the linked Flutter example and the provided Todo schema using dynamic group authorization; done means the subscription no longer throws a NullPointerException.

Written by the indexing model from the issue text.

Assessment

Tech stack
flutter, graphql, java
Domain
api, authentication, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.