On Wed, 29 Apr 2026 07:32:29 GMT, Jeremy Wood <[email protected]> wrote:

>> If we made n-many calls to 
>> textPane.getAccessibleContext().getAccessibleText() then we'd add n-many 
>> DocumentListeners to the HTMLDocument.
>> 
>> These listeners are very light, but even so: after thousands of listeners it 
>> may start to degrade performance.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Jeremy Wood has updated the pull request with a new target base due to a 
> merge or a rebase. The incremental webrev excludes the unrelated changes 
> brought in by the merge/rebase. The pull request contains 11 additional 
> commits since the last revision:
> 
>  - Merge remote-tracking branch 'origin/master' into 8380790
>  - 8380790: adding new test
>    
>    I was worried this PR might uninstall the hypertext support object 
> prematurely. But this test passes without any further intervention. (Maybe 
> the hypertext support object IS being uninstalled, but that's OK because a 
> replacement is lazily installed the next time we check.)
>  - 8380790: trivial formatting cleanup
>  - 8380790: trivial formatting cleanup
>  - 8380790: reduce number of DocumentListeners
>    
>    This converts JEditorPaneAccessibleHypertextSupport from a field inside 
> the AccessibleContext to a client property inside the JEditorPane. The 
> AccessibleContext may be discarded and recreated as needed, but this lets us 
> keep track of the JEditorPaneAccessibleHypertextSupport so we can uninstall 
> its listeners when the Document changes.
>    
>    This brings us to change #2:
>    Refactor JEditorPaneAccessibleHypertextSupport so it's constructor does 
> NOT add an anonymous DocumentListener. Instead we can leverage the fact that 
> JEditorPaneAccessibleHypertextSupport is already a DocumentListener, and just 
> override its DocumentListener methods. This makes it easy for us to uninstall 
> the DocumentListener logic.
>  - Merge branch 'master' into 8380790
>  - 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 "...

Marked as reviewed by prr (Reviewer).

@mrserb I think this is waiting on you.

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

PR Review: https://git.openjdk.org/jdk/pull/30401#pullrequestreview-4266146240
PR Comment: https://git.openjdk.org/jdk/pull/30401#issuecomment-4423416977

Reply via email to