B4J Question OKHttputils has a FileNotFoundException

xulihang

Active Member
Licensed User
Longtime User
I never encounter this error on my computer, but my users frequently report this to me. I cannot figure out the reason.

This happens when the app makes an HTTP request continuously (>2 times per second, sample code). Does this has anything to do with OKHttpUtils?

B4X:
error: java.io.FileNotFoundException: C:\Users\zero4\AppData\Local\Temp\14 (Access denied 拒绝访问。)
StackTrace: java.io.FileNotFoundException: C:\Users\zero4\AppData\Local\Temp\14 (�ܾ����ʡ�)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(Unknown Source)
at java.io.FileOutputStream.(Unknown Source)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:439)
at org.xulihang.imagetrans.httputils2service._hc_responsesuccess(httputils2service.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.BA$3.run(BA.java:247)
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(Unknown Source)
 
Last edited:

xulihang

Active Member
Licensed User
Longtime User
After I changed the temp folder's path, the user has not encountered this problem for now. For users having this problem, I may provide a setting so that they can specify a temp folder.
 
Upvote 0

xulihang

Active Member
Licensed User
Longtime User
My guess is that another process locks the file. Might be an anti-virus software.

You can change the TempFolder and see if it makes any difference.

B4X:
HttpUtils2Service.Service_Create
 HttpUtils2Service.TempFolder = xui.DefaultFolder
There are many users reporting this error (https://github.com/xulihang/ImageTrans-docs/issues/358). I think the filename of the temp files should be a unique name instead of a number to avoid such a problem.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
This happen to me recently when I try to use openjdk 17 and 19. My temporary folder name is 2. Try Catch doesn't suppress the error. I thought problem is my server https or let's encrypt not valid so I tried add HU2_ACCEPTALL.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I try further testing on another project. The first job call is succeed but when I try to make second call, it failed.
B4X:
Waiting for debugger to connect...
Program started.
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Error occurred on line: 93 (HttpUtils2Service)
java.io.FileNotFoundException: C:\Users\aeric\AppData\Local\Temp\2 (Access is denied)
    at java.base/java.io.FileOutputStream.open0(Native Method)
    at java.base/java.io.FileOutputStream.open(FileOutputStream.java:298)
    at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:237)
    at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:465)
    at com.puterise.todo.b4x.httputils2service._hc_responsesuccess(httputils2service.java:143)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA$3.run(BA.java:265)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I try further testing on another project. The first job call is succeed but when I try to make second call, it failed.
B4X:
Waiting for debugger to connect...
Program started.
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Error occurred on line: 93 (HttpUtils2Service)
java.io.FileNotFoundException: C:\Users\aeric\AppData\Local\Temp\2 (Access is denied)
    at java.base/java.io.FileOutputStream.open0(Native Method)
    at java.base/java.io.FileOutputStream.open(FileOutputStream.java:298)
    at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:237)
    at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:465)
    at com.puterise.todo.b4x.httputils2service._hc_responsesuccess(httputils2service.java:143)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA$3.run(BA.java:265)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)
The folder seems contain some temporary files which are not properly deleted when I uninstall a program, in my case CheckPoint VPN client.
I renamed the folder and now the problem is gone. If you think it is safe to delete the folder then just delete it.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Another thread with similar issue as mine.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
...I will share my last experience with an api... when not having success... have same errors.. but using responseerror saved my day with a try catch end try too...

So ... after wait for not only check for success but for error too... saved my day (actually my month)
 
Upvote 0
Top