maidh91 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Concurrency bug in AbstractMultimap #339

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Multiple concurrent reads of HashMultimap result in null pointer exception.

Using Google collections version 1.0

Problem
com.google.common.collect.AbstractMultimap.AsMap.entrySet()
can return null when called by multiple threads.

1311    @Override public Set<Map.Entry<K, Collection<V>>> entrySet() {
1312      Set<Map.Entry<K, Collection<V>>> result = entrySet;
1313      return (entrySet == null) ? entrySet = new AsMapEntries() : result;
1314    }

1. thread 1 executes line 1312
2. thread 2 executes 1312 and 1313
3. thread 1 executes 1313.

Thread 1 will return null.

Fix by
1313      return (result == null) ? entrySet = new AsMapEntries() : result;

Original issue reported on code.google.com by marsh.ye...@gmail.com on 12 Mar 2010 at 4:43

Attachments:

GoogleCodeExporter commented 9 years ago
Great catch. Someone internally actually independently reported this the same 
day as you submitted this bug 
report!

Original comment by kurt.kluever on 18 Mar 2010 at 1:01

GoogleCodeExporter commented 9 years ago

Original comment by kurt.kluever on 18 Mar 2010 at 6:13

GoogleCodeExporter commented 9 years ago
For those who find this bug on the interwebs, the patch made it into release 
guava-r06 at the latest.

Original comment by pline...@gmail.com on 28 Jul 2010 at 3:11

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 27 Jan 2011 at 1:59

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:10