RFR: 8343540: Report preview error for inherited effectively-preview methods
Jan Lahoda
jlahoda at openjdk.org
Thu Nov 7 15:44:57 UTC 2024
Consider a case where a new preview interface is introduced to JDK, and an existing non-preview class is retrofitted to use it. I.e. a case like:
//JDK types:
@PreviewFeature(...)
public interface NewAPI {
public default void test() {}
}
public class ExistingRetrofittedClass implements NewAPI {}
//user type:
class Test {
void t(ExistingRetrofittedClass c) {
c.test();
}
}
There is currently no error or warning about the invocation of the test method, as the method itself is not marked as preview, and the receiver is not preview either.
The proposal herein is that invoking a method on a receiver that is not of preview type itself, but the method is declared in a preview class or interface, the method will be considered to be a preview method, and the appropriate error or warning will be printed. Similar behavior is implementing for dereferencing fields.
Similarly when implementing or overriding such "effectively" preview methods, like:
//user types:
class Test1 extends ExistingRetrofittedClass {
public void test() {}
}
java also does not produce any error or warning. If the method itself would be marked as preview, an error or warning would be printed.
The proposal herein is to produce an error or warning for method declared inside a non-preview class or interface, which is overridden by a method declared inside a preview class or interface.
-------------
Commit messages:
- Adding one more testcase.
- Cleanup.
- Produce errors/warnings for also methods overriding methods from preview types.
- Report preview error/warning when invoking methods whose owner is a preview class/interface on a site that is non-preview. Dtto for dereferencing fields.
Changes: https://git.openjdk.org/jdk/pull/21953/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=21953&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8343540
Stats: 181 lines in 3 files changed: 162 ins; 0 del; 19 mod
Patch: https://git.openjdk.org/jdk/pull/21953.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/21953/head:pull/21953
PR: https://git.openjdk.org/jdk/pull/21953
More information about the compiler-dev
mailing list