Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix maxlength #2

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open

Hotfix maxlength #2

wants to merge 47 commits into from

Conversation

@koppor
Copy link
Owner Author

koppor commented Apr 16, 2024

Upload action downgrade because of actions/upload-artifact#485

@koppor koppor mentioned this pull request Apr 16, 2024
6 tasks
@@ -362,6 +362,7 @@ private String GetText(int maxLength) {
String text = (String)getAttribute(TEXT);
if (text == null) return null;
validateRange(text);
maxLength = Math.max(-1, maxLength);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koppor when the issue at hand happens, GetText(int maxLength) is called from native (GlassTextRangeProvider::GetText), and gets an unexpected value, which is maxLength = Integer.MAX_VALUE (so maxLength = +2147483647).

Note that if you add to that number any start positive value, it gives Integer.MIN_VALUE+start (that is -2147483647+start), and that is what leads to think of "negative" values for maxLength, but that is not the case.

Therefore, a better fix is either:

maxLength = maxLength == Integer.MAX_VALUE ? -1 : maxLength;

or:

int endOffset = maxLength < Integer.MAX_VALUE && maxLength != -1 ? Math.min(end, start + maxLength) : end;

The patch/workaround is easy in this case.

However, the hard part is finding out why it is happening for some Windows users and not for everybody.

And also, if WinTextRangeProvider should be called only when some accessibility feature is enabled (like Narrator), why are there reports from users without any such feature (at least that they are aware of)?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jperedadnr Thank you so much for the explanation!

However, the hard part is finding out why it is happening for some Windows users and not for everybody.

Fortunately, there is a reproducer now: Install the DeepL app (https://www.deepl.com/app). I am (unfortunately) serious on that. - https://stackoverflow.com/a/78340343/873282 contains more details for the reproducer.

why are there reports from users without any such feature (at least that they are aware of)

I would assume that helper apps trying to read from components from the screen use accessibility features to get the text content.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw your answer, and I've tried it myself, but I'm on those that can't reproduce this issue in any way on my Windows machine (I have latest Windows 11 23H2).

Using DeepL doesn't trigger calls to WinRangeTextProvider for me.

I get these for instance using Narrator. However, even then, all maxLength values are "normal".

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using Windows 11 23H2 Build 22631.3447 with AMD graphics card. On my Windows 10 machine, it also appeared. Thus, I thought, it would be reproducible.

(Need to leave now. I will fire up a VM on Azure tonight and try to reproduce it there. In parallel, I asked JabRef developers to test and post their setup here. Maybe, we can narrow down the setups somehow.)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is important to switch on/off the deepl app in the residential area (system tray, lower right corner). In jabref, I can even recover from the crash by closing the deepl app in the system tray, then getting back to it by opening the app again. Pretty funny.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment: -1 and Integer.MAX_VALUE both seem to be reasonable values for an unlimited length. Maybe, the accessibility developers of Microsoft like the latter more.

The code part start + maxLength could be changed to Math.max(maxLength, start + maxLength). Then any value around Integer.MAX_VALUE would work.

IMHO WinTextProvider#GetText should also be able to handle Integer.MAX_VALUE-2 - the caller cannot know the values of start used, because it does not pass start and should not track state of the called instance of WinTextProvider.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My proposal is in 5f2a296 (#2)

-       int endOffset = maxLength != -1 ? Math.min(end, start + maxLength) : end;
+       int endOffset = maxLength >= 0 ? Math.min(end, Math.max(start + maxLength, maxLength)) : end;

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jperedadnr The above change leads to a working JabRef. (Thank you for sharing your thoughts with Integer.MAX_VALUE.) Now, how to get this into JFX?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just filed openjdk#1442. If you came up with a better solution, I just withdraw. Just wanted to share it more visible (also (hopefully) to reduce load from you).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks, now let's see what reviewers say about it.

While I guess that your fix is as good as what I also suggested, if you follow my comments in the JBS issue, it might be that the change should be needed in the native side after all, discarding this MAX_VALUE for instance, before forwarding the call to (java) GetText.

As in: why do we have accessibility calls for something we don't expect?

@koppor
Copy link
Owner Author

koppor commented Apr 17, 2024

Reproducers

main variant ver yes no
11 23H2 22631.3447 koppor (locally and on Azure), 2024-04-17, dfw63, 2024-04-17, Loey Ghreeb (regular user), Super3001, jperedadnr jperedadnr, 2024-04-17 (admin), Loey Ghreeb (admin), koppor (admin)
11 22H2 10.0.22621.3447 koppor, 2024-04-17 (Azure) -
10 22H2 10.0.19045.4291 koppor, 2024-04-17 (locally, Azure), calixtus (locally) -

@calixtus
Copy link

yes: Edition Windows 10 Pro 22H2, build 19045.4291

@LoayGhreeb
Copy link

Windows 11 23H2 (build 22631.3447)

  • No: main user account (administrator).
  • Yes: new standard local user.

@jperedadnr
Copy link

jperedadnr commented Apr 17, 2024

create a user account, allow it to be used using Remote Desktop, connect, login, start DeepL

That finally helped...
I can reproduce it now as well!! (either from remote connection or directly with the regular user)

@Super3001
Copy link

yes: Win11, 23H2, version=22631.3447

@koppor
Copy link
Owner Author

koppor commented Apr 18, 2024

I contacted DeepL regarding that issue. I have support "Request no. 405861".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants