Illegal reflective access operation has occured

Having problems with building or using the JCEF Java binding? Ask your questions here.

Illegal reflective access operation has occured

Postby gerelef » Tue Aug 18, 2020 10:54 am

I'm using Java CEF for the front-end development of my application, and I cannot get to run a rudimentary example properly.
I'm using OpenJDK14, but compiling at Java 8 version (as it was specified that compilations above java 8 does not work correctly with jcef).
It's probably worthwhile to note that the jframe does in fact "show up", but once it closes the program does not stop running.
I've been using this guide as an example to get going:
https://medium.com/@daniel.bischoff/int ... f67a677db6

Any idea what could be causing this error, and how can I resolve it ?
Also, are there any official docs to get started in JCEF?

I got an illegal reflective access operation warning when running this code:
Code: Select all
CefApp c = CefApp.getInstance();
        CefClient cli = c.createClient();
        CefBrowser br = cli.createBrowser("https://www.google.gr", OS.isWindows(), false);

        JFrame frame = new JFrame();
        frame.getContentPane().add(br.getUIComponent());

        frame.setVisible(true);

        frame.addWindowListener(new WindowAdapter() {
            @Override public void windowClosing(WindowEvent e) {
                frame.dispose();
                c.dispose();
                // Alternative: CefApp.getInstance().dispose();
            }
        });


Code: Select all
"C:\Program Files\AdoptOpenJDK\jdk-14.0.2.12-hotspot\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1\lib\idea_rt.jar=58819:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\...\Desktop\ProgrammingPractice\logging_test\out\production\logging_test;C:\Users\...\Desktop\ProgrammingPractice\logging_test\lib\jcef.jar;C:\Users\...\Desktop\ProgrammingPractice\logging_test\lib\jogl-all.jar;C:\Users\...\Desktop\ProgrammingPractice\logging_test\lib\gluegen-rt.jar;C:\Users\...\Desktop\ProgrammingPractice\logging_test\lib\jcef-tests.jar;C:\Users\...\Desktop\ProgrammingPractice\logging_test\lib\jogl-all-natives-windows-amd64.jar;C:\Users\...\Desktop\ProgrammingPractice\logging_test\lib\gluegen-rt-natives-windows-amd64.jar com.gerelef.Main
initialize on Thread[AWT-EventQueue-0,6,main] with library path C:\Users\...\Desktop\java-cef-build-bin\bin\lib\win64

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.jogamp.common.os.NativeLibrary$3 (file:/C:/Users/.../Desktop/ProgrammingPractice/logging_test/lib/gluegen-rt.jar) to method java.lang.ClassLoader.findLibrary(java.lang.String)
WARNING: Please consider reporting this to the maintainers of com.jogamp.common.os.NativeLibrary$3
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Exception in thread "AWT-EventQueue-0" Exception in thread "AWT-EventQueue-0" Exception in thread "AWT-EventQueue-0" Exception in thread "AWT-EventQueue-0" Exception in thread "AWT-EventQueue-0" [0818/183723.147:INFO:CONSOLE(0)] "A cookie associated with a cross-site resource at http://gstatic.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.", source: https://www.google.gr/ (0)


My development platform is windows 10, and I'm using this (updated, recently precompiled) distribution of JCEF: https://github.com/jcefbuild/jcefbuild/releases
gerelef
Newbie
 
Posts: 5
Joined: Tue Aug 18, 2020 10:45 am

Re: Illegal reflective access operation has occured

Postby magreenblatt » Tue Aug 18, 2020 12:17 pm

Return false for the 2nd parameter to createBrowser so that it doesn't use off-screen rendering.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Illegal reflective access operation has occured

Postby gerelef » Tue Aug 18, 2020 12:50 pm

magreenblatt wrote:Return false for the 2nd parameter to createBrowser so that it doesn't use off-screen rendering.


Just tried that, and chromium opens up very nicely without exceptions, however now I cannot interact with the JFrame at all, not even resize it, or even press any button either in the browser or the "menu" (I'm referring to the buttons to minimize, close etc.)

Edit: important note, as I was just experimenting with this.
As the application opens, if the window is completely minimized, (as in, chromium isn't visible at all), I'm able to interact with the window. However, once I change the size of the JFrame window with my mouse, it becomes inresponsibe again.
gerelef
Newbie
 
Posts: 5
Joined: Tue Aug 18, 2020 10:45 am

Re: Illegal reflective access operation has occured

Postby magreenblatt » Tue Aug 18, 2020 1:29 pm

How does it behave with the JCEF sample apps?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Illegal reflective access operation has occured

Postby gerelef » Tue Aug 18, 2020 1:42 pm

magreenblatt wrote:How does it behave with the JCEF sample apps?


As I said, I downloaded a binary distribution, from what I believe, is the most recent version JCEF. This distribution is bundled with an example, and the instructions are to run it with the provided run.bat by the provider.
Having said that, the example provided is working very well as intended.

Edit: upon copying and pasting the code from the example into my own example project, it runs without any problem very well. This... is something else.
gerelef
Newbie
 
Posts: 5
Joined: Tue Aug 18, 2020 10:45 am

Re: Illegal reflective access operation has occured

Postby gerelef » Tue Aug 18, 2020 1:57 pm

I'm doing some testing on my own and these two things seem critical so far:
The JFrame should be disposed *after* the CefApp instance gets disposed
Code: Select all
addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                CefApp.getInstance().dispose();
                dispose();
            }
        });


This code section is absolutely critical, and if userOSR boolean is set to true, (or the field windowless_rendering_enabled is set to true) JCef will not run correctly, and will freeze as described above.
Code: Select all
CefSettings settings = new CefSettings();
        settings.windowless_rendering_enabled = useOSR;
        cefApp_ = CefApp.getInstance(settings);


This block of code seems critical as well, provided you want to exit/stop the program from running in the background when the browser is shut down.
Code: Select all
CefApp.addAppHandler(new CefAppHandlerAdapter(null) {
            @Override
            public void stateHasChanged(org.cef.CefApp.CefAppState state) {
                // Shutdown the app if the native CEF part is terminated
                if (state == CefAppState.TERMINATED) System.exit(0);
            }
        });


it is also critical when creating the browser from the client, that the parameter is false.
Code: Select all
browser_ = client_.createBrowser(startURL, false, false);
gerelef
Newbie
 
Posts: 5
Joined: Tue Aug 18, 2020 10:45 am

Re: Illegal reflective access operation has occured

Postby gerelef » Tue Aug 18, 2020 2:03 pm

I have come to a minimal working example without errors that works as expected.
Courtesy of the person who wrote the original jcef app I was provided with, bless their heart.
Code: Select all
        CefApp.addAppHandler(new CefAppHandlerAdapter(null) {
            @Override
            public void stateHasChanged(org.cef.CefApp.CefAppState state) {
                // Shutdown the app if the native CEF part is terminated
                if (state == CefAppState.TERMINATED) System.exit(0);
            }
        });
        CefSettings settings = new CefSettings();
        settings.windowless_rendering_enabled = false;
        CefApp cefApp = CefApp.getInstance(settings);

        CefClient client = cefApp.createClient();
        CefBrowser browser = client.createBrowser("https://www.google.gr", false, false);

        JFrame frame = new JFrame();
        frame.add(browser.getUIComponent());

        frame.pack();
        frame.setSize(800, 600);
        frame.setVisible(true);

        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                CefApp.getInstance().dispose();
                frame.dispose();
            }
        });
gerelef
Newbie
 
Posts: 5
Joined: Tue Aug 18, 2020 10:45 am

Re: Illegal reflective access operation has occured

Postby paulbanks » Tue Aug 25, 2020 5:46 am

gerelef wrote:I have come to a minimal working example without errors that works as expected.
Courtesy of the person who wrote the original jcef app I was provided with, bless their heart.
Code: Select all
        CefApp.addAppHandler(new CefAppHandlerAdapter(null) {
            @Override
            public void stateHasChanged(org.cef.CefApp.CefAppState state) {
                // Shutdown the app if the native CEF part is terminated
                if (state == CefAppState.TERMINATED) System.exit(0);
            }
        });
        CefSettings settings = new CefSettings();
        settings.windowless_rendering_enabled = false;
        CefApp cefApp = CefApp.getInstance(settings);

        CefClient client = cefApp.createClient();
        CefBrowser browser = client.createBrowser("https://www.google.gr", false, false);

        JFrame frame = new JFrame();
        frame.add(browser.getUIComponent());

        frame.pack();
        frame.setSize(800, 600);
        frame.setVisible(true);

        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                CefApp.getInstance().dispose();
                frame.dispose();
            }
        });


It's good to know everything is working fine. You can ask me for help next time. Feel free to do that.
Hey there! Check out my essay writing service later. You might need it for writing needs.
paulbanks
Newbie
 
Posts: 2
Joined: Tue Aug 25, 2020 5:44 am


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 12 guests