False import resolution error in TestLintTask?

963 views
Skip to first unread message

John Rodriguez

unread,
Aug 6, 2021, 6:06:51 PM8/6/21
to lint-dev

After bumping the JakeWharton/Timber project to AGP 7.0, we're seeing the following Lint error:

"""
timber.lint.WrongTimberUsageDetectorTest > innerStringFormatWithStaticImport FAILED java.lang.IllegalStateException: app/src/foo/Example.java:3: Error: Couldn't resolve this import [LintError] import static java.lang.String.format; ~~~~~~~~~~~~~~~~~~~~~~~ This usually means that the unit test needs to declare a stub file or placeholder with the expected signature such that type resolving works. If this import is immaterial to the test, either delete it, or mark this unit test as allowing resolution errors by setting `allowCompilationErrors()`. (This check only enforces import references, not all references, so if it doesn't matter to the detector, you can just remove the import but leave references to the class in the code.) For more information, see the "Library Dependencies and Stubs" section in https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-master-dev:lint/docs/api-guide/unit-testing.md.html
"""

when running the Lint Detector tests like so:

./gradlew timber-lint:test

The outlined error makes sense for 3rd-party libraries, like RecyclerView, but shouldn't the JDK or Kotlin standard libs be resolvable by Lint? Or should custom lint authors also stub out those standard lib functions?

For now, we're disabling compilation errors, like so: https://github.com/JakeWharton/timber/blob/master/timber-lint/src/test/java/timber/lint/WrongTimberUsageDetectorTest.kt#L192


Also, filed as https://issuetracker.google.com/issues/195752900 in case this is indeed a bug.

Drew Hannay

unread,
Aug 6, 2021, 7:21:52 PM8/6/21
to lint-dev
It seems like Lint just doesn't understand the static import. I just tried changing it to not use a static import and the test sources are fine and the test can pass without using `allowCompilationErrors` (after adjusting the expected output a bit)

Tor Norbye

unread,
Aug 6, 2021, 7:33:44 PM8/6/21
to Drew Hannay, lint-dev
Yes -- the resolve checker is a new feature and unfortunately didn't account for static imports, but this was fixed a few weeks ago:

The fix is included in 7.1.0-alpha07 which doesn't look like it's out yet but hopefully next week (no promises, things happen and plans change, etc etc etc)

-- Tor

--
You received this message because you are subscribed to the Google Groups "lint-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lint-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lint-dev/c8d0064e-61e7-4e5a-87ee-3305a5a3bc03n%40googlegroups.com.

John Rodriguez

unread,
Aug 6, 2021, 10:24:30 PM8/6/21
to lint-dev
Got it, thanks!

Zac Sweers

unread,
May 21, 2023, 8:53:16 PM5/21/23
to lint-dev
This remains broken in lint 8.2.0 alphas too :/. Filed this https://issuetracker.google.com/issues/283693338
Reply all
Reply to author
Forward
0 new messages