java.lang.IllegalStateException: Unable to load cache item - jpa

The above exception is thrown from a unit test when I add Java modularity to my project. I cannot find a solution to this exception.
I have added to MAVEN_OPTS
--add-opens java.base/java.lang=ALL-UNNAMED
And the same in the configuration of the surefire plugin (to no avail) because the following is part of the stacktrace:
throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to module com.google.guice
My project is a maven multiproject with two modules:
module org.veary.debs.api {
exports org.veary.debs.api;
exports org.veary.debs.api.model;
exports org.veary.debs.api.dao;
}
module org.veary.debs.db {
exports org.veary.debs.db;
requires com.google.guice;
requires com.google.guice.extensions.persist;
requires java.persistence;
requires javax.inject;
requires org.veary.debs.api;
}
Here is a snippet of the first section of the stacktrace. Any help would be appreciated.
INFO: An exception was caught and reported. Message: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,by
te[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to module com.google.guice
java.lang.IllegalStateException: Unable to load cache item
at com.google.guice#4.2.2/com.google.inject.internal.cglib.core.internal.$LoadingCache.createEntry(LoadingCache.java:79)
at com.google.guice#4.2.2/com.google.inject.internal.cglib.core.internal.$LoadingCache.get(LoadingCache.java:34)
at com.google.guice#4.2.2/com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116)
at com.google.guice#4.2.2/com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:291)
at com.google.guice#4.2.2/com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:65)
at com.google.guice#4.2.2/com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:258)
at com.google.guice#4.2.2/com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:207)
at com.google.guice#4.2.2/com.google.inject.internal.ProviderMethod.create(ProviderMethod.java:69)
at com.google.guice#4.2.2/com.google.inject.internal.ProviderMethodsModule.createProviderMethod(ProviderMethodsModule.java:272)
at com.google.guice#4.2.2/com.google.inject.internal.ProviderMethodsModule.getProviderMethods(ProviderMethodsModule.java:116)
at com.google.guice#4.2.2/com.google.inject.internal.ProviderMethodsModule.configure(ProviderMethodsModule.java:100)
at com.google.guice#4.2.2/com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:344)
at com.google.guice#4.2.2/com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:353)
at com.google.guice#4.2.2/com.google.inject.spi.Elements.getElements(Elements.java:103)
at com.google.guice#4.2.2/com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:137)
at com.google.guice#4.2.2/com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
at com.google.guice#4.2.2/com.google.inject.Guice.createInjector(Guice.java:87)
at com.google.guice#4.2.2/com.google.inject.Guice.createInjector(Guice.java:69)
at com.google.guice#4.2.2/com.google.inject.Guice.createInjector(Guice.java:59)
at org.veary.debs.db/org.veary.debs.tests.PersistenceTest.testAccountDao(PersistenceTest.java:43)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)

You need to check that you have correct java version, use this command:
java --version
If it's not version 11 configure java to version 11. If you already have multiple java installed use this command:
alternatives --config java
and select java 11

Related

failed to get TestNG version from class: java.lang.IllegalArgumentException: invalid version "[WORKING]": non-numeric "[WORKING]

failed to get TestNG version from class: java.lang.IllegalArgumentException: invalid version "[WORKING]": non-numeric "[WORKING]
When i try to run my testCases with TestNG.,i am getting the below exception (INVALID VERSION)
Eclipse Version: 4.25
TestNG Jar: 7.6.1
TestNG Plugin Version: 7.4.0
I tried with upgrading and downgrading the versions of eclipse and testNG Plugin
[RemoteTestNG] failed to get TestNG version from class: java.lang.IllegalArgumentException: invalid version "[WORKING]": non-numeric "[WORKING]"
[RemoteTestNG] now trying to parse the version from pom.properties
[RemoteTestNG] now trying to parse the version from MANIFEST.MF
[RemoteTestNG] parsing TestNG version at jar:file:///C:/Users/Hp%20ProBook%20430%20G7/.m2/repository/org/testng/testng/7.6.1/testng-7.6.1.jar!/META-INF/MANIFEST.MF
[RemoteTestNG] detected TestNG version 7.6.1
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
org.testng.TestNGException:
An error occurred while instantiating class restAssuredBasics.testNG: Unable to make public restAssuredBasics.testNG() accessible: module DemoProject does not "exports restAssuredBasics" to module org.testng
at org.testng#7.6.1/org.testng.internal.objects.SimpleObjectDispenser.createInstance(SimpleObjectDispenser.java:99)
at org.testng#7.6.1/org.testng.internal.objects.SimpleObjectDispenser.dispense(SimpleObjectDispenser.java:40)
at org.testng#7.6.1/org.testng.internal.objects.GuiceBasedObjectDispenser.dispense(GuiceBasedObjectDispenser.java:28)
at org.testng#7.6.1/org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:106)
at org.testng#7.6.1/org.testng.internal.ClassImpl.getInstances(ClassImpl.java:136)
at org.testng#7.6.1/org.testng.TestClass.getInstances(TestClass.java:129)
at org.testng#7.6.1/org.testng.TestClass.initTestClassesAndInstances(TestClass.java:109)
at org.testng#7.6.1/org.testng.TestClass.init(TestClass.java:101)
at org.testng#7.6.1/org.testng.TestClass.<init>(TestClass.java:66)
at org.testng#7.6.1/org.testng.TestRunner.initMethods(TestRunner.java:463)
at org.testng#7.6.1/org.testng.TestRunner.init(TestRunner.java:335)
at org.testng#7.6.1/org.testng.TestRunner.init(TestRunner.java:288)
at org.testng#7.6.1/org.testng.TestRunner.<init>(TestRunner.java:218)
at org.testng.remote.support.RemoteTestNG6_12$1.newTestRunner(RemoteTestNG6_12.java:33)
at org.testng.remote.support.RemoteTestNG6_12$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_12.java:66)
at org.testng#7.6.1/org.testng.ITestRunnerFactory.newTestRunner(ITestRunnerFactory.java:52)
at org.testng#7.6.1/org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:706)
at org.testng#7.6.1/org.testng.SuiteRunner.init(SuiteRunner.java:225)
at org.testng#7.6.1/org.testng.SuiteRunner.<init>(SuiteRunner.java:115)
at org.testng#7.6.1/org.testng.TestNG.createSuiteRunner(TestNG.java:1349)
at org.testng#7.6.1/org.testng.TestNG.createSuiteRunners(TestNG.java:1325)
at org.testng#7.6.1/org.testng.TestNG.runSuitesLocally(TestNG.java:1167)
at org.testng#7.6.1/org.testng.TestNG.runSuites(TestNG.java:1099)
at org.testng#7.6.1/org.testng.TestNG.run(TestNG.java:1067)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make public restAssuredBasics.testNG() accessible: module DemoProject does not "exports restAssuredBasics" to module org.testng
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Constructor.java:188)
at java.base/java.lang.reflect.Constructor.setAccessible(Constructor.java:181)
at org.testng#7.6.1/org.testng.internal.objects.SimpleObjectDispenser.instantiateUsingDefaultConstructor(SimpleObjectDispenser.java:177)
at org.testng#7.6.1/org.testng.internal.objects.SimpleObjectDispenser.createInstance(SimpleObjectDispenser.java:87)
... 26 more

Eclipse Google Cloud plugin Unable to start DevAppServer: InaccessibleObjectException: Unable to make static java.net.URLStreamHandler

Trying to get a basic setup working to run the local Google App Engine running in Eclipse using the Google Cloud Tools for Eclipse, but I keep getting the error below when starting the server using the Run As -> App Engine option.
I believe my environment is good because I am able to run the test application with a local app server from the command line using the java_dev_appserver command, so the problem seems specific to the Eclipse environment.
at com.google.appengine.tools.development.DevAppServerFactory.doCreateDevAppServer(DevAppServerFactory.java:383)
at com.google.appengine.tools.development.DevAppServerFactory.createDevAppServer(DevAppServerFactory.java:315)
at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:385)
at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:59)
at com.google.appengine.tools.development.DevAppServerMain.run(DevAppServerMain.java:259)
at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:250)
Caused by: java.lang.ExceptionInInitializerError
at com.google.appengine.tools.development.DevAppServerImpl.<init>(DevAppServerImpl.java:136)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at com.google.appengine.tools.development.DevAppServerFactory.doCreateDevAppServer(DevAppServerFactory.java:368)
... 5 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make static java.net.URLStreamHandler java.net.URL.getURLStreamHandler(java.lang.String) accessible: module java.base does not "opens java.net" to unnamed module #49c43f4e
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
at com.google.appengine.tools.development.StreamHandlerFactory.<clinit>(StreamHandlerFactory.java:53)
... 12 more
I started from a clean Windows 11 machine, installed Google Cloud SDK, added the app-engine-java component, configured a project, tested by deploying to the cloud with the CLI, installed Eclipse, added the Google Tools for Eclipse plugin, created a sample project using the Google plugin Create Project -> Google App Engine Standard project, and tried to run it.
This is probably very simple but I can't figure it out.
The problem was happening with JRE v17 that installs by default with Eclipse 2021-12. Installing Eclipse with JRE v11 solved the problem. Thanks to greg-449 for putting me on the right track.
Downgrading the JVM to jdk-11.0.13 solved this problem for me as well.
Since I didn't un-install JRE v17, I had to change my eclipse.ini file to point to JDK 11, then update the Eclipse workspace settings for installed JRE's to include JDK 11 and update my workspace properties to use that version by default instead of the JRE 17. I also updated the JDK compliance settings to be JDK 11 instead of 17 and disabled the "release" setting that wanted to still use 17.
Thanks for this post. I had been working on this problem for several days upgrade/downgrading libraries, etc.
I am already on java version 11 and after looking here and there, I have downgraded from 11 to 8 but still facing same issue with eclipse plugin.
java.lang.RuntimeException: Unable to create a DevAppServer
at com.google.appengine.tools.development.DevAppServerFactory.doCreateDevAppServer(DevAppServerFactory.java:378)
at com.google.appengine.tools.development.DevAppServerFactory.createDevAppServer(DevAppServerFactory.java:310)
at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:384)
at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:58)
at com.google.appengine.tools.development.DevAppServerMain.run(DevAppServerMain.java:258)
at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:249)
Caused by: java.lang.ExceptionInInitializerError
at com.google.appengine.tools.development.DevAppServerImpl.<init>(DevAppServerImpl.java:135)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at com.google.appengine.tools.development.DevAppServerFactory.doCreateDevAppServer(DevAppServerFactory.java:363)
... 5 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make static java.net.URLStreamHandler java.net.URL.getURLStreamHandler(java.lang.String) accessible: module java.base does not "opens java.net" to unnamed module #133e16fd
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
at com.google.appengine.tools.development.StreamHandlerFactory.<clinit>(StreamHandlerFactory.java:52)
... 12 more
Any suggestion, What can be the issue?

How to address Scala error in eclipse 2019?

I am trying to do a basic scala HelloWorld in Eclipse 2019 and I am getting an error.
The following is my code and the error it is producing. Can someone please help me address this error in eclipse? Thanks
package hello
object HelloWorld {
def main(args: Array[String]): Unit = {
println("Hello, world!")
}
}
Error:
Exception in thread "main" java.lang.NoClassDefFoundError:
scala/Predef$
at HelloWorld/hello.HelloWorld$.main(HelloWorld.scala:5)
at HelloWorld/hello.HelloWorld.main(HelloWorld.scala)
Caused by: java.lang.ClassNotFoundException: scala.Predef$
at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 2 more
Scala library is already in source path
There are two required places to set your class-path:
Build/compilation time class-path: (i) Right-click on your project, (ii) Buildpath > Configure BuildPath, (iii) Add Library (or jar), (iv) Select the Scala Library. This one you already have as supported by your screenshot.
Run-time compilation class-path: This needs to be explicitly set in the Run-time configuration to also include the scala library: (i) Run configurations..., (ii) Classpath, (iii) Add Jar and use the scala-library jar. For this option, I have not tested whether User vs Bootstrap matters. Furthermore, I was unable to use the Add Library here, only Add jar results in a functioning run within Eclipse.
The second option is the likely cause of the error you are getting.
You need to add Scala library to your classpath.
From Eclipse:
Right-click on your project
Configure Buildpath
Add Library
Select the Scala Library

Caused by: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

I've a gradle project which uses hibernate > 4 . If I run my war file in Apache tomcat, I don't get any error. But when I'm deploying it in Wildfly 8.2 , I get the following exception
Caused by: org.hibernate.InvalidMappingException: Error while parsing file: /G:/wildfly-8.2.0.Final/bin/content/mywar-1.0.war/WEB-INF/classes/com/mysite/
hbm/Role.hbm.xml
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1182) [hibernate-ent
itymanager-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:848) [hibernate-entitymanager-4.3.7.Fi
nal.jar:4.3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845) [hibernate-entitymanager-4.3.7.Fi
nal.jar:4.3.7.Final]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398) [hibernate-core-4.3.7.Final.jar:4.
3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844) [hibernate-entitymanager-4.3.7.Final.
jar:4.3.7.Final]
at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) [jipijapa-hibernate4-3-1.0.1.Final.jar:]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
... 8 more
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.legacyReadMappingDocument(MappingReader.java:375) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:304) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.add(Configuration.java:518) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.add(Configuration.java:514) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.add(Configuration.java:688) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:726) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1177) [hibernate-ent
itymanager-4.3.7.Final.jar:4.3.7.Final]
... 14 more
Caused by: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory Nested exception: org.dom4j.DocumentFactory cannot
be cast to org.dom4j.DocumentFactory
at org.dom4j.io.SAXReader.read(SAXReader.java:484) [dom4j-1.6.1.jar:1.6.1]
I just added a exclude in my Gradle file like
runtime.exclude group: "dom4j"
Now when I run gradle build, dom4j.jar is not created in the war file. Now I can run my deploy and run my project successfully on Wildfly 8.2 without any error. But the real problem starts here.
One of the feature in my project is that, it'll copy a file.xlsm to anotherfile.xlsm where I'm using jars like Apache Poi for those purposes. Here, Apache Poi is trying to access a method in dom4j.jar during file processing, it results in the following error
18:40:13,261 ERROR [io.undertow.request] (default task-29) UT005023: Exception handling request to /app/parentPath/myAction: org.springframework.web.util.NestedSe
rvletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1287) [spring-webmvc-4.1.4.RELEASE.jar:4.1.4
.RELEASE]
Any ideas how I can permanently use dom4j.jar inside my classpath? I've searched for many question and most of them suggested to remove dom4j from classpath. I do successfully run my program by removing it from classpath but it results in the above error during excel file processing. Wasted more than a day on this..!! IS it possible to include dom4j.jar in my classpath?
Update:
I've done a little trick in MANIFEST.MF file.
I've opened
mywar.war > META-INF > MANIFEST.MF
and added
Dependencies: org.dom4j export
at the end of the file and saved it. So if I deploy my war file, I'm successfully running it without any error.
Can someone explain where I've to add this kind of property in my src/ file so that it will be automatcially added to MANIFEST.MF after gradle build..
This exception on wildfly usually occurs when you include a hibernate lib in your war that's different from the wildfly one, since you are deploying to wildfly it already include hibernate so you can set you live as provided in gradle aka compileProvided and deploy without exporting the dependence.
If you still got the same error try declaring the hibernate dependency on manifest but keep the lib as provided it should work fine.
I had this same problem and i know how frustrating this one can be. I was able to resolve this problem. see my answer here. Hope this help

DB2 Native Library can't find libraries

I have an application that depends on loading a db2 driver. I was getting weird errors that the db2jcct2.dll wasn't being loaded, so I made sure to add it to my lib path per: http://www-01.ibm.com/support/docview.wss?uid=swg21419978 and I also made sure it was added to java.library.path at program startup. After doing that I get the following error/stack trace.
com.ibm.db2.jcc.c.SqlException: Failure in loading T2 native library db2jcct2, reason: java.lang.UnsatisfiedLinkError: C:\Program Files (x86)\IBM\SQLLIB\BIN\db2jcct2.dll: Can't find dependent libraries
at com.ibm.db2.jcc.t2.a.a(a.java:31)
at com.ibm.db2.jcc.t2.T2Configuration.<clinit>(T2Configuration.java:84)
at com.ibm.db2.jcc.t2.a.a(a.java:31)
at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:174)
at com.ibm.db2.jcc.t2.T2Configuration.<clinit>(T2Configuration.java:84)
at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)