Fixed
Status Update
Comments
tn...@google.com <tn...@google.com> #2
Fixed for 3.2 alpha 6 by Change-Id: I33a69b3b48610b1847b93475f0b20bb0c3008f09 .
Lint's testing infrastructure already made sure that test java/kotlin files don't have serious compilation errors in them (which you can override by calling allowCompilationErrors() on the TestLintTask). This was missing for XML; I've added that now. Thanks for the report!
Lint's testing infrastructure already made sure that test java/kotlin files don't have serious compilation errors in them (which you can override by calling allowCompilationErrors() on the TestLintTask). This was missing for XML; I've added that now. Thanks for the report!
Description
I expected the following test to fail:
@Test
fun failLint() {
lint()
.files(
xml(
"res/values/styles.xml",
"""
|<?xml version="1.0" encoding="utf-8"?>
|<resources>
| <style name="TextAppearance">
| <item name="android:lineSpacingMultiplier">1.33</item>
| </style>
|</resources>
|/>
""".trimMargin()
),
xml(
"res/layout/layout.xml",
"""
|<?xml version="1.0" encoding="utf-8"?>
|<TextView
| android:textAppearance="@style/TextAppearance"
|/>
""".trimMargin()
)
)
.issues(ISSUE_STYLE_ITEM)
.run()
.expectClean()
}
but it instead succeeded.
Attaching a debugger and digging into org.apache.xerces.internal.parsers.XML11Configuration#parse(boolean), I entered a catch block and introspected the exception to find: "::::4:3:-1:The prefix "android" for attribute "android:textAppearance" associated with an element type "TextView" is not bound." -- a helpful debugging message.
Unfortunately, this exception is swallowed and ignored in LintCliXmlParser.parseXml(CharSequence, File) returning null. Its caller LintDriver#checkResourceFolder uses this null XmlContext as a sign to stop processing the current xml file and continue on to the next XmlFile in the iterated set (line 1679).
Instead, I would have expected the XML processing to fail, bubbling up to my test and resulting in a failure.