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

RealmLog causes IllegalStateException #3928

Closed
ghost opened this issue Dec 19, 2016 · 8 comments
Closed

RealmLog causes IllegalStateException #3928

ghost opened this issue Dec 19, 2016 · 8 comments
Milestone

Comments

@ghost
Copy link

ghost commented Dec 19, 2016

Steps

  1. Run an asynchronous query using Realm
  2. Use the RxJava API (query.asObservable)
  3. Inside of a map operator, check if the RealmObject returned is loaded and is valid

Desired behavior
The boolean checks return true or false and I go about my day.

Encountered behavior
In the case of isValid being false, RealmLog attempts to write this event and calls toString() on the Realm proxy class. This causes an IllegalStateException with the message: Can't access a row that hasn't been loaded or represents 'null', make sure the instance is loaded and is valid by calling 'RealmObject.isLoaded() && RealmObject.isValid()'.

StackTrace

FATAL EXCEPTION: main Process: org.unos.transnet.release, PID: 12048 java.lang.IllegalStateException: Can't access a row that hasn't been loaded or represents 'null', make sure the instance is loaded and is valid by calling 'RealmObject.isLoaded() && RealmObject.isValid()'. at io.realm.internal.Row$1.isNullLink(Row.java:191) at io.realm.ProfileEntityRealmProxy.realmGet$user(ProfileEntityRealmProxy.java:100) at org.unos.ett.api.entity.ProfileEntity.toString(ProfileEntity.java:31) at java.util.Formatter.transform(Formatter.java:1421) at java.util.Formatter.doFormat(Formatter.java:1081) at java.util.Formatter.format(Formatter.java:1042) at java.util.Formatter.format(Formatter.java:1011) at java.lang.String.format(String.java:1554) at java.lang.String.format(String.java:1528) at io.realm.log.RealmLog.log(RealmLog.java:360) at io.realm.log.RealmLog.trace(RealmLog.java:203) at io.realm.log.RealmLog.trace(RealmLog.java:192) at io.realm.HandlerController.completedAsyncRealmObject(HandlerController.java:636) at io.realm.HandlerController.handleMessage(HandlerController.java:131) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Code Sample

realm.where(entityClass)
                .findFirstAsync()
                .asObservable()
                .cast(entityClass)
                .map(new Func1<Entity, Optional<Entity>>() {
            @Override
            public Optional<Entity> call(Entity entity) {
                boolean loaded = entity.load();
                if (loaded && entity.isValid()) {
                    return Optional.of(entity);
                } else {
                    return Optional.absent();
                }
            }
        })
                .first();

Version of Realm and tooling

Realm version(s): 2.1.1

Realm sync feature enabled: no

Android Studio version: 2.2.3

Which Android version and device: Android Emulator, API 23

@Zhuinden
Copy link
Contributor

While this is clearly a bug, what's the point of using findFirstAsync() if you're just going to load it immediately synchronously anyways?

@ghost
Copy link
Author

ghost commented Dec 20, 2016

This is more a proof of concept than anything.

@cmelchior
Copy link
Contributor

Well that is embarrassing. Thanks for the report.

@ghost
Copy link
Author

ghost commented Jan 9, 2017

Any progress on this? Still occurring.

@cmelchior
Copy link
Contributor

We should fix this asap, but might want to verify if it is still happening on #3834

@cmelchior cmelchior added this to the 2.4 milestone Jan 24, 2017
@ghost
Copy link
Author

ghost commented Jan 24, 2017

It doesn't look like there's a snapshot available for the changes you're making in #3834.

@dalinaum
Copy link
Contributor

Since #3834 is still reviewing, the snapshot doesn't include it yet.

@beeender
Copy link
Contributor

#3834 is merged to master. will be fixed in v2.4.0. 2.4.0-SNAPSHOT should be including it now.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants