Repository: nvaccess/nvda

Issue:
Starting NVDA after a Java application requires a restart of the app for NVDA to read the interface
NVDA problem with java applications 
hello dear fellow programmers and users of NVDA, I am noticing a problem for a while now regarding NVDA   usability with Java applications.  Most of us probably know that java access bridge  has to be enabled for it to work and it does, however there is a problem with accessing the interface when NVDA is restarted and application is still on. The problem is that the application is no longer accessible and NVDA does not pronounce anything on the window unless I  restart the application I am working with. To conclude, basically if I turn off NVDA while am working with the Java application I have to restart the application for NVDA to read the  GUI.
I tested same with Jaws and a problem does not exist.  I'm writing this now because I never saw this problem being addressed before and this problem exists for very long time.  I don't know myself where the problem could be, but I know for a fact that this problem affects any Java application.
So I am wondering now whether this issue can be addressed in future NVDA releases?  Our developers aware of this issue? If yes why it  is not fixed yet?  I am thinking theoretically, if jaws does not have that issue it is possible to theoretically fix the problem.

A  quick note how come NVDA does not have the feature where mouse is moving based on location that NVDA has focus on? The reason I am asking this is that I encountered many situations whereNVDA does not read the application, when using keyboard on its own, however when I hover the mouse over different elements of the application it works without any problems.  I know that NVDA has a feature " move navigation object to mouse " it would be nice however to have the mode whereby it does that automatically is extremely handy in the situations where   regular cursor doesn't work.

Thank you for reading and I hope some of my feature requests can be addressed in the future.


### Steps to reproduce:
Turn on any Java application and restart and NVDA while the application is on

### Actual behavior:
The NVDA is silent and does not pronounce any elements on the screen.

### Expected behavior:
theoretically it should work as if I started the java application while NVDA is on.

### System configuration
NVDA version 2019.2 installed on my pc.
Using Windows version 10.0.17763 workstation




Discussion:
This is just a random thought, but it seems Jaws still uses a hook into 
windows display code on windows start up. Could it be that they are using 
this instead of the access bridge?
 Brian

bglists@blueyonder.co.uk
Sent via blueyonder.
Please address personal E-mail to:-
briang1@blueyonder.co.uk, putting 'Brian Gaff'
in the display name field.
Newsgroup monitored: alt.comp.blind-users 


I always thought this was a limitation in Java, did not know that JAWS doesn't have this issue. I agree that it is slightly annoying to require restarting the app.

I will try to have a short look into this in the near future.
I think it is important, just get rid of this bug for ever, and that
is it, java is sorted as much as it can be.

On 9/30/19, Leonard de Ruijter <notifications@github.com> wrote:
> I always thought this was a limitation in Java, did not know that JAWS
> doesn't have this issue. I agree that it is slightly annoying to require
> restarting the app.
>
> I will try to have a short look into this in the near future.
>
> --
> You are receiving this because you authored the thread.
> Reply to this email directly or view it on GitHub:
> https://github.com/nvaccess/nvda/issues/10296#issuecomment-536401642

Quick investigation reveals that the `isJavaWindow` function on the access bridge DLL returns False on the window of the application, even though it is a Java window. This is pretty strange.
One possibility would be changing `JABHandler.isJavaWindow` to return True when the access bridge is available and the window class is `SunAwtFrame`. I think in these cases, even though we may yield the JABWindow class in possibly faulty cases, `kwargsFromSuper` should still report False.

@michaelDCurran: May I have your onion here before filing a pr with the suggested change?
@leonardder  so I am assuming isJavaWindow does however work correctly on SunAwtFrame if the app is started after NVDA starts? Or are you saying that isJavaWindow always returns false for this window?
@leonardder What is the status of your investigation? This has been brought again on NVDA users list hence my question.

Resolving patch:
diff --git a/source/JABHandler.py b/source/JABHandler.py
--- a/source/JABHandler.py
+++ b/source/JABHandler.py
@@ -746,13 +746,13 @@ def initialize():
 	except WindowsError:
 		raise NotImplementedError("dll not available")
 	_fixBridgeFuncs()
-	bridgeDll.Windows_run()
 	# Accept wm_copydata and any wm_user messages from other processes even if running with higher privileges
 	if not windll.user32.ChangeWindowMessageFilter(winUser.WM_COPYDATA, 1):
 		raise WinError()
 	for msg in range(winUser.WM_USER + 1, 0xffff):
 		if not windll.user32.ChangeWindowMessageFilter(msg, 1):
 			raise WinError()
+	bridgeDll.Windows_run()
 	# Register java events
 	bridgeDll.setFocusGainedFP(internal_event_focusGained)
 	bridgeDll.setPropertyActiveDescendentChangeFP(internal_event_activeDescendantChange)


Test patch: