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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:49:38+00:00 2026-05-17T17:49:38+00:00

I have been completely puzzled by an issue I just came over in my

  • 0

I have been completely puzzled by an issue I just came over in my Java application.

When I attempt to run the code given below, Java raises a ConcurrentModificationException on the line that says “if ( this.vertexStore.get ( v ).addAll ( output ) )”.

I find this very strange considering this a completely single-threaded application, and that I am not actually modifying anything that I am looping over as far as I can tell?

In fact, the only place I can see the error occurring is inside the addAll method, but that shouldn’t happen either as I’m using HashMap and LinkedList from the Java class library…

private Queue<Vertex> worklist = new LinkedList<Vertex> ( );
protected Map<Vertex, Set<T>> vertexStore = new HashMap<Vertex, Set<T>> ( );

// . . .

while ( this.worklist.size ( ) > 0 ) {
        Vertex vertex = this.worklist.remove ( );

        Set<T> output = this.processVertice ( vertex, this.vertexStore.get ( vertex ) );

        this.vertexStore.put ( vertex, output );

        for ( Vertex v : vertex.edgesTo ( ) ) {
            // Conveniently, addAll returns true if the set changed
            if ( this.vertexStore.get ( v ).addAll ( output ) )
                this.worklist.add ( v );
        }
    }

EDIT: Error trace:

Exception in thread "main" java.util.ConcurrentModificationException
    at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
    at java.util.HashMap$KeyIterator.next(HashMap.java:828)
    at java.util.AbstractCollection.addAll(AbstractCollection.java:305)
    at DataFlowAnalyser.process(DataFlowAnalyser.java:41) (the if line)

Any good ideas are very welcome!

PS: Full source here (sorry for lack of comments, code not completed)

Cheers,
Jon

  • 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-05-17T17:49:39+00:00Added an answer on May 17, 2026 at 5:49 pm

    You’re calling addAll and passing a reference to the Set itself. If you debug through the code you’ll see that this.vertexStore.get(v) returns the same object as is referenced by the output var.

    Normally this wouldn’t be a problem for a HashSet because addAll won’t actually modify the state of a HashSet if you’re just adding all the same elements. In this case however, you’re modifying the instances of HamiltonPath after they’ve been added to the set which in turn changes their hash code and makes the HashSet think that the object being added is different than the one it already has.

    Here’s some code that illustrates the problem better than my prose:

    List<String> list1 = Arrays.asList("foo");
    List<String> list2 = Arrays.asList("bar");
    Set<List<String>> set = new HashSet<List<String>>();
    set.add(list1);
    set.add(list2);
    list1.add("baz"); 
    list2.add("qux");
    set.addAll(set); // throws ConcurrentModificationException
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Completely new to java and I have been playing around with regex in a
I am completely new to HTML5 and have been reading about it for the
I am a complete Noob when it comes to GIT. I have been just
I have been having an issue with Visual Studio 2010 that is driving me
I have been playing with some of Apple's example code for customizing UITableViewCells. I
I'm completely new to Linux and have been trying to get my (Windows built)
I am completely new to Batch files and have been tinkering around with simple
Are there any types of oncomplete methods to know when images have been completely
I have been completely unable to get forward class declarations in Delphi 2010. I
I have been learning Perl for a few days and I am completely new.

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.