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

Null check operator used on a null value when parsing ResourceType #3

Open
luis901101 opened this issue Apr 24, 2024 · 0 comments
Open

Comments

@luis901101
Copy link

I'm basically working on my app UI presentation and every time I make a change on how a ListView item would look like and hot-reload it, the FHIR fetch fails with NPE.

This is the stacktrace:

Null check operator used on a null value
#0      Resource.resourceTypeToString (package:fhir/r4/resource/resource.dart:162:36)
#1      enumToString (package:fhir_at_rest/enums/enums_to_string.dart:25:26)
#2      FhirRequest._url.<anonymous closure> (package:fhir_at_rest/r4/fhir_request.dart:1649:32)
#3      _$FhirSearchRequestImpl.map (package:fhir_at_rest/r4/fhir_request.freezed.dart:8821:18)
#4      FhirRequest._url (package:fhir_at_rest/r4/fhir_request.dart:1622:20)
#5      FhirRequest.uri (package:fhir_at_rest/r4/fhir_request.dart:1550:18)
#6      FhirRequest.request.<anonymous closure> (package:fhir_at_rest/r4/fhir_request.dart:1042:19)
#7      _$FhirSearchRequestImpl.map (package:fhir_at_rest/r4/fhir_request.freezed.dart:8821:18)
#8      FhirRequest.request (package:fhir_at_rest/r4/fhir_request.dart:970:69)
#0      Resource.resourceTypeToString (package:fhir/r4/resource/resource.dart:162:36)
#1      enumToString (package:fhir_at_rest/enums/enums_to_string.dart:25:26)
#2      FhirRequest._url.<anonymous closure> (package:fhir_at_rest/r4/fhir_request.dart:1649:32)
#3      _$FhirSearchRequestImpl.map (package:fhir_at_rest/r4/fhir_request.freezed.dart:8821:18)
#4      FhirRequest._url (package:fhir_at_rest/r4/fhir_request.dart:1622:20)
#5      FhirRequest.uri (package:fhir_at_rest/r4/fhir_request.dart:1550:18)
#6      FhirRequest.request.<anonymous closure> (package:fhir_at_rest/r4/fhir_request.dart:1042:19)
#7      _$FhirSearchRequestImpl.map (package:fhir_at_rest/r4/fhir_request.freezed.dart:8821:18)
#8      FhirRequest.request (package:fhir_at_rest/r4/fhir_request.dart:970:69)
.......

Then when I go to the exact class and line that it's pointed (package:fhir/r4/resource/resource.dart:162:36) I've found this:

static String resourceTypeToString(R4ResourceType type) =>
      resourceTypeToStringMap[type]!;

I've checked and that Map contains the Appointment which is the ResourceType I'm fetching and in fact I'm sure of it because before hot-reload it fetches just fine, moreover if I hot-restart it also fetches just fine.

Anyway, that line: resourceTypeToStringMap[type]! and the logic behind it seems a bit tricky, I mean, there is not need to use a Map for parsing an enum to String, it should be enough just to: type.name and also is not recommended at all to use ! when getting a value from a Map.

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

No branches or pull requests

1 participant