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 8273259
In Process

The Archive Base Latest Questions

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

Everything works fine on local, but when deployed I get a ConcurrentModificationException thrown when

  • 0

Everything works fine on local, but when deployed I get a ConcurrentModificationException thrown when I use session.setAttribute() from a servlet. I use this to return a value from the datastore after using an HTML form to add an Entity.

How come and what could I do about it?

Here is the broken servlet:

public class AdminServlet extends HttpServlet {
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        Boolean logged = false;
        HttpSession session = req.getSession(true);
        Enumeration<String> names = session.getAttributeNames();

        while(names.hasMoreElements()) {
            String name = (String) names.nextElement();

            if(name.equals("logged")) {
                logged = (Boolean) session.getAttribute("logged");
            }
        }

        if(logged) {
            String p1 = req.getParameter("name");
            String p2 = req.getParameter("value");

            if(p1 != "" && p2 != "") {
                Entity e= new Entity("MyEntity");
                e.setProperty("name", p1);
                e.setProperty("value", p2);

                DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
                Transaction txn = datastore.beginTransaction();

                Key k = datastore.put(e);

                txn.commit();

                if(txn.isActive())
                    txn.rollback();

                session.setAttribute("returnedKey", KeyFactory.keyToString(k)); // CRASHES HERE
            }
        }

        resp.sendRedirect("adminpage.jsp");
    }
}

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-08T07:24:47+00:00Added an answer on June 8, 2026 at 7:24 am

    You have an Enumeration open on the session as well.

    Enumeration names = session.getAttributeNames();

    Changing attributes in session would affect name and that is why you are seeing the error.

    Try writing your code so that names is not in use (nulled or out of scope):

    It’d be easy to put it in a method

    public boolean logLogged(HttpSession session){
    
        Enumeration<String> names = session.getAttributeNames();
    
        boolean loggedTmp=false;
    
        while(names.hasMoreElements()){
    
            String name = (String) names.nextElement();
    
            if(name.equals("logged")){
                loggedTmp = (Boolean) session.getAttribute("logged");
            }
        }
    
        return loggedTmp;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I write this, everything works fine: class A < ActiveRecord::Base acts_as_taggable end But
Everything works fine when I have my application on my local server, but I
I have my pickerview set up and everything works fine, but right now I
I implemented this Jquery show/hide code and everything works fine except that the box
there's an audio application which streams files via network, everything works fine but one
So, everything works fine locally, but at heroku it changes to :en Fire up
When I run 'script/server' everything works fine, but when I run my unit tests
I've recently pushed a Rails 3.1 App to heroku. Locally, everything works fine, but
We want to use Microsoft.Office.Interop.Excel in our web application. Everything works fine on our
I've built a carousel in Papervision3D using Flash CS5, everything works fine but when

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.