title: Is using an array inside an anonymous class thread safe?
body: <p>I'm trying to determine if the following java methods are thread safe:</p>
  
  <pre><code>public Object calledByMultipleThreads() {
      final Object[] item = new Object[1];
  
      if (!EventQueue.isDispatchThread()) {
          try {
              EventQueue.invokeAndWait(new Runnable() {
                  @Override
                  public void run() {
                      helperMethod(item)
                  }
              });
          } catch (InterruptedException | InvocationTargetException ex) {
              // logging...
          }
      } else {
          helperMethod(item)
  
      }
  
      return item[0];
  }
  
  private void helperMethod(Object[] item) {
      item[0] = new Object();
  }
  </code></pre>
  
  <p>I know that <code>final Object[] item = new Object[1]</code> is a workaround (since something like <code>final Object item</code> couldn't be modified inside the <code>Runnable</code>). And since <code>invokeAndWait</code> is used, <code>item[0]</code> is set before it's referenced by the <code>return</code>, but my fear is that a caller thread (that's not the EDT) might not see the update to the <code>item</code> array, and return <code>null</code>. Is this possible? Is there any way I can test its safety?</p>