From e8e95263bb2da713c6546304418d4e1acf2d3246 Mon Sep 17 00:00:00 2001 From: praneethKulukuri26 Date: Sat, 20 Dec 2025 13:43:41 +0000 Subject: [PATCH] Fix interaction between @NotOnlyInitialized and @UnderInitialization --- .../InitializationAnnotatedTypeFactory.java | 17 +++++++---------- .../InitializationNotOnlyInitialized.java | 13 +++++++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 checker/tests/nullness/InitializationNotOnlyInitialized.java diff --git a/checker/src/main/java/org/checkerframework/checker/initialization/InitializationAnnotatedTypeFactory.java b/checker/src/main/java/org/checkerframework/checker/initialization/InitializationAnnotatedTypeFactory.java index 9cc9498f61df..6c6297602c98 100644 --- a/checker/src/main/java/org/checkerframework/checker/initialization/InitializationAnnotatedTypeFactory.java +++ b/checker/src/main/java/org/checkerframework/checker/initialization/InitializationAnnotatedTypeFactory.java @@ -512,16 +512,13 @@ protected void setSelfTypeInInitializationCode( // - if the class is final, this is @Initialized // - otherwise, this is @UnderInitialization(CurrentClass) as // there might still be subclasses that need initialization. - if (areAllFieldsInitializedOnly(enclosingClass)) { - Store store = getStoreBefore(tree); - if (store != null - && getUninitializedInvariantFields(store, path, false, Collections.emptyList()) - .isEmpty()) { - if (classType.isFinal()) { - annotation = INITIALIZED; - } else { - annotation = createUnderInitializationAnnotation(classType); - } + Store store = getStoreBefore(tree); + if (store != null + && getUninitializedInvariantFields(store, path, false, Collections.emptyList()).isEmpty()) { + if (classType.isFinal()) { + annotation = INITIALIZED; + } else { + annotation = createUnderInitializationAnnotation(classType); } } diff --git a/checker/tests/nullness/InitializationNotOnlyInitialized.java b/checker/tests/nullness/InitializationNotOnlyInitialized.java new file mode 100644 index 000000000000..074f14adfd37 --- /dev/null +++ b/checker/tests/nullness/InitializationNotOnlyInitialized.java @@ -0,0 +1,13 @@ +// @test +// @summary Reproduce incorrect interaction between @NotOnlyInitialized and @UnderInitialization +// @compile +import org.checkerframework.checker.initialization.qual.*; +import org.checkerframework.checker.nullness.qual.*; + +class Parent { + @NonNull String parentField; + + Parent() { + parentField = "parent"; + } +}