Skip to content

Deprecation warnings incompletely controlled by compiler preferences #4562

@iloveeclipse

Description

@iloveeclipse

In the light of #4553 I've tried to construct a simple exmaple to understand which differences we have before / after the fix 545483d / #4293 with previous ecj version and with latest javac from Java 25.

Consider following code (in 3 different files, this is important for ecj):

package c;
@Deprecated
public class OldClass {
//  @Deprecated
    public void foo() {
    }
//  @Deprecated
    public void bar() {
    }
}
package c;
public class ExtendsOldClass extends OldClass {
	@Override
	public void foo() {
		super.foo();
	}
	public void callingFoo() {
		super.foo();
	}
	public void callingBar() {
		bar();
	}
}
package c;
public class UseOldClass {
	public void callingFoo() {
		new ExtendsOldClass().foo();
		new OldClass().foo();
	}
	public void callingBar() {
		new ExtendsOldClass().bar();
		new OldClass().bar();
	}
}

javac reports 3 warnings

javac -d /tmp/testcompile --release 17 -Xlint:deprecation  /data/workspaces/aloskuto-bf/Deprecation/src/c/*.java 
/data/workspaces/aloskuto-bf/Deprecation/src/c/ExtendsOldClass.java:2: warning: [deprecation] OldClass in c has been deprecated
public class ExtendsOldClass extends OldClass {
                                     ^
/data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java:5: warning: [deprecation] OldClass in c has been deprecated
                new OldClass().foo();
                    ^
/data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java:9: warning: [deprecation] OldClass in c has been deprecated
                new OldClass().bar();
                    ^
3 warnings

ecj latest (9 ! warnings with/without explicit -warn:+deprecation )

java -jar ~/Downloads/ecj-I20251026-1800.jar -d /tmp/testcompile --release 17 -warn:+deprecation /data/workspaces/aloskuto-bf/Deprecation/src/c/*.java
----------
1. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/ExtendsOldClass.java (at line 2)
        public class ExtendsOldClass extends OldClass {
                                             ^^^^^^^^
The type OldClass is deprecated
----------
2. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/ExtendsOldClass.java (at line 5)
        super.foo();
              ^^^
The method foo() from the type OldClass is deprecated
----------
3. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/ExtendsOldClass.java (at line 8)
        super.foo();
              ^^^
The method foo() from the type OldClass is deprecated
----------
----------
4. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 5)
        new OldClass().foo();
            ^^^^^^^^
The type OldClass is deprecated
----------
5. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 5)
        new OldClass().foo();
            ^^^^^^^^
The constructor OldClass() is deprecated
----------
6. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 5)
        new OldClass().foo();
                       ^^^
The method foo() from the type OldClass is deprecated
----------
7. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 9)
        new OldClass().bar();
            ^^^^^^^^
The type OldClass is deprecated
----------
8. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 9)
        new OldClass().bar();
            ^^^^^^^^
The constructor OldClass() is deprecated
----------
9. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 9)
        new OldClass().bar();
                       ^^^
The method bar() from the type OldClass is deprecated
----------
9 problems (9 warnings)

ecj latest (10 ! warnings with project settings)

org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
java -jar ~/Downloads/ecj-I20251026-1800.jar -d /tmp/testcompile --release 17 -properties /data/workspaces/aloskuto-bf/Deprecation/.settings/org.eclipse.jdt.core.prefs /data/workspaces/aloskuto-bf/Deprecation/src/c/*.java
----------
1. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/ExtendsOldClass.java (at line 2)
        public class ExtendsOldClass extends OldClass {
                                             ^^^^^^^^
The type OldClass is deprecated
----------
2. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/ExtendsOldClass.java (at line 4)
        public void foo() {
                    ^^^^^
The method ExtendsOldClass.foo() overrides a deprecated method from OldClass
----------
3. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/ExtendsOldClass.java (at line 5)
        super.foo();
              ^^^
The method foo() from the type OldClass is deprecated
----------
4. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/ExtendsOldClass.java (at line 8)
        super.foo();
              ^^^
The method foo() from the type OldClass is deprecated
----------
----------
5. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 5)
        new OldClass().foo();
            ^^^^^^^^
The type OldClass is deprecated
----------
6. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 5)
        new OldClass().foo();
            ^^^^^^^^
The constructor OldClass() is deprecated
----------
7. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 5)
        new OldClass().foo();
                       ^^^
The method foo() from the type OldClass is deprecated
----------
8. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 9)
        new OldClass().bar();
            ^^^^^^^^
The type OldClass is deprecated
----------
9. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 9)
        new OldClass().bar();
            ^^^^^^^^
The constructor OldClass() is deprecated
----------
10. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 9)
        new OldClass().bar();
                       ^^^
The method bar() from the type OldClass is deprecated
----------
10 problems (10 warnings)

Note, switching deprecation warnings in project settings off via

org.eclipse.jdt.core.compiler.problem.deprecation=disabled
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled

doesn't produce expected effect except one warning less is reported :-(

Before the 545483d / #4293 ecj reported 12 warnings (so the fix only changed 2 from 12 warnings)

java -jar ~/Downloads/ecj-I20251024-0020.jar -d /tmp/testcompile --release 17 -properties /data/workspaces/aloskuto-bf/Deprecation/.settings/org.eclipse.jdt.core.prefs /data/workspaces/aloskuto-bf/Deprecation/src/c/*.java
----------
1. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/ExtendsOldClass.java (at line 2)
        public class ExtendsOldClass extends OldClass {
                                             ^^^^^^^^
The type OldClass is deprecated
----------
2. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/ExtendsOldClass.java (at line 4)
        public void foo() {
                    ^^^^^
The method ExtendsOldClass.foo() overrides a deprecated method from OldClass
----------
3. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/ExtendsOldClass.java (at line 5)
        super.foo();
              ^^^
The method foo() from the type OldClass is deprecated
----------
4. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/ExtendsOldClass.java (at line 8)
        super.foo();
              ^^^
The method foo() from the type OldClass is deprecated
----------
5. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/ExtendsOldClass.java (at line 11)
        bar();
        ^^^
The method bar() from the type OldClass is deprecated
----------
----------
6. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 5)
        new OldClass().foo();
            ^^^^^^^^
The type OldClass is deprecated
----------
7. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 5)
        new OldClass().foo();
            ^^^^^^^^
The constructor OldClass() is deprecated
----------
8. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 5)
        new OldClass().foo();
                       ^^^
The method foo() from the type OldClass is deprecated
----------
9. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 8)
        new ExtendsOldClass().bar();
                              ^^^
The method bar() from the type OldClass is deprecated
----------
10. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 9)
        new OldClass().bar();
            ^^^^^^^^
The type OldClass is deprecated
----------
11. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 9)
        new OldClass().bar();
            ^^^^^^^^
The constructor OldClass() is deprecated
----------
12. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/c/UseOldClass.java (at line 9)
        new OldClass().bar();
                       ^^^
The method bar() from the type OldClass is deprecated
----------
12 problems (12 warnings)

Funny enough, if switching deprecation warnings seem to be inconsistent (command line vs preferences), disabling them seem to work via command line argument, even if enabled in preferences:

java -jar ~/Downloads/ecj-I20251026-1800.jar -d /tmp/testcompile --release 17 -properties /data/workspaces/aloskuto-bf/Deprecation/.settings/org.eclipse.jdt.core.prefs -warn:-deprecation  /data/workspaces/aloskuto-bf/Deprecation/src/d/*.java

... nothing reported ...

Observed

ecj seem to be inconsistent with itself and with javac regarding deprecation warnings handling.

Expected

  1. After the fix 545483d / Do not emit restriction warning on inherited method #4293 I would not expect that deprecation warnings are reported on code that uses not explicitly deprecated methods, but obviously this is still the case.
    => to be addressed by members of a deprecated type are not implicitly deprecated #4564

For this ticket:

  1. -warn:+deprecation should enable all deprecation warnings that should be reported (similar to -warn:-deprecation which disables all deprecation warnings).
  2. org.eclipse.jdt.core.compiler.problem.deprecation* options seem not have same scope as -warn:+deprecation option on command line.
  3. There is even worse discreptancies if specifying all classes in a single java file => Not all deprecation warnings reported for types defined in one java file #4563

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompilerEclipse Java Compiler (ecj) related issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions