GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • CodeQL documentation
  • CodeQL overview
  • Writing CodeQL queries
  • CodeQL language guides
  • QL language reference
  • CodeQL standard-libraries
  • CodeQL query help
  • CodeQL repository
  • QL publications
  • CodeQL query help for C and C++
  • CodeQL query help for C#
  • CodeQL query help for GitHub Actions
  • CodeQL query help for Go
  • CodeQL query help for Java and Kotlin

This view

  • Original page
  • New address

GeezerVison is showing codeql.github.com — Self assignment — CodeQL query help documentation

Self assignment¶

ID: java/redundant-assignment
Kind: problem
Security severity: 
Severity: error
Precision: very-high
Tags:
   - quality
   - reliability
   - correctness
   - logic
Query suites:
   - java-code-quality.qls
   - java-security-and-quality.qls

Click to see the query in the CodeQL repository

Assigning a variable to itself does not have any effect. Therefore, such an assignment is either completely unnecessary, or it indicates a typo or a similar mistake.

Recommendation¶

If the assignment is unnecessary, remove it. If the assignment indicates a typo or a similar mistake, correct the mistake.

Example¶

The following example shows part of a method that is intended to make a copy of an existing MotionEvent without preserving its history. On line 8, o.mFlags is assigned to itself. Given that the statement is surrounded by statements that transfer information from the fields of o to the fields of the new event, ev, the statement is clearly a mistake. To correct this, the mFlags value should be assigned to ev.mFlags instead, as shown in the corrected method.

static public MotionEvent obtainNoHistory(MotionEvent o) {
    MotionEvent ev = obtain(o.mNumPointers, 1);
    ev.mDeviceId = o.mDeviceId;
    o.mFlags = o.mFlags;  // Variable is assigned to itself
    ...
}

static public MotionEvent obtainNoHistory(MotionEvent o) {
    MotionEvent ev = obtain(o.mNumPointers, 1);
    ev.mDeviceId = o.mDeviceId;
    ev.mFlags = o.mFlags;  // Variable is assigned correctly
    ...
}

References¶

  • Help - Eclipse Platform: Java Compiler Errors/Warnings Preferences.

  • © GitHub, Inc.
  • Terms
  • Privacy
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.