• Stack Overflow Public questions & answers
  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Talent Build your employer brand
  • Advertising Reach developers & technologists worldwide
  • About the company

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Sonar violation on "disallowed assignment of parameters"

I have the following code and I got an sonar violation error: disallowed assignment of parameters What is the best way to fix this?

PhoonOne's user avatar

I suspect one of 2 things are happening here:

1 - There is a bug in the checkstyle plugin

2 - The code sonar analysed is not quite the code you posted here

I believe that violation should apply in the following case:

So when you are reassigning the method parameter it would be expected, but in your example you are not, you are assigning it to a class field so it should be ok.

Try changing the method parameter to final and see if you still see the violation.

cowls's user avatar

Your Answer

Sign up or log in, post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct .

Not the answer you're looking for? Browse other questions tagged java sonarqube or ask your own question .

Hot Network Questions

assignment of parameter is not allowed

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .

Remove Assignments to Parameters

Some value is assigned to a parameter inside method’s body.

Use a local variable instead of a parameter.

Why Refactor

The reasons for this refactoring are the same as for Split Temporary Variable , but in this case we’re dealing with a parameter, not a local variable.

First, if a parameter is passed via reference, then after the parameter value is changed inside the method, this value is passed to the argument that requested calling this method. Very often, this occurs accidentally and leads to unfortunate effects. Even if parameters are usually passed by value (and not by reference) in your programming language, this coding quirk may alienate those who are unaccustomed to it.

Second, multiple assignments of different values to a single parameter make it difficult for you to know what data should be contained in the parameter at any particular point in time. The problem worsens if your parameter and its contents are documented but the actual value is capable of differing from what’s expected inside the method.

Each element of the program should be responsible for only one thing. This makes code maintenance much easier going forward, since you can safely replace code without any side effects.

This refactoring helps to extract repetitive code to separate methods .

How to Refactor

Create a local variable and assign the initial value of your parameter.

In all method code that follows this line, replace the parameter with your new local variable.

Tired of reading?

No wonder, it takes 7 hours to read all of the text we have here.

Try our interactive course on refactoring. It offers a less tedious approach to learning new stuff.

Skip to Content

Skip over Site Identifier

Service & Support

Skip over Generic Navigation

Skip over Search

Skip over Site Explorer

Site Explorer Site Explorer

assignment of parameter is not allowed

Parameter assignment error

Created by: royalmaster at: 5/18/2018 10:04 am (10 replies), rating (1) thanks 1, entries per page: 10 | all, all about step 7 (tia portal), presales info, catalog and ordering system online, technical info, contact & partners, follow us on.


  1. Cách khắc phục lỗi “The Parameter Is Incorrect” trong Windows 10

    assignment of parameter is not allowed

  2. Solution

    assignment of parameter is not allowed

  3. c++

    assignment of parameter is not allowed

  4. Visual Studio/TFS error on Check In: The parameter is incorrect

    assignment of parameter is not allowed

  5. Parameter conversion not allowed

    assignment of parameter is not allowed

  6. Fix 'The parameter is incorrect' on BitLocker drive in Windows 10/8/7

    assignment of parameter is not allowed


  1. Order of Operations-PEMDAS Song

  2. short description parameter is not 🚫 #viral #youtubeshorts #reels #viralvideo

  3. The Laughing faces in art │part 1

  4. Basics of VFD Part -2 (Control Section)

  5. QRC Q1 2023

  6. Which of the following parameter is not a part of P population grow


  1. How to remove 'Assignment of Parameter 'variable' is not allowed'

    In my Sonar I have an error that says: 'Assignment of Parameter 'variable' is not allowed. The line that it's on is: @RequestParam (value="variable", required=false) String variable. So I'm wondering how I could get that error off since I can't just create a setter when I'm using that annotation.

  2. Sonar violation on "disallowed assignment of parameters"

    I suspect one of 2 things are happening here: 1 - There is a bug in the checkstyle plugin. 2 - The code sonar analysed is not quite the code you posted here. I believe that violation should apply in the following case: /** * @param lastAccessTime the lastAccessTime to set */ public void setLastAccessTime (Date lastAccessTime) { lastAccessTime ...

  3. ParameterAssignmentCheck (checkstyle 10.11.0 API)

    Disallows assignment of parameters. Rationale: Parameter assignment is often considered poor programming practice. Forcing developers to declare parameters as final is often onerous. Having a check ensure that parameters are never assigned would give the best of both worlds.

  4. Parameter assignment error

    hi, yes, this could be the problem. when the addresses of a F-IO is not used in the F-programm, the DB of the F-module is not loaded with HW-configuration and this can cause an error. Try to use one of the F- inputs/output in the F-programm, to verify if I am right.