realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.45k stars 1.75k forks source link

Exception when socket address is null. #7828

Closed molind closed 1 year ago

molind commented 1 year ago

Received an exception from realm-java during Realm.getInstance(configuration):

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.net.InetAddress.getHostName()' on a null object reference.

Probably, it's here: https://github.com/realm/realm-java/blob/main/realm/realm-library/src/main/java/io/realm/internal/OsRealmConfig.java#L387

Maybe it should continue to work as if it's offline in this case.

molind commented 1 year ago

I've added exception handler in my code to catch it with a full stack. But since there is only 1 function with getHostName() in all realm-java it should be there.

clementetb commented 1 year ago

Hi, this piece of code is triggered whenever the device has setup a proxy.

Do you have more information about this proxy setup? What device model is triggering the crash? What Android version is it running? Can you reproduce locally?

molind commented 1 year ago

@clementetb I can't reproduce it locally, it's from our sentry reports. Happened on device 2201116SG (Redmi Note 11 Pro), Android 12 without root. Realm-java version 10.15.1.

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.net.InetAddress.getHostName()' on a null object reference
    at io.realm.internal.OsRealmConfig.getHostString(SourceFile:386)
    at io.realm.internal.OsRealmConfig.<init>(SourceFile:362)
    at io.realm.internal.OsRealmConfig.<init>(SourceFile:41)
    at io.realm.internal.OsRealmConfig$Builder.build
    at io.realm.RealmCache.doCreateRealmOrGetFromCache(SourceFile:443)
    at io.realm.RealmCache.createRealmOrGetFromCache
    at io.realm.Realm.getInstance(SourceFile:464)
clementetb commented 1 year ago

@molind would you mind trying the latest snapshot 10.16.2-SNAPSHOT, it includes a fix for the issue.