On Wed, 24 Jun 2026 20:07:39 GMT, Jeremy Wood <[email protected]> wrote:

>> Calling `getAccessibleContext()` may in some cases replace the field 
>> `accessibleContext`. So we should use `getAccessibleContext()` here to make 
>> sure sure we have the most up-to-date AccessibleContext / DocumentListener.
>> 
>> 
>> ### Other Related Consideration
>> 
>> The `setDocument()` method includes analogous logic for 
>> `inputMethodRequestsHandler`. However `inputMethodRequestsHandler` is never 
>> reassigned outside of the JTextComponent class, so that shouldn't require a 
>> similar fix/change anytime soon.
>> 
>> 
>> ---------
>> - [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 seven additional 
> commits since the last revision:
> 
>  - 8385367: trying to fix whitespace for PR
>  - 8385367: moving fix to JEditorPane
>    
>    This is in response to:
>    https://git.openjdk.org/jdk/pull/31271#discussion_r3358850956
>  - 8385367: cleaning up test
>  - Merge branch 'master' into 8385367
>  - Merge branch 'openjdk:master' into master
>  - 8385367: make sure new DocumentListener is only added once
>    
>    In getAccessibleContext() when we create a new AccessibleContext: we 
> immediately add it as a DocumentListener to our Document.
>    
>    So in that case: setDocument(..) doesn't need to add a DocumentListener.
>  - 8385367: stop using stale/orphaned AccessibleContext

I updated this PR.

> maybe [JEditorPane] should be over-riding setDocument to do the unusual thing.

Since getAccessibleContext() changes based on the EditorKit, I put this logic 
in the setEditorKit method

> by calling getAccessibleContext() you've ensured accessibleContext

Yes, but (in both the prev and current code changes) I'm only calling 
getAccessibleContext() if accessibleContext is already observed to be non-null. 
I'm trying to be mindful about not constructing the accessibleContext field if 
it's not being used.

(It is weird that we can swap out the `accessibleContext` field; I'm not sure 
if that can have broader implications for assistive technologies that rely on 
the AccessibleContext for info...?)

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

PR Comment: https://git.openjdk.org/jdk/pull/31271#issuecomment-4793196071

Reply via email to