Error: Could not initialize class ru.yandex.clickhouse.ClickHouseUtil - jdbc

I'm using clickhouse-jdbc in my java application. And I'm adding it to pom.xml like this:
<dependency>
<groupId>ru.yandex.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.1.34</version>
</dependency>
And when I run my java application java -jar myapp.jar. It's throwing:
java.lang.NoClassDefFoundError: Could not initialize class
ru.yandex.clickhouse.ClickHouseUtil
And in my packaged jar file, there is also ClickHouseUtil.class. And I'm using Intellij Idea for packaging jar. How can I fix this issue?

The error 'Could not initialize class ....' means that the JVM has already tried and failed to perform static initialization of the class mentioned.
Static initialization of a class involves assigning values to any static fields and running any static { ... } blocks. The class in question is ru.yandex.clickhouse.ClickHouseUtil, and static initialization of this class consists only of setting up the static final field CLICKHOUSE_ESCAPER. This appears to rely on a couple of Guava escaper classes (com.google.common.escape.Escaper and com.google.common.escape.Escapers).
So I suspect that these Guava classes aren't in your packaged JAR file.
It's also worth pointing out that the exception message 'Could not initialize class ....' means that static initialization has already failed. In other words, when this exception is thrown, it is at least the second time the JVM has failed to load the class. It's possible that your app may have reported a more informative error message when the JVM failed to load this class for the first time.

Related

Spring Boot Application - Running jar file gives ResourceFinderException error

Created a jar file for a spring boot multimodule application and ran the jar file using java -jar command. While starting the application, it gives ResourceFinderException. When I analyzed it, the issue is happening because in my ResourceConfig file, i have used the package for my api end points. If I use register(service.class), the application starts fine. Any suggestion how can I provide the package instead of using register? The reason I want to use package is because I have lots of services inside multiple packages and the code looks very ugly if i use register for all the services. The ResourceConfig file looks like below.
public class AppResourceConfig extends ResourceConfig {
public AppResourceConfig {}{
super();
property("jersery.config.beanValidation.enableOutputValidationErrorEntity.server");
**packages("com.api");**
register(GsonProvider.class);
register(RequestContextFilter.class);
register(NotFoundExceptionMapper.class);
register(DefaultExceptionMapper.class);
}
}
Here the issue is with highlighted line: packages("com.api")
If I comment out this code application will be up. Otherwise it is giving org.glassfish.jersey.server.internal.scanning.ResourceFinderException: java.io.FileNotFoundException: api-01.03.00.04-snapshot.jar (No such file or direcotry)
Note: api-01.03.00.04-snapshot.jar is the jar file for one of the module in a project

com.oracle.truffle.polyglot.PolyglotImpl (in unnamed module) cannot access class org.graalvm.polyglot.impl.AbstractPolyglotImpl

I tried to extend scaffolded quarkus demo, https://code.quarkus.io/, with polyglot code for GraalVM:
#GET
#Produces(MediaType.TEXT_PLAIN)
public String hello() {
String out = "From JS:";
try (Context context = Context.create()) {
Value function = context.eval("js", "x => x+1");
assert function.canExecute();
int x = function.execute(41).asInt();
out=out+x;
System.out.println(out);
}
return "hello";
}
I added dependencies to pom.xml as suggested here [https://stackoverflow.com/questions/54384499/illegalstateexception-no-language-and-polyglot-implementation-was-found-on-the]
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>20.1.0</version>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<version>20.1.0</version>
</dependency>
<dependency>
<groupId>org.graalvm.truffle</groupId>
<artifactId>truffle-api</artifactId>
<version>20.1.0</version>
</dependency>
But when I run on cmd line
./mvnw clean package
Test fails with exception, which I do not understand.
2020-06-22 19:26:56,328 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler]
(executor-thread-1) HTTP Request to /hello failed, error id: 996b0479-d836-47a5-bbcb-67bd876f9277-1: org.jboss.resteasy.spi.UnhandledException:
java.lang.IllegalAccessError: superclass access check failed:
class com.oracle.truffle.polyglot.PolyglotImpl (in unnamed module #0x7bf61ba2) cannot access class org.graalvm.polyglot.impl.AbstractPolyglotImpl (in module org.graalvm.sdk)
because module org.graalvm.sdk does not export org.graalvm.polyglot.impl to unnamed module #0x7bf61ba2
UPDATE:
It looks like regression in quarkus, https://github.com/quarkusio/quarkus/issues/10226.
App test is passing when used with quarkus 1.2.1 (instead of 1.5.2).
Look into the mvn dependency:tree -- it turns out that org.graalvm.js:js:20.1.0 depends on org.graalvm.sdk:graal-sdk:19.3.1. I'd personally call that GraalVM JS bug.
If you add an explicit dependency on org.graalvm.sdk:graal-sdk:20.1.0, it should work.
(At least it did for me, but I was getting a different error than you, so not sure.)
EDIT: as I was warned about in the comment, it is not true that org.graalvm.js:js:20.1.0 depends on org.graalvm.sdk:graal-sdk:19.3.1. Instead, there must be something else that forces graal-sdk to 19.3.1, perhaps something from Quarkus. Explicitly managing it to 20.1.0 should still help.
are you maybe executing that on GraalVM 19.3.1? That is known to confuse the system. Our strong suggestion is to EITHER run on a GraalVM (which automatically includes a proper version of Graal.js, no further input needed), OR run on a Stock JDK and import the respective JARs from Maven. If you import (a different version of) our Jars from maven on a GraalVM, then you might run into conflicts like that.

Not working without sonar.language property

I am trying to run the sonarqube task in Gradle. If I don't set the sonar.language property, it throws the next exception for multiple classes:
Exception during analysis of file ...
java.io.IOException: Error while analyzing class ...
It seems weird to me because the property has been deprecated. I would run it with the property set to java, but I have one Groovy test file that I need to include in it.

PAX Exam - Class not found error

I'm working on PAX integration tests for our project and I'm facing few issues with regards to class loading.
I have deployed few bundles in PAX (used karaf container). Once the karaf is up, I could see my bundles and services are up and active. However, in my test cases, I've referred to a Class (not a service nor a component) which will used to during my test execution. The class is resided in the bundle and bundle is up and running successfully, but I'm getting ClassnotFoundError while accessing the class in test case executionas below,
**java.lang.ClassNotFoundException: com.myproject.sample.bundle.DatabaseConfig
at** org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at com.integrationtest.testcases.internal.development.LaunchContainerTest.populateDBProfiles(LaunchContainerTest.java:189)
at com.integrationtest.testcases.internal.development.LaunchContainerTest.testLaunchOSGiContainerWithDefualtSettingsAndSleep(LaunchContainerTest.java:152)
Failed tests:
LaunchContainerTest.testLaunchOSGiContainerWithDefualtSettingsAndSleep:152->populateDBProfiles:189
▒ ClassNotFound
Is it something to do with the container?
As your test itself will also run within the OSGi context you need to adapt your test. The dynamically generated test bundle needs to know that it needs to import the class in question.
For this you can add a specialized probe configuration method. Like the following below:
#ProbeBuilder
public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
//make sure the needed imports are there.
probe.setHeader(Constants.IMPORT_PACKAGE, "*,com.myproject.sample.bundle.*");
return probe;
}

EJB application won't deploy in OC4J with Java7

An EJB application which works using Java6 JRE fails to deploy with Java7, it throws the following error:
14/01/13 13:33:23 WARNING: Application.setConfig Application:
accesscontrolapp is in failed state as initialization failed.
oracle.classloader.util.AnnotatedNoClassDefFoundError:
Missing class: org.apache.crimson.tree.ElementNode
Dependent class: com.sun.enterprise.deployment.xml.EjbBundleNode
Loader: oc4j:10.1.3
Code-Source: .../oc4j_standalone/j2ee/home/lib/oc4j-internal.jar
Configuration: in META-INF/boot.xml in
...\oc4j_standalone\j2ee\home\oc4j.jar
The missing class is not available from any code-source or loader in
the system.
I located the missing class in j2ee/home/lib/crimson_1_1_3.jar so I don't understand, why the error?
The error message refers to META-INF/boot.xml within oc4j.jar, if you look at that file it reads:
<code-source path="lib/crimson_1_1_3.jar" if="java.specification.version == /1\.[5-6]/"/>
This was apparently done to prevent loading of crimson in java 1.4. If you change this to read '[5-9]' then this works for Java 1.7 and presumably 1.8 and 1.9 as well.

Resources