I'm working on annotating one of my projects to remove all checker Nullness warnings. This also means that I am handling the initialization warnings as well as these 2 checkers work hand in hand. I've managed to work through a couple of packages of the project and now am working on a package that has GUI classes as well as lots of objects referencing each other at construction time. I'm finding quite a few warnings about calling methods while the class is under initialization. Particularly about constructing the GUI itself.
1) For the JDK GUI methods is the answer to annotate the JDK to allow most methods to be called while under initialization or is there another pattern to use?
2) I'm finding that I need a lot of NotOnlyInitialized annotations with objects referencing each other during construction. Is this expected?
Is there a good pattern for handling this kind of reference chain?
4) Lambdas don't appear to be handled well either. When methods are called from inside a lambda that isn't being executed yet, but the lambda is constructed inside the constructor causes the method calls inside the lambda to be tagged with this being under initialization, however the lambda isn't executed until after the constructor is completed. Moving the lambda to an explicit inner class fixed these warnings.
/home/jpschewe/projects/fll-sw/working-dir/src/main/java/fll/xml/ui/ChallengeDescriptionEditor.java:299: warning: [methodref.receiver.bound.invalid] Incompatible receiver type
mDescription.getSubjectiveCategories().forEach(this::addSubjectiveCategory);
^
found : @UnderInitialization(javax.swing.JPanel.class) @NonNull ChallengeDescriptionEditor
required: @Initialized @NonNull ChallengeDescriptionEditor
Consequence: method
@UnderInitialization(javax.swing.JPanel.class) @NonNull ChallengeDescriptionEditor
is not a valid method reference for
@NonNull void addSubjectiveCategory(@Initialized @NonNull ChallengeDescriptionEditor this, @Initialized @NonNull SubjectiveScoreCategory p0) in @UnderInitialization(javax.swing.JPanel.class) @NonNull ChallengeDescriptionEditor
/home/jpschewe/projects/fll-sw/working-dir/src/main/java/fll/xml/ui/ChallengeDescriptionEditor.java:300: warning: [methodref.receiver.bound.invalid] Incompatible receiver type
mDescription.getNonNumericCategories().forEach(this::addNonNumericCategory);
^
found : @UnderInitialization(javax.swing.JPanel.class) @NonNull ChallengeDescriptionEditor
required: @Initialized @NonNull ChallengeDescriptionEditor
Consequence: method
@UnderInitialization(javax.swing.JPanel.class) @NonNull ChallengeDescriptionEditor
is not a valid method reference for
@NonNull void addNonNumericCategory(@Initialized @NonNull ChallengeDescriptionEditor this, @Initialized @NonNull NonNumericCategory p0) in @UnderInitialization(javax.swing.JPanel.class) @NonNull ChallengeDescriptionEditor
Thank you for any insights,
Jon