On Wed, 17 Sep 2025 00:57:34 GMT, Vicente Romero <[email protected]> wrote:
> This PR introduces a new Xlint category: `initialization`. When enabled it
> will indicate if some code in an identity class couldn't be placed in the
> prologue phase. This applies to field initializers and constructors with no
> explicit `super` invocation. So for example for code like:
>
>
> class Test {
> int i = 0;
>
> Test() {
> this.i = 1;
> }
> }
>
>
> a warning will be issued as if there were a super invocation at the end of
> the constructor, the compiler would issue an error.
>
> PS. The new lint warning had to be disabled during the build as in other case
> it wouldn't finish
src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java line 285:
> 283: * construction due to a this dependency.
> 284: */
> 285: INITIALIZATION("initialization"),
IMHO this should contain the word `strict` somewhere.
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 1257:
> 1255: }
> 1256: if (!prologueCode.isEmpty()) {
> 1257: CtorPrologueVisitor ctorPrologueVisitor = new
> CtorPrologueVisitor(localEnv, addedSuperInIdentityClass && allowValueClasses);
I suppose I'd rather not run the visitor if the lint warning is disabled?
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 1601:
> 1599: v.type = chk.checkLocalVarType(tree,
> tree.init.type, tree.name);
> 1600: }
> 1601: if (allowValueClasses && v.owner.kind == TYP &&
> !v.isStatic()) {
checking again whether value classes are enabled here seems redundant?
test/langtools/tools/javac/SuperInit/InitializationWarningTest.java line 9:
> 7: */
> 8:
> 9: class InitializationWarningTest implements Iterable<Object> {
Since the code base is shared -- perhaps a better testing methodology would be
to run _all_ the existing early init negative tests in this new mode, to make
sure they generate a warning when there was an error before?
-------------
PR Review Comment:
https://git.openjdk.org/valhalla/pull/1595#discussion_r2355572298
PR Review Comment:
https://git.openjdk.org/valhalla/pull/1595#discussion_r2355557583
PR Review Comment:
https://git.openjdk.org/valhalla/pull/1595#discussion_r2355570464
PR Review Comment:
https://git.openjdk.org/valhalla/pull/1595#discussion_r2355577796