andriydruk / RxDNSSD

Android version of mDNSResponder
Apache License 2.0
298 stars 75 forks source link

[Bug]: NullPointerException: Null value passed for browser parameter to BrowseListener.serviceFound() #215

Open phatblat opened 2 years ago

phatblat commented 2 years ago

What happened?

Ran across a crash running the Ditto Android test suite. Somehow it appears that a null value is being passed to the serviceFound() method of our anonymous BrowseListener implementation from the RxDNSSD library.

// dnssd: DNSSD?
browseService = dnssd!!.browse("_http-alt._tcp", object : BrowseListener {
    override fun serviceFound(
        browser: DNSSDService, flags: Int, ifIndex: Int,
        serviceName: String, regType: String, domain: String
    ) {
        searchingPrefix?.let { prefix ->
            DittoLog.d(TAG, "mDNS saw service $serviceName")
            // Ignore any _http-alt._tcp peers who are not Ditto. Their announce string comes after the prefix.
            if (!serviceName.startsWith(prefix)) {
                return
            }
            // Ignore ourselves
            if (serviceName == makeServiceNameForPrefix(prefix, announce)) {
                return
            }
            val params = ResolveParameters()
            params.flags = flags
            params.ifIndex = ifIndex
            params.serviceName = serviceName
            params.regType = regType
            params.domain = domain
            val announce = serviceName.substring(prefix.length)
            serviceInfo[announce] = params
            peerAppeared(announce)
        }
    }

    override fun serviceLost(
        browser: DNSSDService, flags: Int, ifIndex: Int,
        serviceName: String, regType: String, domain: String
    ) {
        searchingPrefix?.let { prefix ->
            DittoLog.i(TAG, "mDNS lost service $serviceName")
            if (serviceName.startsWith(prefix)) {
                val announce = serviceName.substring(prefix.length)
                peerDisappeared(announce)
            }
        }
    }

    override fun operationFailed(service: DNSSDService, errorCode: Int) {
        DittoLog.e(TAG, "mDNS browse error: $errorCode")
        browseFailed()
    }
})

Version

0.9.15

What API do you use?

Bindable (recommended)

What device / emulator do you use?

SM-G960U1

What Android API version is on your device?

29

Relevant log output

live.ditto.dittotests.DittoTests > dittoTransportDiagnostics[SM-G960U1 - 10] FAILED
java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter browser
at live.ditto.transports.MdnsPlatform$doStartSearching$1.serviceFound(Unknown Source:2)
Tests on SM-G960U1 - 10 failed: Instrumentation run failed due to 'Process crashed.'

Could you reproduce this issue in samples?