'Why doesn't javac produce a warning when using a deprecated constructor of a parameterized type?

Say you have a parameterized class with a deprecated constructor, and a User class that calls this constructor. In the example below, using the diamond operator, javac (version 11.0.11) does not produce a deprecation warning:

class DepTester<T> {
    T t;

    @Deprecated
    public DepTester(T t) {
        this.t = t;
    }
}

class User {
    DepTester<String> tester = new DepTester<>("This does not produce a warning!");
}

However, with an explicit type argument in the constructor call, the warning is issued:

class User {
    DepTester<String> tester = new DepTester<String>("This produces a warning.");
}

[WARNING] DepTester.java:[17,40] DepTester(T) in com.foo.DepTester has been deprecated

The explicit type argument is normally not included, which IntelliJ inspection also warns about:

Explicit type argument String can be replaced with <>

I can't find an explanation for this behaviour in the Java language spec. I tried with javac 17, and it produces a warning in both cases, so is this a bug in javac 11?

EDIT: My bug report to Oracle was assigned an ID in the Java bug database: JDK-8281107



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source