B4J Question B4JPackager and "WARNING: An illegal reflective access operation has occurred"

drponciano

Member
Licensed User
Longtime User
My program works fine with no warnings if I complie with JDK from Oracle but, if I compile with OpenJDK 11, I get the "Illegal reflective..." warning after a few iterations. That is not a problem when I'm running the app from Java "java -jar myapp.jar" but, if I use B4J Packager, when running the EXE, the program stops after the warning.
Any idea how can I avoid the warning or what is causing it?
 

drponciano

Member
Licensed User
Longtime User
Running from B4J UI the warning is also present in the log area but the program keeps working fine. Not the case with the EXE. Here is the output from run_debug.bat:

Recibo RED 63
PROM 1
Fin de Newdata RED
IRR InstantƔneo 154
main._beep (java line: -1)
java.lang.IllegalAccessException: class anywheresoftware.b4j.object.JavaObject (in module b4j) cannot access class sun.awt.windows.WToolkit (in module java.desktop) because module java.desktop does not export sun.awt.windows to module b4j
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Unknown Source)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at b4j/anywheresoftware.b4j.object.JavaObject.RunMethod(Unknown Source)
at b4j/b4j.example.main._beep(Unknown Source)
at b4j/b4j.example.main._timer_principal_tick(Unknown Source)
at jdk.internal.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at b4j/anywheresoftware.b4a.BA.raiseEvent2(Unknown Source)
at b4j/anywheresoftware.b4a.objects.Timer$TickTack$1.run(Unknown Source)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(Unknown Source)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)


C:\Fuentes\Basic4Mac\ZiECG_JV\Objects\temp\build\bin>pause
Presione una tecla para continuar . . .
 
Last edited:
Upvote 0

drponciano

Member
Licensed User
Longtime User
I found the problem! Now, is there a solution?
The warning is issued the first time the beep routine is called:

B4X:
Sub Beep
   Dim jo As JavaObject
   jo.InitializeStatic("java.awt.Toolkit")
   Dim toolkit As JavaObject = jo.RunMethod("getDefaultToolkit", Null)
   toolkit.RunMethod("beep", Null)
End Sub
 
Upvote 0

Nicola Ciaramellano

Member
Licensed User
Longtime User
I found the problem! Now, is there a solution?
The warning is issued the first time the beep routine is called:

B4X:
Sub Beep
   Dim jo As JavaObject
   jo.InitializeStatic("java.awt.Toolkit")
   Dim toolkit As JavaObject = jo.RunMethod("getDefaultToolkit", Null)
   toolkit.RunMethod("beep", Null)
End Sub
Hi @drponciano,
just a curiosity of mine ... why are you using the toolkit's beep method to reproduce the sound?
 
Upvote 0
Top