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

pubKeyHash.toJson leads to NullPointerException #521

Closed
sitaram-kalluri opened this issue Feb 21, 2024 · 0 comments · Fixed by #523
Closed

pubKeyHash.toJson leads to NullPointerException #521

sitaram-kalluri opened this issue Feb 21, 2024 · 0 comments · Fixed by #523
Assignees
Labels
bug Something isn't working

Comments

@sitaram-kalluri
Copy link
Member

sitaram-kalluri commented Feb 21, 2024

Describe the bug

In at_client, the monitor connection fails to start with the below exception

WARNING|2024-02-21 10:29:34.818178|Monitor (@alice🛠)|runZonedGuarded received socket error Converting object to an encodable object failed: Instance of 'Metadata' - calling _handleError 

INFO|2024-02-21 10:29:34.818691|Monitor (@alice🛠)|socket.listen onDone called. Will destroy socket, set status stopped, call retryCallback 

INFO|2024-02-21 10:29:34.818936|Monitor (@alice🛠)|Monitor error Converting object to an encodable object failed: Instance of 'Metadata' - calling the retryCallback 

The reason for the above failure is because the Metadata object fails JSON Encode due to the NullPointerException. Attaching the error stack trace

#0      Metadata.toJson (package:at_commons/src/keystore/at_key.dart:687:60)
#1      _defaultToEncodable (dart:convert/json.dart:627:55)
#2      _JsonStringifier.writeObject (dart:convert/json.dart:787:36)
#3      _JsonStringifier.writeMap (dart:convert/json.dart:874:7)
#4      _JsonStringifier.writeJsonValue (dart:convert/json.dart:829:21)
#5      _JsonStringifier.writeObject (dart:convert/json.dart:784:9)
#6      _JsonStringStringifier.printOn (dart:convert/json.dart:982:17)
#7      _JsonStringStringifier.stringify (dart:convert/json.dart:967:5)
#8      JsonEncoder.convert (dart:convert/json.dart:345:30)
#9      JsonCodec.encode (dart:convert/json.dart:231:45)
#10     jsonEncode (dart:convert/json.dart:114:10)
#11     NotificationServiceImpl._internalNotificationCallback (package:at_client/src/service/notification_service_impl.dart:236:15)
<asynchronous suspension>

Below condition in at_key.dart is the root cause the above mentioned exceptions. The default value of fullJson is true. Since fullJson is true and the condtion is "OR", even if pubKeyHash is "NULL", the control still enters into IF condition and toJson() is invoked on NULL object leading to the above exceptions.

if (fullJson || pubKeyHash != null) {
      map[AtConstants.sharedWithPublicKeyHash] = pubKeyHash!.toJson();
    }

Steps to reproduce

  1. Point at_commons version to 4.0.2
  2. Run the tests related to monitor connection.
  3. For instance: test/enrollment_test.dart: A test to verify enrollment request returns notification in at_client functional test.

Expected behavior

The Monitor connection should be started successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants