Kong / unirest-java

Unirest in Java: Simplified, lightweight HTTP client library.
http://kong.github.io/unirest-java/
MIT License
2.58k stars 591 forks source link

java.lang.IllegalAccessError / java.lang.NoClassDefFoundError #435

Closed TooikLeChevalier closed 2 years ago

TooikLeChevalier commented 2 years ago

Describe the bug does not read module com.google.gson

To Reproduce I try to create JavaFX project with request send / receive data from my website when I run on intellij by gradle it's work normally. but when I turn on .app my project and run it makes an error like this :

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at javafx.fxml@18-ea/javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
    at javafx.fxml@18-ea/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
    at javafx.base@18-ea/javafx.event.Event.fireEvent(Unknown Source)
    at javafx.graphics@18-ea/javafx.scene.Node.fireEvent(Unknown Source)
    at javafx.controls@18-ea/com.sun.javafx.scene.control.behavior.TextFieldBehavior.fire(Unknown Source)
    at javafx.controls@18-ea/com.sun.javafx.scene.control.behavior.TextInputControlBehavior.lambda$keyMapping$62(Unknown Source)
    at javafx.controls@18-ea/com.sun.javafx.scene.control.inputmap.InputMap.handle(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
    at javafx.base@18-ea/javafx.event.Event.fireEvent(Unknown Source)
    at javafx.graphics@18-ea/javafx.scene.Scene$KeyHandler.process(Unknown Source)
    at javafx.graphics@18-ea/javafx.scene.Scene.processKeyEvent(Unknown Source)
    at javafx.graphics@18-ea/javafx.scene.Scene$ScenePeerListener.keyEvent(Unknown Source)
    at javafx.graphics@18-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(Unknown Source)
    at javafx.graphics@18-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(Unknown Source)
    at java.base/java.security.AccessController.doPrivileged(Unknown Source)
    at javafx.graphics@18-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$1(Unknown Source)
    at javafx.graphics@18-ea/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
    at javafx.graphics@18-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(Unknown Source)
    at javafx.graphics@18-ea/com.sun.glass.ui.View.handleKeyEvent(Unknown Source)
    at javafx.graphics@18-ea/com.sun.glass.ui.View.notifyKey(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.javafx.reflect.Trampoline.invoke(Unknown Source)
    at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.reflect.MethodUtil.invoke(Unknown Source)
    at javafx.fxml@18-ea/com.sun.javafx.fxml.MethodHelper.invoke(Unknown Source)
    ... 44 more
Caused by: java.lang.IllegalAccessError: class kong.unirest.json.ToObjectMapper (in module fr.eclypsegames.merged.module) cannot access class com.google.gson.JsonElement (in module com.google.gson) because module fr.eclypsegames.merged.module does not read module com.google.gson
    at fr.eclypsegames.merged.module@1.0.0/kong.unirest.json.ToObjectMapper.<clinit>(Unknown Source)
    at fr.eclypsegames.merged.module@1.0.0/kong.unirest.json.JSONElement.<clinit>(Unknown Source)
    at fr.eclypsegames.merged.module@1.0.0/kong.unirest.JsonNode.<init>(Unknown Source)
    at fr.eclypsegames.eclypselauncher@1.0.0/fr.eclypsegames.eclypselauncher.Login.checkLogin(Unknown Source)
    at fr.eclypsegames.eclypselauncher@1.0.0/fr.eclypsegames.eclypselauncher.Login.onConnectionButtonClick(Unknown Source)
    ... 54 more

and if y retry to send agin the data the error turn on :

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at javafx.fxml@18-ea/javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
    at javafx.fxml@18-ea/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
    at javafx.base@18-ea/javafx.event.Event.fireEvent(Unknown Source)
    at javafx.graphics@18-ea/javafx.scene.Node.fireEvent(Unknown Source)
    at javafx.controls@18-ea/javafx.scene.control.Button.fire(Unknown Source)
    at javafx.controls@18-ea/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source)
    at javafx.controls@18-ea/com.sun.javafx.scene.control.inputmap.InputMap.handle(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
    at javafx.base@18-ea/javafx.event.Event.fireEvent(Unknown Source)
    at javafx.graphics@18-ea/javafx.scene.Scene$MouseHandler.process(Unknown Source)
    at javafx.graphics@18-ea/javafx.scene.Scene.processMouseEvent(Unknown Source)
    at javafx.graphics@18-ea/javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
    at javafx.graphics@18-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
    at javafx.graphics@18-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
    at java.base/java.security.AccessController.doPrivileged(Unknown Source)
    at javafx.graphics@18-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(Unknown Source)
    at javafx.graphics@18-ea/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
    at javafx.graphics@18-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
    at javafx.graphics@18-ea/com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
    at javafx.graphics@18-ea/com.sun.glass.ui.View.notifyMouse(Unknown Source)
    at javafx.graphics@18-ea/com.sun.glass.ui.mac.MacView.notifyMouse(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.javafx.reflect.Trampoline.invoke(Unknown Source)
    at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at javafx.base@18-ea/com.sun.javafx.reflect.MethodUtil.invoke(Unknown Source)
    at javafx.fxml@18-ea/com.sun.javafx.fxml.MethodHelper.invoke(Unknown Source)
    ... 45 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class kong.unirest.json.JSONObject
    at fr.eclypsegames.merged.module@1.0.0/kong.unirest.JsonNode.<init>(Unknown Source)
    at fr.eclypsegames.eclypselauncher@1.0.0/fr.eclypsegames.eclypselauncher.Login.checkLogin(Unknown Source)
    at fr.eclypsegames.eclypselauncher@1.0.0/fr.eclypsegames.eclypselauncher.Login.onConnectionButtonClick(Unknown Source)
    ... 55 more

Environmental Data:

ryber commented 2 years ago

Unirest is just a plain old library, it's not explicitly designed for modules and I am unfamiliar with whatever '''fr.eclypsegames.merged.module''' is (it's not part of unirest).

Can you provide a project somewhere with the issues re-created? Not with Gradle either, just plain old Maven.

TooikLeChevalier commented 2 years ago

fr.eclypsegames is the call of my package and merged.module I think is the call of step to compile commande into .app

this is all step is use for create .app and during this process create auto an merged.module

> Task :compileJava
> Task :processResources
> Task :classes
> Task :jar
> Task :prepareMergedJarsDir
> Task :createMergedModule
> Task :createDelegatingModules
> Task :prepareModulesDir
> Task :jlink
> Task :jpackageImage
> Task :jpackage

moreover I didn't have the possibility to recreate in Maven because I didn't know how use

In addition I send more information :

HttpResponse<String> response = Unirest.post(uri).header("accept", "application/json").header("Content-Type", "application/json").body(new JsonNode(json)).asString();

uri : is https address json : contains json argument for POST methode

module-info.java

module fr.eclypsegames.eclypselauncher {
    requires javafx.controls;
    requires javafx.fxml;
    requires java.desktop;
    requires javafx.web;
    requires java.net.http;
    requires com.google.gson;
    requires unirest.java;
    requires unirest.object.mappers.gson;

    opens fr.eclypsegames.eclypselauncher to javafx.fxml, com.google.gson, unirest.java, unirest.object.mappers.gson;
    exports fr.eclypsegames.eclypselauncher;
}

build.gradle dependencies

dependencies {
    implementation("com.google.code.gson:gson:2.9.0")
    implementation("com.konghq:unirest-java:3.13.6")
    implementation('com.konghq:unirest-object-mappers-gson:3.13.6')
}
ryber commented 2 years ago

This appears to be some artifact of your launcher or environment. You need Unirest and all of it's dependencies to be on the class path and allowed across modules. There isn't anything special about unirest itself in regards to dependencies. It's quite ordinary. I have no insights into what is happening inside your code.

Siedlerchr commented 2 years ago

You probably need to adjust the creeation of the merged modules to include gson. For us it works fine with modularity https://github.com/JabRef/jabref/blob/main/build.gradle