title: Changing observed property value in EventHandler changes Event properties
body: <p>I have a <code>TableView</code> with a column of <code>ComboBox</code> cells, created with <code>ComboBoxTableCell.forTableColumn()</code>.  I'm very new to JavaFX. You may want to skip to &quot;TLDR&quot; at the bottom before going through all of it.</p>
  <p>In <code>onEditCommit()</code> for the column, I launch an <code>Alert</code> to get confirmation (&quot;Really ____?&quot;).  If it isn't confirmed, I want the cell's value to revert to what it was originally. The observed property is a <code>SimpleStringProperty</code>, and the table/row/bean type is a <code>FooBar</code> object. The table is backed by an <code>ObservableList&lt;FooBar&gt;</code>, retrieved using the Event object. This is the <code>EventHandler</code>, in kotlin:</p>
  <pre><code>EventHandler { ev -&gt;
      ev.newValue?.let { str -&gt;
  
          println(&quot;A old ${ev.oldValue} ===&gt; new ${ev.newValue}&quot;)
  
          list[ev.tablePosition.row]?.let { foobar -&gt;
              if (str != foobar.prop.value) {
                  val confirm = runDialog()
                  if (!confirm) foobar.prop.value = ev.oldValue
  
                  println(&quot;B old ${ev.oldValue} ---&gt; new ${ev.newValue} &quot;
                      +&quot;| prop ${foobar.prop.value}&quot;)
              }
          }
      }
  }           
  </code></pre>
  <p>The ComboBox has three options, &quot;Alpha&quot;, &quot;Beta&quot;, &quot;Charlie&quot;.  Here's what happens when I select the ComboBox and change the value, but then cancel in the confirm dialoge (the actual output is indented):</p>
  <pre><code>[ Box reads &quot;Alpha&quot;; select &quot;Beta&quot; ]
      A old Alpha ===&gt; new Beta
  [ Cancel dialog... Box reads &quot;Beta&quot;
      B old Alpha ---&gt; new Beta | prop Alpha
  [ Repeat by selecting &quot;Charlie&quot; ]
      A old Alpha ===&gt; new Charlie
  [ Cancel dialog ]   
      B old Alpha ---&gt; new Charlie | prop Alpha
  [ Box reads &quot;Charlie&quot; ]         
  </code></pre>
  <p>Notice that the property is being reset, but the cell contents aren't reflecting that.  I thought this might be an issue with what happens when the handler returns -- ie., the commit happens afterward -- but using <code>Platform.runLater()</code> to set the property did not make a difference.</p>
  <p>What did is intuiting that the edit is never committed, ie., <code>foobar.prop.value</code> is always the same, so setting it to <code>oldValue</code> doesn't change anything.  However, the ComboBox is still out-of-sync with the property it is supposed to be an observer of.</p>
  <p>This theory is supported by the fix, which is to stash <code>oldValue</code> and set <code>foobar.prop</code> to something new before running the dialog.</p>
  <pre><code>    val orig = ev.oldValue
      list[ev.tablePosition.row]?.let { foobar -&gt;
          if (str != foobar.format.value) {
              // Set before dialog.
              foobar.format.value = ev.newValue
              val confirm = runDialog()
              if (!confirm()) foobar.format.value = orig   
  </code></pre>
  <p>But what's a bit mysterious here is why <code>orig</code> is necessary at all -- why not just <code>foobar.format.value = ev.oldValue</code>?  Because <code>ev.oldValue</code> changes <em>in between</em> the third
  last and last lines above; I'm guessing the <code>Event</code> object is actually being recycled and set with <code>foobar.format.value</code>.  Or it could have to do with the dialog, which probably makes it a bone fide bug.  Here's what happens using the fix:</p>
  <pre><code>[ Box reads &quot;Alpha&quot;; select &quot;Beta&quot; ]
      A old Alpha ===&gt; new Beta
  [ Cancel dialog... Box reads &quot;Alpha&quot;
      B old Alpha ---&gt; new Beta | prop Alpha ]     
  </code></pre>
  <p>So I am at least able to get what I want, but I am troubled by all this unexpected behaviour.
  Here's what happens if, instead of using <code>orig</code>, I change that assignment to <code>ev.oldValue</code> (with no other changes):</p>
  <pre><code>[ Box reads &quot;Alpha&quot;; select &quot;Beta&quot; ]
      A old Alpha ===&gt; new Beta
  [ Cancel dialog... Box reads &quot;Beta&quot; ]
      B old Beta ---&gt; new Beta | prop Beta      
  </code></pre>
  <p>Back to the same problem.</p>
  <h2>(TLDR) This means changing <code>foobar.prop.value</code> in the handler has the side affect of changing <code>ev.oldValue</code>.</h2>
  <p>Confirmed with:</p>
  <pre><code>println(&quot;old ${ev.oldValue}&quot;)
  foobar.prop.value = ev.newValue
  println(&quot;old now ${ev.oldValue}&quot;)          
  </code></pre>
  <p>Which I guess is the short version of this question. I'm sure I'm not the first to notice this. Is that behaviour expected, documented or easily explicable? I suppose there is a certain desirability in it, but it makes the <code>Event</code> object seem a bit shifty.</p>
  <p><strong>There's also the matter of the ComboBox falling out of sync with the value, which does not seem desirable at all.</strong></p>
  <p>This is openjfx 11 on x64 linux.</p>