eclipse-jdt / eclipse-jdt/eclipse.jdt.core

Static import of method from deprecated class does not report a warning

Open
#5,238 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 10h
Merged PRs (30d)
49

Description

This snippet reports a java warning "The type AccessController has been deprecated since version 17 and marked for removal":

```java
import java.security.AccessController;
import java.security.PrivilegedAction;

public class AccessControllerTest {

public static void foo() {
PrivilegedAction x = null;
AccessController.doPrivileged(x);
}
}
```

But this snippet does not do so:

```java
import java.security.PrivilegedAction;

import static java.security.AccessController.doPrivileged;

public class AccessControllerTest2 {

public static void foo() {
PrivilegedAction x = null;
doPrivileged(x);
}
}
```

As far as I understand it, all methods of a `@Deprecated` class are also deprecated.

When compiling with java, this warning is reported:

```
javac src\AccessControllerTest2.java
src\AccessControllerTest2.java:3: warning: [removal] AccessController in java.security has been deprecated and marked for removal
import static java.security.AccessController.doPrivileged;
^
1 warning
```

Here is also a screenshot of the warning for the first sample:

Image

The second sample just renders the deprecated class as strikethrough:

Image

This is a followup to #3921
Maybe related to https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2644 - in this issue, there is the valid argument that you cannot suppress warnings on import statements.

Adding a `@SuppressWarnings("removal")` annotation on the place where the method of the deprecated class is used has no effect - Java compiler still reports the warning. So I assume this is not fixable at all?

Contributor guide

Open the contributing guide

Research direction

Reproduce the two Java snippets and compare JDT's diagnostics with javac, especially for the static import of AccessController.doPrivileged. Read the follow-up in #3921 and the suppression discussion in eclipse.jdt.ui#2644 before tracing the compiler's deprecation-warning path. Done means the static import reports the appropriate warning, with behavior and suppression semantics covered by regression tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.