user2125853
user2125853

Reputation: 1315

Why am I seeing ConcurrentModificationException in Java 1.7.0?

We have an Eclipse RCP (Rich client platform) based application that gets launched via javaws. When the application is downloaded and launched, I am see the following in the java console:

Detected from bootclasspath: C:\\Program Files\\Java\\jre7\\lib\\deploy.jar
Exception in thread "HandshakeCompletedNotify-Thread" java.util.ConcurrentModificationException
    at java.util.HashMap$HashIterator.nextEntry(Unknown Source)
    at java.util.HashMap$EntryIterator.next(Unknown Source)
    at java.util.HashMap$EntryIterator.next(Unknown Source)
    at sun.security.ssl.SSLSocketImpl$NotifyHandshakeThread.run(Unknown Source)

The above is the entire stack trace. We did a recent update to the application and I am seeing this. This happens with java 1.7.0. I also tried same application with Java 1.8.0_144 and DID NOT see the exception.

What bothers me is that when I run an older version of the application on 1.7.0 I do not see the exception. The trace shows only java classes, so it is hard for me to know where this might be happening or it just has to do with Java.

Other than the exception, the application seems to run fine. Any pointers would be helpful.

Upvotes: 1

Views: 280

Answers (2)

Sambit
Sambit

Reputation: 8011

The following source code may give you some hints.

https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/src/share/classes/sun/security/ssl/SSLSocketImpl.java

In this case in Java 7, java 7 creators use HashMap<HandshakeCompletedListener, AccessControlContext> and I see the synchronized methods for add and remove. I know that it will not solve your problem, but it may give you some outline.

Upvotes: 0

Louis Wasserman
Louis Wasserman

Reputation: 198033

In general, ConcurrentModificationException is thrown on a best effort basis. Specifically: if a ConcurrentModificationException is thrown, you always have a bug, but if one is not thrown, you may just have a bug and it couldn't detect it.

The exact details of how that detection is done vary between Java versions; sometimes it works, sometimes it doesn't, and when it works may vary. But if you got a ConcurrentModificationException, in any version, you have a concurrent modification bug in your code.

Upvotes: 2

Related Questions