JakeWharton / JakeWharton/timber

Logging generic type as String causes unexpected lint failure

Open
#109 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
10.9k
Forks
994
Avg merge
17h 16m
Merged PRs (30d)
17

Description

Running lint on the following code causes an "unexpected failure."

``` java
public class Foo {

public void logBar(T bar) {
Timber.d("bar: %s", bar);
}
}
```

The error message is:

```
Unexpected failure during lint analysis of Foo.java (this is a bug in lint or one of the libraries it depends on)
EcjParser.equalsCompound(EcjParser.java:2351)->EcjParser$EcjResolvedClass.isSubclassOf(EcjParser.java:1381)->WrongTimberUsageDetector.isSubclassOf(WrongTimberUsageDetector.java:329)->WrongTimberUsageDetector.checkThrowablePosition(WrongTimberUsageDetector.java:448)
```

The failure message goes away if we replace `Timber.d("bar: %s", bar);` with `Timber.d("bar: %s", bar.toString());`. It seems like lint isn't able to recognize the implicit `toString()` method call.

Furthermore, I'm seeing this issue for the Gradle plugin version `1.5.0`. Using the plugin version `1.3.1` also makes the failure message disappear.

Here's an [example app](https://github.com/mattlogan/TimberBug) with this issue.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the failure in the linked TimberBug example app using Gradle plugin 1.5.0 and the Foo.java snippet. Start with the stack trace entries in WrongTimberUsageDetector.checkThrowablePosition and EcjParser.equalsCompound; done means lint completes without an unexpected failure for the generic type passed to Timber.d.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.