[ 
https://issues.apache.org/jira/browse/GROOVY-11894?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King updated GROOVY-11894:
-------------------------------
    Description: 
The NullChecker and StrictNullChecker are compile-time type checking extensions 
for detecting null-safety violations.

  h3. NullChecker (annotation-based)                                            
                                                                                
                                               
   
  Checks code annotated with {{@Nullable}}, {{@NonNull}}, and related 
annotations. Detects:                                                           
                                                         
  - Assigning {{null}} to a {{@NonNull}} field              
  - Passing {{null}} or {{@Nullable}} values to {{@NonNull}} parameters         
                                                                                
                                               
  - Returning {{null}} from {{@NonNull}} methods                       
  - Dereferencing {{@Nullable}} variables without null checks or safe 
navigation ({{?.}})                                                             
                                                         
  - Dereferencing {{@Nullable}} method return values                            
                                                                                
                                               
  - Re-assigning {{null}} to {{@MonotonicNonNull}}/{{@Lazy}} fields after 
initialization
                                                                                
                                                                                
                                               
  Recognizes annotations by simple name from any package (JSpecify, JSR-305, 
JetBrains, SpotBugs, Checker Framework). Also recognizes class-level
  {{@NullMarked}}/{{@NonNullByDefault}}/{{@ParametersAreNonnullByDefault}} and 
Groovy's {{@NullCheck}}. {{@NullUnmarked}} opts out.                            
                                                
                                                            
  Null guards ({{if (x != null)}}), early exit ({{if (x == null) 
return/throw}}), and safe navigation ({{?.}}) are recognized.                   
                                                              
                                                            
  h3. StrictNullChecker (annotation + flow-sensitive)                           
                                                                                
                                               
                                                            
  Includes all annotation-based checks plus flow-sensitive tracking for 
unannotated code:                                                               
                                                       
  - Variables assigned {{null}}, uninitialized, or from ternary/elvis with a 
null branch are tracked as nullable
  - Dereferences of tracked-nullable variables are flagged                      
                                                                                
                                               
  - Reassignment to non-null or {{?=}} clears nullable state
  - {{@Nullable}} method return values assigned to variables are tracked        
                                                                                
                                               
                                                                        
  {code:groovy}                                                                 
                                                                                
                                               
  @TypeChecked(extensions='groovy.typecheckers.NullChecker')       // 
annotation-only                                                                 
                                                         
  class RelaxedCode { ... }                                                     
                                                                                
                                               
                                                                                
                                                                                
                                               
  @TypeChecked(extensions='groovy.typecheckers.StrictNullChecker')  // + flow 
analysis                                                                        
                                                 
  class StrictCode { ... }                                                      
                                                                                
                                               
  {code}  

> Provide a NullChecker for groovy-typecheckers
> ---------------------------------------------
>
>                 Key: GROOVY-11894
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11894
>             Project: Groovy
>          Issue Type: New Feature
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>
> The NullChecker and StrictNullChecker are compile-time type checking 
> extensions for detecting null-safety violations.
>   h3. NullChecker (annotation-based)                                          
>                                                                               
>                                                    
>    
>   Checks code annotated with {{@Nullable}}, {{@NonNull}}, and related 
> annotations. Detects:                                                         
>                                                            
>   - Assigning {{null}} to a {{@NonNull}} field              
>   - Passing {{null}} or {{@Nullable}} values to {{@NonNull}} parameters       
>                                                                               
>                                                    
>   - Returning {{null}} from {{@NonNull}} methods                       
>   - Dereferencing {{@Nullable}} variables without null checks or safe 
> navigation ({{?.}})                                                           
>                                                            
>   - Dereferencing {{@Nullable}} method return values                          
>                                                                               
>                                                    
>   - Re-assigning {{null}} to {{@MonotonicNonNull}}/{{@Lazy}} fields after 
> initialization
>                                                                               
>                                                                               
>                                                    
>   Recognizes annotations by simple name from any package (JSpecify, JSR-305, 
> JetBrains, SpotBugs, Checker Framework). Also recognizes class-level
>   {{@NullMarked}}/{{@NonNullByDefault}}/{{@ParametersAreNonnullByDefault}} 
> and Groovy's {{@NullCheck}}. {{@NullUnmarked}} opts out.                      
>                                                       
>                                                             
>   Null guards ({{if (x != null)}}), early exit ({{if (x == null) 
> return/throw}}), and safe navigation ({{?.}}) are recognized.                 
>                                                                 
>                                                             
>   h3. StrictNullChecker (annotation + flow-sensitive)                         
>                                                                               
>                                                    
>                                                             
>   Includes all annotation-based checks plus flow-sensitive tracking for 
> unannotated code:                                                             
>                                                          
>   - Variables assigned {{null}}, uninitialized, or from ternary/elvis with a 
> null branch are tracked as nullable
>   - Dereferences of tracked-nullable variables are flagged                    
>                                                                               
>                                                    
>   - Reassignment to non-null or {{?=}} clears nullable state
>   - {{@Nullable}} method return values assigned to variables are tracked      
>                                                                               
>                                                    
>                                                                         
>   {code:groovy}                                                               
>                                                                               
>                                                    
>   @TypeChecked(extensions='groovy.typecheckers.NullChecker')       // 
> annotation-only                                                               
>                                                            
>   class RelaxedCode { ... }                                                   
>                                                                               
>                                                    
>                                                                               
>                                                                               
>                                                    
>   @TypeChecked(extensions='groovy.typecheckers.StrictNullChecker')  // + flow 
> analysis                                                                      
>                                                    
>   class StrictCode { ... }                                                    
>                                                                               
>                                                    
>   {code}  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to