B4J Question [problem gone] Occasional Debug crashes

Didier9

Well-Known Member
Licensed User
Longtime User
This is a bit hard to describe.
I am working on this program (the same for several years, just adding new features and fixing bugs) and it seems that recently I started getting crashes when I recompile in debug mode:
B4X:
Waiting for debugger to connect...
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.NullPointerException
	at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:383)
	at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
	... 5 more
java.lang.ExceptionInInitializerError
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at com.sun.javafx.application.LauncherImpl.lambda$launchApplicationWithArgs$155(LauncherImpl.java:352)
	at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
	at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: java.net.SocketException: Connection reset
	at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
	at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
	at b4j.r9_b4j.main.<clinit>(main.java:17)
	... 11 more
Caused by: java.net.SocketException: Connection reset
	at java.net.SocketInputStream.read(SocketInputStream.java:210)
	at java.net.SocketInputStream.read(SocketInputStream.java:141)
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
	at java.io.DataInputStream.readByte(DataInputStream.java:265)
	at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
	at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
	... 13 more
It does not do it every time but once it does it, I have to restart the IDE (or switch to release mode) then I am good again for a little while.
If I switch to release mode after it has crashed in debug mode, then it runs, but if I go back to debug without restarting, it will fail again.
It does it when I do an incremental live update and when I do a complete recompile.
I am using B4J v9.80.
It does it on multiple computers with the same project, 32 or 64 bits Windows 10 Pro with Oracle Java and 8 or 16 GB of RAM.
I am reluctant to post the entire project because it is very large, and it seems to be the only project that does it, so I do not have a small project that does it.
Some guidance as to what to do next to debug this will be appreciated.
 

Didier9

Well-Known Member
Licensed User
Longtime User
Sometimes there are problems coming from third parties reasons...

So a try..catch..log...end try always help... maybe a null value or a network prob...

The program does not even start execution in debug mode (it does the first time after reloading the IDE), so I cannot put a Try/Catch. Then it does work in Release mode, every time...
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Sounds to me an antivirus issue or firewall. Debug mode needs a port
But why would it start the first time?
I did check that if I start the IDE and compile my program in debug mode, I can do incremental compile AS LONG AS I DO NOT CHANGE THE PROGRAM but the problem occurs as soon as I make a change to the source code while the program is stopped on a breakpoint. Things get funky from that point on. If I just restart the program from the breakpoint, it restarts but if I change the code, I cannot do an incremental or full compile until I reload the IDE. I can change the mode to release though so it is strictly a debug issue. It would seem that it may be a port issue but this program does not use IP ports for anything, it does use the serial port though.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Debug mode uses a port, that's why you are only seeing it on debug.

Try disabling the antivirus and look if it works. It is possible that the footprint of your code looks like a virus. That's my theory.
I disabled the Windows Firewall and it seems to work!
I have to work on this so I will confirm later if the problem is gone for good, but if so, that would be annoying but not nearly as much as not being able to debug, so it would be an improvement...
If that turns out to be the issue, how do I get rid of it?
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
I have some weird things with 2 b4j web server running in debug mode. Then now I set one b4j web server in release mode and one in debug without problem
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
The firewall did not fix the problem, it's back :(
Try to run it in a new clean windows setup and free hardware error... to be sure...

May be it is a socket initialization prob.. and need to check if is initialized ... could be anything... May be is a port error... and some other app need to use it...

you must use try catch before the error... and someway restart the job..reset..reinitialize... also use some sleep or wait method

It is difficult to understand the prob without code..and try it
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
1) Try to run it in a new clean windows setup and free hardware error... to be sure...

2) May be it is a socket initialization prob.. and need to check if is initialized ... could be anything... May be is a port error... and some other app need to use it...

3) you must use try catch before the error... and someway restart the job..reset..reinitialize... also use some sleep or wait method

4) It is difficult to understand the prob without code..and try it

1) I have not done that but the problem exists on 3 different machines. These machines are configured roughly the same though.

2) I can debug one time (until I hit a breakpoint and make a change to the code) after the IDE is reloaded. It seems I can break and restart as long as I do not make changes to the code. If I make changes to the code and recompile, I need to reload the IDE. It makes no difference if I recompile the entire project or do an incremental compile using Ctrl-S, the program won't restart either way.

3) no I can't because the program does not start. Look at the first two lines:
B4X:
Waiting for debugger to connect...
java.lang.reflect.InvocationTargetException
I do not get "Program started"
This is what I get the first time I debug after reloading the IDE:
B4X:
Waiting for debugger to connect...
Program started.
...
4) I agree... I have the source code and I can't find it :)

I understand not posting the source code severely hampers the ability to offer help.
I am going to try and narrow the problem down.
I will try to find the most recent version that did not have that bug and work from there.

Thank you all for the suggestions.
 
Upvote 0

rspitzer

Active Member
Interesting, I have had the same issues as you, but as you stated, a restart, seems to cure it. So I just ignored it as a random event.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
I think that if you make the whole routine a sub... and have them all into it... and then try catch endtry... some you can auto restart it...

I think... check some if isinitialized (a simple if)...

Ofcourse this is not a fix - is just skip error (resume next) and restart - you will loose some secs... but will work for you...

all these ofcourse... if this crash not coming every some mins...

ps: also check for "NULL" values, strings, byte arrays, objects/etc with 0 size... before send or before use them after receiving - all these can make troubles!!!
 
Last edited:
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Update: the problem is seemingly gone. I "cleaned" the project and that fixed the issue on two of the 3 computers, but did not immediately fix it on the one I use most. I rebooted it and cleaned the project again and it seems that now all is good. I made no change to the project other than Tools -> Clean Project.

Note that I had this problem only with a certain project. I work on this project on multiple machines, depending on where I happen to be. The source code is shared through Cloud Storage (Sync). It seems as if some project file(s) got corrupted on the main machine, and the problem was carried to the other machines when sharing the project.
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Cloud Storage (Sync)
You should really use git for code.

If you don't like commandline then download GitHub desktop. It is life changing
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Thank you for the reminder about GIT. I may actually give it a try.

The problem I have with version control software in general (I used Perforce way back) is that if they actually work well, they are complex. I agree that you do not necessarily need to understand how they work under the hood to use them, but there lies the problem for me. I am not very trusty of software that hides complexity behind a smart UI. I like to know what it does under the hood. That was the reason why it took me so long to start using Java (through B4X) and still there are many things I do not understand that make me uncomfortable.

But yes, I guess I need to get with the times. My workflow is cumbersome when working on multiple machines, and occasionally errors and screw ups creep up.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
The with command line git. You only need 4 commands

git pull
git add .
git commit -m "description"
git push

Because you work solo, that's all you need.
So when I am done working on a machine, assuming I did not add files (just made some changes to existing files), I just need "git commit -m 'description'" then "git push", and when I start working on the other machine, I do "git pull" and then automatically the files are updated in my workspace?
 
Upvote 0
Top