<div dir="ltr"><div>Could you please elaborate why the implementation of <a href="https://github.com/openjdk/jdk/blob/8ec6b8de3bb3d7aeebdcb45d761b18cce3bab75e/src/java.desktop/unix/classes/sun/awt/X11/XTextAreaPeer.java#L258" target="_blank">sun.awt.X11.XTextAreaPeer#repaintText</a> is <i>correct</i>?<br></div><div><br></div><div>Also let me add more context to the question:</div><div>With one of the X11 regression tests on our infrastructure, we're struggling with a deadlock when the test invokes the public AWT's API method <i>java.awt.TextComponent#setText</i> <u>outside of EDT</u> while EDT is dispatching an input event. Sometimes, it leads to the situation when EDT obtains the AWT tree lock and is trying to lock the instance of <i>java.awt.TextComponent</i> while the call of <i>java.awt.TextComponent#setText</i> (which is on a different thread), in opposite, locks self and is trying to obtain the AWT tree lock. Here is a classical deadlock.</div><div><br></div><div>Before this discussion, I was strongly convinced that AWT guarantees thread-safety in the sense that it's safe to invoke any of its (not Swing's) public UI operations on any thread. However I can't find any proof (or refutation) about this in the AWT documentation now. Is it wrong?</div><div><br></div><div>If there's such a guarantee, let's take a look at the case described above again:</div><div>* The test seems correctly written, although it invokes <i>java.awt.TextComponent#setText</i> outside of EDT.</div><div>* But it internally leads to a call of <a href="https://github.com/openjdk/jdk/blob/8ec6b8de3bb3d7aeebdcb45d761b18cce3bab75e/src/java.desktop/unix/classes/sun/awt/X11/XTextAreaPeer.java#L258" target="_blank">sun.awt.X11.XTextAreaPeer#repaintText</a> which, in this case, calls Swing API outside of EDT, which is definitely incorrect. Thus we must fix the implementation of XTextAreaPeer#repaintText, not the test, right?</div><div><br></div><div><b>Summarizing all the questions:</b></div><div>* Does AWT (still) guarantee thread-safety? The question is about AWT only, excluding Swing.</div><div>* If it does, the implementation of <a href="https://github.com/openjdk/jdk/blob/8ec6b8de3bb3d7aeebdcb45d761b18cce3bab75e/src/java.desktop/unix/classes/sun/awt/X11/XTextAreaPeer.java#L258" target="_blank">sun.awt.X11.XTextAreaPeer#repaintText</a> doesn't take this into account, so it must be fixed, mustn't it?</div><div><br></div><div>Thanks in advance!</div><div><br></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Best regards,<div>Nikita Provotorov</div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Nov 17, 2023 at 7:42 PM Philip Race <<a href="mailto:philip.race@oracle.com">philip.race@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><u></u>

  
  <div>
    No, the code that calls setText() is where it starts.<br>
    <br>
    -phil.<br>
    <br>
    <div>On 11/17/23 2:51 AM, Nikita Provotorov
      wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">
        <div>Thanks for the response!</div>
        <div>However I'd like to clarify: is it correct to say that the
          current implementation of <a href="https://github.com/openjdk/jdk/blob/8ec6b8de3bb3d7aeebdcb45d761b18cce3bab75e/src/java.desktop/unix/classes/sun/awt/X11/XTextAreaPeer.java#L258" target="_blank">sun.awt.X11.XTextAreaPeer#repaintText</a> is
          wrong because it doesn't make sure if <i>javax.swing.JComponent#paintImmediately</i>
          is called on EDT only<span> </span>(e.g.
          via<span> </span><i>SwingUtilities#invokeLater</i>)?</div>
        <br clear="all">
        <div>
          <div dir="ltr" class="gmail_signature">
            <div dir="ltr">Best regards,
              <div>Nikita Provotorov</div>
            </div>
          </div>
        </div>
        <br>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Thu, Nov 16, 2023 at
          9:30 PM Philip Race <<a href="mailto:philip.race@oracle.com" target="_blank">philip.race@oracle.com</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
          <div> Because (like in this case), an AWT component might
            actually be implemented using Swing,<br>
            the recommendation is to treat AWT components like Swing,
            and update them only on the EDT.<br>
            <br>
            -phil.<br>
            <br>
            <div>On 11/15/23 4:01 PM, Nikita Provotorov wrote:<br>
            </div>
            <blockquote type="cite">
              <div dir="ltr">
                <div>Hello!<br>
                </div>
                <div>I've discovered that on X11 platforms a call
                  of java.awt.TextComponent#setText can lead to a call
                  of javax.swing.JComponent#paintImmediately(java.awt.Rectangle)
                  on the same thread.</div>
                <div>Since java.awt.TextComponent#setText is allowed to
                  be called on any thread (because it's AWT, not Swing),
                  JComponent#paintImmediately may be called outside of
                  EDT. Is this a valid behavior?</div>
                <div><br>
                </div>
                <div>The following stacktrace shows how exactly this can
                  happen:</div>
                <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">at
                  javax.swing.JComponent.paintImmediately<br>
                  at sun.awt.X11.XTextAreaPeer$AWTTextArea.repaintNow<br>
                  at sun.awt.X11.XTextAreaPeer.repaintText<br>
                  at sun.awt.X11.XTextAreaPeer.setText<br>
                  at java.awt.TextComponent.setText</blockquote>
                <br clear="all">
                <div>
                  <div dir="ltr" class="gmail_signature">
                    <div dir="ltr">Best regards,
                      <div>Nikita Provotorov</div>
                    </div>
                  </div>
                </div>
              </div>
            </blockquote>
            <br>
          </div>
        </blockquote>
      </div>
    </blockquote>
    <br>
  </div>

</blockquote></div>