RxBonjour icon indicating copy to clipboard operation
RxBonjour copied to clipboard

onServiceLost producing NullPointerException

Open paddykily opened this issue 7 years ago • 5 comments

I have the below code in a background service.

I also tried JmDNSDriver but thats results in the following error W/art: Failed to open zip archive '/system/framework/qcom.fmradio.jar': I/O Error

val rxBonjour = RxBonjour.Builder()
                .platform(AndroidPlatform.create(this))
                .driver(NsdManagerDriver.create(this))
                .create()

val nsdDisposable = rxBonjour.newDiscovery("_octoprint._tcp")
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(
        { event ->
            when(event) {
                is BonjourEvent.Added -> println("Resolved Service: ${event.service}")
                is BonjourEvent.Removed -> println("Lost Service: ${event.service}")
            }
        },
        { error -> println("Error during Discovery: ${error.message}") }
    )
com.robo3d E/AndroidRuntime: FATAL EXCEPTION: NsdManager
                                                            Process: com.robo3d, PID: 10842
                                                            kotlin.KotlinNullPointerException
                                                                at de.mannodermaus.rxbonjour.BonjourService.<init>(Models.kt:27)
                                                                at de.mannodermaus.rxbonjour.drivers.nsdmanager.ExtensionsKt.toLibraryModel(Extensions.kt:36)
                                                                at de.mannodermaus.rxbonjour.drivers.nsdmanager.NsdManagerDiscoveryEngine$NsdDiscoveryListener.onServiceLost(NsdManagerDiscoveryEngine.kt:61)
                                                                at android.net.nsd.NsdManager$ServiceHandler.handleMessage(NsdManager.java:336)
                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                at android.os.Looper.loop(Looper.java:148)
                                                                at android.os.HandlerThread.run(HandlerThread.java:61)

paddykily avatar Oct 23 '17 10:10 paddykily

Thanks for reporting! The only fields expected to be non-null by BonjourService are the service name, type & port. I suspected that this information has to always be there even when a service is lost, but I guess it doesn't. Is this issue reproducible to you? If so, could you place a breakpoint in NsdManagerDiscoveryEngine#L61, just before the call to toLibraryModel() is made? If I can have a look at the properties of that service object, we might be able to figure out which info may not be available to NsdManager at that time.

mannodermaus avatar Oct 23 '17 23:10 mannodermaus

Good day! I have the same issue. Here is stacktrace for NsdManagerDiscoveryEngine#L61: name: SampleName, type: _http._tcp., host: null, port: 0

Kutashov avatar Oct 28 '17 21:10 Kutashov

Thanks for the insight! It probably comes down to the host address of a "lost" Service object not being available. I will examine and push a fix to the next RC shortly.

mannodermaus avatar Oct 28 '17 23:10 mannodermaus

Thank you for this solution! We can just use JmDNS driver for now. However, this driver returns two addresses for me: BonjourService(type=_workstation._tcp.local., name=GoZeroconf, v4Host=/192.168.56.1 BonjourService(type=_workstation._tcp.local., name=GoZeroconf, v4Host=/192.168.1.68 First one is virtualbox adapter. And I have no idea how to make it go without deleting VB or moving to another machine. BTW, it takes some time for the server to be visible in BonjourService. Possibly, because there are no dns entries in a router dns table. And I suppose, we are not capable to affect it.

Kutashov avatar Oct 29 '17 07:10 Kutashov

Have the same isssue with NsdManagerDriver. When use NsdManagerDriver my app just always crashes. There is solution?

SergeyBurlaka avatar Feb 27 '18 09:02 SergeyBurlaka