Skip to content

Not all deprecation warnings reported for types defined in one java file #4563

@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.

I run immediately into the problem that ecj doesn't produce all deprecation warnings for types defined in same file (but javac does).

This is "spin off" from #4562.

Consider this one file example with only class level deprecation:

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

javac from Java 25 reports three warnings:

javac -d /tmp/testcompile --release 17 -Xlint:deprecation  /data/workspaces/aloskuto-bf/Deprecation/src/a/*.java 

/data/workspaces/aloskuto-bf/Deprecation/src/a/OldClass.java:11: warning: [deprecation] OldClass in a has been deprecated
class ExtendsOldClass extends OldClass {
                              ^
/data/workspaces/aloskuto-bf/Deprecation/src/a/OldClass.java:26: warning: [deprecation] OldClass in a has been deprecated
        new OldClass().foo();
            ^
/data/workspaces/aloskuto-bf/Deprecation/src/a/OldClass.java:30: warning: [deprecation] OldClass in a has been deprecated
        new OldClass().bar();
            ^
3 warnings

ecj reports nothing on command line if using -warn:+deprecation option:

java -jar ~/Downloads/ecj-I20251026-1800.jar -d /tmp/testcompile --release 17 -warn:+deprecation /data/workspaces/aloskuto-bf/Deprecation/src/a/*.java

... but reports one warning if using project settings below (and this warning is also shown in the editor)

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/a/*.java
----------
1. WARNING in /data/workspaces/aloskuto-bf/Deprecation/src/a/OldClass.java (at line 13)
        public void foo() {
                    ^^^^^
The method ExtendsOldClass.foo() overrides a deprecated method from OldClass
----------
1 problem (1 warning)

Splitting the code over three files results in a completely different picture and ecj reports more deprecation warnings, but there are issues with that reporting, see #4562.

Expected

ecj should report warnings independently whether the code is in one or multiple files.

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