isar / isar/hive

getting an object of the List<T> throws casting exception after hot restart

Open
#234 11 comments 3 reactions 1 assignee Claimed by @simc View on GitHub
problem
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

Because Hive is trying to cast List to a given List a cast exception is happening inside of hive. The workaround is to just fetch a List without supplying the concrete type and then do a cast() or a fromList(). I do think that this is an actual bug as the behaviour for this is different when you just added the data to the cache as opposed to the get after a hot reload. In both cases it should behave the same in my opinion. This is a source of bugs that might go unnoticed at first.

I know that there have been issues reported like this and the response was that this is because of dart limitations however I do feel that this is still a bug and that this is fixable. A possible solution would be (I haven't confirmed this) to use the dart mirrors library (https://api.dart.dev/stable/2.7.1/dart-mirrors/dart-mirrors-library.html) that provides some basic reflection to cover this case.

**Code sample**
```
var box = openBox>("some box name");
box.put("some key", [1, 2, 3]);
box.get("some key"); //This works without an exception

//perform hot restart
var box = openBox>("some box name");
box.get("some key"); //This throws an exception
```

**Version**
- Platform: iOS, Android
- Flutter version: 1.12.13+hotfix.8
- Hive version: 1.4.0+1

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.