Java cast to List fails
<p>I have a problem that I can't get my head round. I'm working some JSON data that's been converted to raw List and Map structures.  Then I'm testing whether a particular field is a List and if it is, I cast it to one in order to work with it further. </p>

<p>So I have;</p>

<pre><code>if (value != null &amp;&amp; value instanceof List){
   List listValue = (List) value;
   ...
}
</code></pre>

<p>In the Eclipse debugger, I can clearly see that value is an ArrayList, and it contains a Map, and so the code continues to the next line where the cast occurs.  The result of the cast is an empty List - that is, listValue is a List with nothing in it.  I don't understand why this should be the case.  Can anyone shed some light on what I'm doing wrong?</p>

<p><strong>Update:</strong> It does seem it was a concurrency problem.  I've posted an answer, to which comments are welcome.  Thanks for everyone's input.</p>
