google / google/error-prone

[2.4.0] Consider splitting JdkObsolete into individual checks

Open
#1,646 19 comments 6 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

### Description of the problem / feature request:

A few false-positives for `JdkObsolete`.

### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

1)

```java
import java.net.NetworkInterface;

Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
NetworkInterface networkInterface = networkInterfaces.nextElement();
}
```

This gives a `JdkObsolete` warning about `Enumeration`. Well, `NetworkInterface.getNetworkInterfaces` is JDK code, I can't do anything about it. :) ErrorProne should ignore enumerations that come from code that is not mine.

2)

```java
Date someDate = someMethodReturningADate();
Instant instant = someDate.toInstant();
```

The second line (that is calling `toInstant`) is marked with a `JdkObsolete` warning. Well, I'm literally migrating away from a Date at that point so an error should not be triggered I guess. I would think that only `new Date` should be marked as `JdkObsolete` not some random usages of `Date` which I got from somewhere else.

### What version of Error Prone are you using?

2.4.0

### Have you found anything relevant by searching the web?

Nope.

P.S.

3)

```java
import javax.mail.internet.MimeMessage;

MimeMessage message = new MimeMessage(session);
message.setSentDate(new Date());
```

I *have* to pass a Date here, that's what the API expects.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.