@@ -2232,6 +2232,15 @@ public void visitClassDef(JCClassDecl tree) {
2232
2232
}
2233
2233
}
2234
2234
2235
+ // verify all static final fields got initailized
2236
+ for (int i = firstadr ; i < nextadr ; i ++) {
2237
+ JCVariableDecl vardecl = vardecls [i ];
2238
+ VarSymbol var = vardecl .sym ;
2239
+ if (var .owner == classDef .sym && var .isStatic ()) {
2240
+ checkInit (TreeInfo .diagnosticPositionFor (var , vardecl ), var );
2241
+ }
2242
+ }
2243
+
2235
2244
// define all the instance fields
2236
2245
for (List <JCTree > l = tree .defs ; l .nonEmpty (); l = l .tail ) {
2237
2246
if (l .head .hasTag (VARDEF )) {
@@ -2320,7 +2329,7 @@ public void visitMethodDef(JCMethodDecl tree) {
2320
2329
for (int i = firstadr ; i < nextadr ; i ++) {
2321
2330
JCVariableDecl vardecl = vardecls [i ];
2322
2331
VarSymbol var = vardecl .sym ;
2323
- if (var .owner == classDef .sym ) {
2332
+ if (var .owner == classDef .sym && ! var . isStatic () ) {
2324
2333
// choose the diagnostic position based on whether
2325
2334
// the ctor is default(synthesized) or not
2326
2335
if (isSynthesized && !isCompactOrGeneratedRecordConstructor ) {
@@ -2329,7 +2338,6 @@ public void visitMethodDef(JCMethodDecl tree) {
2329
2338
} else if (isCompactOrGeneratedRecordConstructor ) {
2330
2339
boolean isInstanceRecordField = var .enclClass ().isRecord () &&
2331
2340
(var .flags_field & (Flags .PRIVATE | Flags .FINAL | Flags .GENERATED_MEMBER | Flags .RECORD )) != 0 &&
2332
- !var .isStatic () &&
2333
2341
var .owner .kind == TYP ;
2334
2342
if (isInstanceRecordField ) {
2335
2343
boolean notInitialized = !inits .isMember (var .adr );
0 commit comments