Realm-java: RealmList<Date> has invalid size value

Created on 10 Oct 2017  路  10Comments  路  Source: realm/realm-java

I have used RealmList for Date object and I have faced a problem with size value. In my case in debbuger I can see only 4 items but size() method shows 5. Because of that loop isn't working correctly.

Please look on attached screenshot.
zrzut ekranu 2017-10-10 o 22 24 09

Version of Realm and tooling

Realm version(s): 4.0.0-RC1

Realm sync feature enabled: no

Android Studio version: 2.3.3

Which Android version and device: 6.0

T-Help

Most helpful comment

image

null values are hidden by default. Really strange default setting if you ask me 馃槥

All 10 comments

Any chance that the date at index 4 is null?

Or does it throw IndexOutOfBoundsException?

Can you please verify getStartDates().get(4) in debugger?

It is null.

But if there is a null item at index[4], size() == 5 is correct? We have unit tests showing this behaviour: https://github.com/realm/realm-java/blob/master/realm/realm-library/src/androidTest/java/io/realm/ManagedRealmListForValueTests.java#L474

@kumien are you sure you never manually inserted null as a parameter in that list?

@cmelchior I didn't realize you can store nulls in primitive lists, is it possible to make a primitive list store only non-null values with @Required?

@Zhuinden Yes, by using @Required, the primitive list will only store non-null values.

Whole object was parsed from json and there wasn't null value. Even if I will add null value to list then it should be visible in the list. Otherwise size() method has to inform how much items we have in the list.

Not sure what you mean by it being "visible in the list"? The Android debugger apparently doesn't show null values in lists (I don't know if that is a setting somewhere), but that isn't Java's problem. If you call list.get(4) you correctly get null back, making the size 5.

But if there is a bug in how we import list data we want to get that fixed as soon as possible. Do you have the data and import code that shows this happening?

Android debugger doesn't show null as last element of list automatically, I ran into this before while debugging FragmentManager-related things where instead of just removing the fragment, they set its index to null.

image

null values are hidden by default. Really strange default setting if you ask me 馃槥

@kumien I assume the above answered your question, if not feel free to reopen.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Frasprite picture Frasprite  路  3Comments

mithrann picture mithrann  路  3Comments

harshvishu picture harshvishu  路  3Comments

Merlin1993 picture Merlin1993  路  3Comments

wyvern610 picture wyvern610  路  3Comments