java.sql.Time exception
Asked Answered
H

5

14

does anybody met something like that? After switching to JAVA 9 I faced such problem

Caused by: java.lang.NoClassDefFoundError: java/sql/Time
    at com.google.gson.Gson.<init>(Gson.java:240)
    at com.google.gson.GsonBuilder.create(GsonBuilder.java:569)
    at net.thucydides.core.reports.json.gson.GsonJSONConverter.<init>(GsonJSONConverter.java:50)
    at net.thucydides.core.reports.json.gson.GsonJSONConverter$$FastClassByGuice$$6794eb79.newInstance(<generated>)
    at com.google.inject.internal.DefaultConstructionProxyFactory$FastClassProxy.newInstance(DefaultConstructionProxyFactory.java:89)
    at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:111)
    at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)
    at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:268)
    at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:56)
    at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
    at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
    at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:194)
    at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
    at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:1019)
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1085)
    at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1015)
    ... 25 more
Caused by: java.lang.ClassNotFoundException: java.sql.Time
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:563)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
    ... 42 more

I tried different java version, also gson library was not updated, I mean the same package was working on java 8. Any suggestion?

Haste answered 15/6, 2018 at 14:21 Comment(10)
You need to add the Java SQL module.Knowlton
@Luiggi Mendoza like jar or maven dependency?Haste
oracle.com/corporate/features/understanding-java-9-modules.htmlKnowlton
@ Luiggi Mendoza I've read articles but didn't get how to add sql moduleHaste
Create a module file that contains module <modulename>; requires java.sql;. It's explained in the article, in section Module Declarations.Knowlton
Be aware, maybe you'll need to add more modules.Knowlton
seems like java/sql.TIme is requested by com.google.gson.Gson. So I can't add dependency on module for this libHaste
The java.sql module is mapped to the platform class loader. Is it possible that Gson is using its own URLClassLoader with null as the parent. That would explain the exception in the question.Hoyt
@Alan Bateman do you have any thoughts how to resolve issue?Haste
Did you manage to track down the code that is creating the URLClassLoader with a "null" parent?Hoyt
H
8

for my case it start works after i run it with JAR manifest configured

enter image description here

Haste answered 30/7, 2018 at 9:56 Comment(0)
R
8

Add java.sql to your module-info.java file:

module MODULE_NAME {
    ...
    requires java.sql;
    ...
}
Rightward answered 29/9, 2018 at 14:18 Comment(0)
A
1

java.sql is a module, java9 sql module

Try:

java --module-path lib --add-modules java.sql
Assembled answered 15/6, 2018 at 14:47 Comment(1)
can you please clarify step by step how to add it? Coz line you provided doesn't workHaste
D
1

Gson has default adapters for some SQL types (one of that is java.sql.Time). Since Java 9 the SQL classes are in their own module (java.sql). Most likely that module was not included by default for you when you executed your program.

However, starting with Gson 2.8.9 the dependency on the SQL types is optional. You can use Gson without any issues, even if they are not present.

Discomfort answered 6/11, 2021 at 19:5 Comment(0)
R
0

The following helped me. IDE: Run-> Edit Configurations and in the "Shorten command line" field select the "JAR manifest"

Ridotto answered 6/8, 2019 at 13:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.