On Mon, 30 Mar 2026 23:24:52 GMT, Sergey Bylokhov <[email protected]> wrote:

>> Jeremy Wood has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   8380790: make sure new Documents get axText listener
>>   
>>   This is in response to:
>>   https://github.com/openjdk/jdk/pull/30401#issuecomment-4144874584
>>   
>>   My current output from this test resembles:
>>   2 listeners  at "A"
>>      javax.swing.plaf.basic.BasicTextUI$UpdateHandler 0x165938a8
>>      javax.swing.text.DefaultCaret$Handler 0x13ad4587
>>   5 listeners  at "B"
>>      javax.swing.JEditorPane$JEditorPaneAccessibleHypertextSupport$1 
>> 0x408dfc5d
>>      javax.swing.JEditorPane$JEditorPaneAccessibleHypertextSupport 0x6badfa89
>>      javax.swing.JEditorPane$AccessibleJEditorPaneHTML 0x8542bca
>>      javax.swing.plaf.basic.BasicTextUI$UpdateHandler 0x165938a8
>>      javax.swing.text.DefaultCaret$Handler 0x13ad4587
>>   4 listeners  at "C"
>>      javax.swing.JEditorPane$AccessibleJEditorPaneHTML 0x8542bca
>>      javax.swing.text.html.AccessibleHTML$DocumentHandler 0x2343eccf
>>      javax.swing.plaf.basic.BasicTextUI$UpdateHandler 0x165938a8
>>      javax.swing.text.DefaultCaret$Handler 0x13ad4587
>>   6 listeners  at "D"
>>      javax.swing.JEditorPane$JEditorPaneAccessibleHypertextSupport$1 
>> 0x13117e17
>>      javax.swing.JEditorPane$JEditorPaneAccessibleHypertextSupport 0x491f0df7
>>      javax.swing.JEditorPane$AccessibleJEditorPaneHTML 0x8542bca
>>      javax.swing.text.html.AccessibleHTML$DocumentHandler 0x2343eccf
>>      javax.swing.plaf.basic.BasicTextUI$UpdateHandler 0x165938a8
>>      javax.swing.text.DefaultCaret$Handler 0x13ad4587
>>   
>>   I'm surprised at each point there are a different number of 
>> DocumentListeners, but this confirms that a new 
>> JEditorPane$JEditorPaneAccessibleHypertextSupport$1 is being added after 
>> setDocument(..)
>
> src/java.desktop/share/classes/javax/swing/JEditorPane.java line 1727:
> 
>> 1725:             if (axText == null) {
>> 1726:                 axText = new JEditorPaneAccessibleHypertextSupport();
>> 1727:                 JEditorPane.this.addPropertyChangeListener("document", 
>> evt -> axText = null );
> 
> Will we accumulate these listeners overtime? (since each 
> getAccessibleText->setDocument->getAccessibleText will re-add the new one).

That depends on what you mean by "we".

If getDocument() is always a new document: I'm not worried about accumulating 
listeners. Some old listeners will be left attached to old orphaned Documents, 
but I'm not even sure if that's a bad thing. (If a JTextComponent doesn't 
reference a Document anymore, does that guarantee no other entity can have a 
reasonable interest in it?)

But I think this usage is going to be problematic:

HTMLDocument doc1, doc2;
...
for (int a = 0; a < 1000; a++) {
    textPane.setDocument(a%2 == 0 ? doc1 : doc2);
    textPane.getAccessibleContext().getAccessibleText();
}


But I chose not to address that in this PR because (to me) that feels like 
feature creep for the original ticket. 

Would you like me to address that here? (This PR is currently changing ~5 
lines, but a bigger refactor may change close to 20-30?)

(Or are you asking about something different?)

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/30401#discussion_r3012719208

Reply via email to