It's not a secret anymore!*
The moose likes Java in General and the fly likes How to modify method parameters? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to modify method parameters?" Watch "How to modify method parameters?" New topic
Author

How to modify method parameters?

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Hi all, I am having a method which takes a couple of strings as parameters. The class which uses this method may sometimes send null parameters. In my method I am checking the parameter values. If any of the parameter is null I am assigning some value to it.

When I use the sonar plugin it reports that "Assignment of parameter x is not allowed". What is the right approach to assign a value to a method parameter?

Can anyone please tell me? Thank you all in advance. Good day.


Love all, trust a few, do wrong to none.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7526
    
  18

chaitanya karthikk wrote:Hi all, I am having a method which takes a couple of strings as parameters. The class which uses this method may sometimes send null parameters. In my method I am checking the parameter values. If any of the parameter is null I am assigning some value to it.

When I use the sonar plugin it reports that "Assignment of parameter x is not allowed". What is the right approach to assign a value to a method parameter?

Can anyone please tell me? Thank you all in advance. Good day.

Without seeing the code, it's very hard to tell. Please supply an SSCCE.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Winston Gutkowski wrote:
Without seeing the code, it's very hard to tell. Please supply an SSCCE.
Winston
Hi Winston, thanks for the reply. This is the code

Now I understood why I should not change the parameter directly, because it messes up the things/code. Now I replace the above code with
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

chaitanya, Winston gave you that link for a reason. Is it really too much trouble click the link and go through that page?


luck, db
There are no new questions, but there may be new answers.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37953
    
  22
chaitanya karthikk wrote: . . . I should not change the parameter directly, because it messes up the things/code. . . .
No, it doesn’t. It doesn’t mess anything up. To find out what it actually does, have a look at this thread, which refers back to our pass‑by‑value story.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to modify method parameters?
 
Similar Threads
Problem to initialize the request parameter of the HttpServlet from any JUnit test class
common validator for object validation
Is it true about EJB QL Where clause...
Exception Handling
setting parameters in Portlet URL that other portlet can also retrieve?