Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-4682

"@CheckForNull" or "@Nullable" should not be used on primitive types

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      "XXX" annotation should not be used on primitive types
    • Highlighting:
      Hide

      Primitive type

      Show
      Primitive type
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way
    • Covered Languages:
      Java
    • Irrelevant for Languages:
      ABAP, APEX, C#, C, C++, Cobol, CSS, Flex, Go, HTML, JavaScript, Kotlin, Objective-C, PHP, PL/I, PL/SQL, Python, RPG, Ruby, Rust, Scala, Solidity, Swift, T-SQL, TypeScript, VB.Net, VB6, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      1min
    • Analysis Level:
      Semantic Analysis
    • Analysis Scope:
      Main Sources

      Description

      By definition, primitive types are not Objects and so they can't be null. Adding @CheckForNull or @Nullable on primitive types adds confusion and is useless.

      This rule raises an issue when @CheckForNull or @Nullable is set on a method returning a primitive type: byte, short, int, long, float, double, boolean, char.

      Noncompliant Code Example

      @CheckForNull
      boolean isFoo() {
       ...
      }
      

      Compliant Solution

      boolean isFoo() {
       ...
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              alexandre.gigleux Alexandre Gigleux
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: