Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8310283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:24:18+00:00 2026-06-08T19:24:18+00:00

In our Java web application which uses Struts 1, we have a lot of

  • 0

In our Java web application which uses Struts 1, we have a lot of code that essentially does this:

HttpSession session = httpServletRequest.getSession();
MyObject myObject = session.getAttribute(MY_OBJECT_KEY);

//code that mutates myObject - setting properties or whatever

session.setAttribute(MY_OBJECT_KEY, myObject);

My question: Is the last line, session.setAttribute(..) necessary? It seems pointless to me – ‘myObject’ and ‘session.getAttribute(..)’ refer to the same location in memory, right? So re-setting the attribute in the session should not be required? Does this do anything I am not aware of? The object does not implement HttpSessionBindingListener which is mentioned in the documentation.

I feel like I need to double check because this is done all over this app and I certainly don’t want to break anything just because I am cleaning up code. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:24:22+00:00Added an answer on June 8, 2026 at 7:24 pm

    It depends what you mean by “mutate”. If “mutate” in this context means you changed properties, but not the instance, then no, you don’t need to setAttribute at the end.

    myObject is a reference to the underlying object. The session has its own reference. They both point to the same underlying object, so you’d be changing properties on the same instance.

    Now, if you do

    myObject = new MYObject();

    THEN you need to pass the new object to the session. In this case, your reference myObject now points to a different instance than the session’s reference.

    Note, why not write a unit test and test it out?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For our Kunagi Java web application we have a signed kunagi.jar file which contains
We have a Java web service that we call from our application. When we
I've set up ehcache on our Java application, which uses Spring and Hibernate. However,
We have an ASMX web service which we invoke from our ASP.NET application using
We have developed SOA architecure for our intranet application, so our web-start java applications
We use Tomcat for our java web application. There is a properties file under
Our Java application has a number of modules which implement a common interface. By
I need to centralize all settings for our Java web application in one .properties
I'm working on a Java web application in which files will be stored in
I am using a Java Web Service which is developed by one of our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.