private fun crawlSingleIndexableResource(indexableFragment: IndexableFragment): List<PreferenceIndex>? { val indexablePreferences: MutableList<PreferenceIndex> = ArrayList() val parser: XmlPullParser = mContext.getResources().getXml(indexableFragment.xmlRes) var type: Int try { while (parser.next().also { type = it } != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) { } var nodeName = parser.name if (!NODE_NAME_PREFERENCE_SCREEN.equals(nodeName)) { throw RuntimeException("XML document must start with <PreferenceScreen> tag; found" + nodeName + " at " + parser.positionDescription) } val outerDepth = parser.depth val attrs: AttributeSet = Xml.asAttributeSet(parser) while (parser.next().also { type = it } != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.depth > outerDepth)) { if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { continue } nodeName = parser.name val key: String = PreferenceXmlUtil.getDataKey(mContext, attrs) val title: String = PreferenceXmlUtil.getDataTitle(mContext, attrs) if (NODE_NAME_PREFERENCE_CATEGORY.equals(nodeName) || TextUtils.isEmpty(key) || TextUtils.isEmpty( title ) ) { Continue } val indexablePreference = PreferenceIndex(key, title, indexableFragment.fragmentName) indexablePreferences.add(indexablePreference) } } catch (ex: XmlPullParserException) { Log.e(TAG, "Error in parsing a preference xml file, skip it", ex)
        } catch (ex: IOException) { Log.e(TAG, "Error in parsing a preference xml file, skip it", ex) } catch (ex: ReflectiveOperationException) { Log.e(TAG, "Error in parsing a preference xml file, skip it", ex) } return indexablePreferences }
Generate an explicit null check ( compare to zero ) .