Upgrade to Java 17 throws java.lang.RuntimeException: Error creating extended parser class: Could not determine whether class has already been loaded - runtimeexception

I am using jtwig lib and the code was working fine but when we upgraded to Java 17, I am getting the below mention runtime exception.
Below is the method and throws RuntimeException while calling template.render()
String renderDescription(String templatePath,String userId, String caseId) {
JtwigTemplate template =
JtwigTemplate.classpathTemplate(templatePath);
JtwigModel model = JtwigModel.newModel()
.with("userId", userId)
.with("caseId", caseId)
.with("statusPageUrlTemplate",
config.getStatusPageUrlTemplate());
return template.render(model);
}
java.lang.RuntimeException: Error creating extended parser class: Could not determine whether class 'org.jtwig.parser.parboiled.base.BooleanParser$$parboiled' has already been loaded
at org.parboiled.Parboiled.createParser(Parboiled.java:58)
at org.jtwig.parser.parboiled.ParserContext.instance(ParserContext.java:31)
at org.jtwig.parser.parboiled.ParboiledJtwigParser.parse(ParboiledJtwigParser.java:37)
at org.jtwig.parser.cache.InMemoryConcurrentPersistentTemplateCache.get(InMemoryConcurrentPersistentTemplateCache.java:39)
at org.jtwig.parser.CachedJtwigParser.parse(CachedJtwigParser.java:19)
at org.jtwig.JtwigTemplate.render(JtwigTemplate.java:98)
at org.jtwig.JtwigTemplate.render(JtwigTemplate.java:74)

I was facing a similar issue after upgrading JVM version, and I found that adding this environment variable helped:
JDK_JAVA_OPTIONS=--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED
I believe it has something to do with stricter default limits on reflection when trying to inspect built-in classes.

Related

Why am I getting "java.lang.NoClassDefFoundError: Could not initialize class io.mockk.impl.JvmMockKGateway" when using quarkusDev task in IntelliJ?

I am using Gradle 7.5, Quarkus 2.12.3 and mockk 1.13.3. When I try to run quarkusDev task from command line and then start continuous testing (by pressing r), then all tests pass OK.
However, when I do the same as from IntelliJ (as gradle run configuration), all tests fail with error:
java.lang.NoClassDefFoundError: Could not initialize class io.mockk.impl.JvmMockKGateway
How can I fix that?
Masked thrown exception
After much debugging I found the problem. The thrown exception actually originates in HotSpotVirtualMachine.java and is thrown during attachment of ByteBuddy as a java agent. Here is the relevant code;
// The tool should be a different VM to the target. This check will
// eventually be enforced by the target VM.
if (!ALLOW_ATTACH_SELF && (pid == 0 || pid == CURRENT_PID)) {
throw new IOException("Can not attach to current VM");
}
Turning check off
So the check can be turned off by setting ALLOW_ATTACH_SELF constant to true. The constant is set from a system property named jdk.attach.allowAttachSelf:
String s = VM.getSavedProperty("jdk.attach.allowAttachSelf");
ALLOW_ATTACH_SELF = "".equals(s) || Boolean.parseBoolean(s);
So, in my case, I simply added the following JVM argument to my gradle file and tests started to pass:
tasks.quarkusDev {
jvmArgs += "-Djdk.attach.allowAttachSelf"
}

UnsupportedOperationException when using enum in Java 11, works fine in Java 8

I am porting an existing application Java 7 to Java 11 (Drools 7.42.0). The application works as expected if I compile as Java 1.8 and deploy on Java 11 container (Weblogic 14). But if I compile the same code in Java 11, I get the following error. The only change between 1.8 and 11 is the java compiler level in Maven pom.
I have ASM7 as a dependency in Maven.
Caused by: java.lang.UnsupportedOperationException: This feature requires ASM7
at org.mvel2.asm.ClassVisitor.visitNestMember(ClassVisitor.java:236)
at org.mvel2.asm.ClassReader.accept(ClassReader.java:651)
at org.mvel2.asm.ClassReader.accept(ClassReader.java:391)
at org.drools.core.util.asm.ClassFieldInspector.processClassWithByteCode(ClassFieldInspector.java:107)
at org.drools.core.util.asm.ClassFieldInspector.processClassWithByteCode(ClassFieldInspector.java:114)
at org.drools.core.util.asm.ClassFieldInspector.<init>(ClassFieldInspector.java:86)
at org.drools.core.util.asm.ClassFieldInspector.<init>(ClassFieldInspector.java:74)
at org.drools.core.base.ClassFieldAccessorFactory.getClassFieldInspector(ClassFieldAccessorFactory.java:157)
at org.drools.core.base.ClassFieldAccessorFactory.getFieldType(ClassFieldAccessorFactory.java:141)
at org.drools.core.base.ClassFieldAccessorStore.getFieldType(ClassFieldAccessorStore.java:295)
at org.drools.compiler.rule.builder.PatternBuilder.getValueType(PatternBuilder.java:1079)
at org.drools.compiler.rule.builder.PatternBuilder.normalizeExpression(PatternBuilder.java:1047)
at org.drools.compiler.rule.builder.PatternBuilder.buildExpression(PatternBuilder.java:965)
at org.drools.compiler.rule.builder.PatternBuilder.buildCcdDescr(PatternBuilder.java:942)
at org.drools.compiler.rule.builder.PatternBuilder.build(PatternBuilder.java:767)
at org.drools.compiler.rule.builder.PatternBuilder.processConstraintsAndBinds(PatternBuilder.java:620)
at org.drools.compiler.rule.builder.PatternBuilder.build(PatternBuilder.java:187)
at org.drools.compiler.rule.builder.PatternBuilder.build(PatternBuilder.java:154)
at org.drools.compiler.rule.builder.PatternBuilder.build(PatternBuilder.java:136)
at org.drools.compiler.rule.builder.GroupElementBuilder.build(GroupElementBuilder.java:66)
at org.drools.compiler.rule.builder.RuleBuilder.build(RuleBuilder.java:107)
at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.internalAddRule(KnowledgeBuilderImpl.java:1183)
at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.addRule(KnowledgeBuilderImpl.java:1178)
at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.lambda$null$3(KnowledgeBuilderImpl.java:1134)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:290)
at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:746)
I noticed while debugging that this was caused by an "enum" in our code. Drools works fine if we remove the enum and use constants. The error seems to suggest that this could happen to any nested classes. Is there a better way to handle this other than changing our code to remove nested classes and enums?
I see that in the class org.drools.core.util.asm.ClassFieldInspector, the API is set to ASM5, but MVEL is expecting ASM7. But not sure why it would work in Java 8 and not in Java 11. Any suggestions?
ClassFieldVisitor(final Class< ? > cls,
final boolean includeFinalMethods,
final ClassFieldInspector inspector) {
super(Opcodes.ASM5);
this.clazz = cls;
this.includeFinalMethods = includeFinalMethods;
this.inspector = inspector;
}
Disclaimer: I'm one of the Drools developers
That's interesting as we might not emit valid ASM code.
Please file a bug on https://issues.redhat.com so that we can fix it
Thank you very much

I need help upgrading OroCommerce to 4.1.1

I just upgraded from 3.1.17 to 4.1.1 and I'm finding a problem with my shopping lists.
When I get to /customer/shoppinglist/5064 I see this:
Looking at my log files from production I see:
[2020-06-23 17:42:56] request.CRITICAL: Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\UndefinedMethodError: "Attempted to call an undefined method named "getDigitalAsset" of class "Proxies\__CG__\Oro\Bundle\AttachmentBundle\Entity\File"." at /usr/share/nginx/html/oroapp/vendor/oro/platform/src/Oro/Bundle/DigitalAssetBundle/Provider/FileTitleProvider.php line 47 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Attempted to call an undefined method named \"getDigitalAsset\" of class \"Proxies\\__CG__\\Oro\\Bundle\\AttachmentBundle\\Entity\\File\". at /usr/share/nginx/html/oroapp/vendor/oro/platform/src/Oro/Bundle/DigitalAssetBundle/Provider/FileTitleProvider.php:47)"} []
I went to look at the code and I see that in fact there is no method getDigitalAsset in oro/platform/src/Oro/Bundle/DigitalAssetBundle/Provider/FileTitleProvider.php, nor in the proxy... how can this be?
I checked this on my VM (where the problem is not happening) and I see that there's this definition in the proxy class:
/**
* {#inheritDoc}
*/
public function getDigitalAsset()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getDigitalAsset', []);
return parent::getDigitalAsset();
}
But again, I don't see a method called getDigitalAsset in the parent class.
I had some issues when doing the upgrade (I realized my nodejs wasn't upgraded as I thought it was), could that have anything to do with the issue?
Thanks
Edit:
I went through my platform upgrade again and found that there were some problems that prevented it from finishing completely.
This is what I found:
> loading Oro\Bundle\CMSBundle\Migrations\Data\ORM\LoadImageSlider
In LoadImageSlider.php line 117:
Attempted to call an undefined method named "setMainImage" of class "Oro\Bundle\CMSBundle\Entity\ImageSlide".
I commented out the loop inside the load method and re-run the upgrade. Then I got:
> loading Oro\Bundle\CMSBundle\Migrations\Data\ORM\LoadImageSlider
In QueryException.php line 65:
[Semantical Error] line 0, col 117 near 'digitalAsset': Error: Class Oro\Bundle\AttachmentBundle\Entity\File has no association named digitalAsset
In QueryException.php line 43:
SELECT file, digitalAsset, sourceFile FROM Oro\Bundle\AttachmentBundle\Entity\File file INNER JOIN file.digitalAsset digitalAsset INNER JOIN digitalAsset.sourceFile sourceFile WHERE file.parentEntityClass = :parentEntityClass
AND file.parentEntityId = :parentEntityId AND file.parentEntityFieldName =
:parentEntityFieldName
Finally I was able to complete the upgrade by commenting out the whole body of the load method
I had some issues when doing the upgrade (I realized my nodejs wasn't upgraded as I thought it was), could that have anything to do with the issue?
It looks like you have multiple versions of nodejs installed. To make an application use the right one, you can provide the absolute path to the executable with the AssetBundle configuration, like:
# config/config.yml
oro_asset:
nodejs_path: /usr/local/node
npm_path: /usr/local/npm

Using JNDI Connection pool as Datanucleus PersistenceManagerFactory

I am developing a web application using DataNucleus as DAO layer (mainly due to historical reasons). It runs inside Payara server (a Glassfish 4 fork)
It works fine, but now I'd like to use a JNDI db connection pool to obtain the PersistenceManagerFactory for DataNucleus.
From the documentation, it seems that the following code would suffice:
pmf = JDOHelper.getPersistenceManagerFactory( "jdbc/HxWmDb", context );
but this way I obtain an error starting the application (DbSession is the class which implements the DAO layer, and the error line is exactly the one above):
Caused by: java.lang.ClassCastException
at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:262)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:150)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:1791)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:1755)
at ejb.DbSession.<init>(DbSession.java:119)
...
Caused by: java.lang.ClassCastException: com.sun.gjc.spi.jdbc40.DataSource40 cannot be cast to org.omg.CORBA.Object
at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:245)
Any suggestion?
Little update, as requested by DN1:
As a first approach, I tried exactly what is described in the link:
Properties properties = new Properties();
properties.setProperty("datanucleus.ConnectionFactoryName","jdbc/HxWmDb");
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(properties);
And the error is, as already said, that a URI is anyway required:
Caused by: org.datanucleus.exceptions.NucleusException: You haven't specified persistence property 'datanucleus.ConnectionURL'

InvalidClassException and serialization issues

So i have an exercise given from my lecturer to build a registration system.
My job is to test the program. My friends gave me the source code, but i cant seem to get it running, although one of my friend can open it without any problems
Here is the error message
java.io.InvalidClassException: javax.swing.JComponent; local class incompatible: stream classdesc serialVersionUID = -3424753864000836906, local class serialVersionUID = 3742318830738515599
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:621)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1623)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1623)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1623)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at java.beans.Beans.instantiate(Beans.java:199)
at java.beans.Beans.instantiate(Beans.java:80)
at gui.MainWindow.initComponents(MainWindow.java:208)
at gui.MainWindow.<init>(MainWindow.java:34)
at srs.Driver.main(Driver.java:17)
Exception in thread "main" java.lang.IllegalArgumentException:
Component must be non-null
at javax.swing.GroupLayout$ComponentSpring.<init>(GroupLayout.java:2953)
at javax.swing.GroupLayout$ComponentSpring.<init>(GroupLayout.java:2933)
at javax.swing.GroupLayout$Group.addComponent(GroupLayout.java:1524)
at javax.swing.GroupLayout$ParallelGroup.addComponent(GroupLayout.java:2484)
at javax.swing.GroupLayout$ParallelGroup.addComponent(GroupLayout.java:2454)
at javax.swing.GroupLayout$Group.addComponent(GroupLayout.java:1505)
at javax.swing.GroupLayout$ParallelGroup.addComponent(GroupLayout.java:2476)
at gui.MainWindow.initComponents(MainWindow.java:1680)
at gui.MainWindow.<init>(MainWindow.java:34)
at srs.Driver.main(Driver.java:17)
Java Result: 1
In one of the package i have this class called "MainWindow.java", and "MainWindow_creditsField2.ser". This package is for GUI purposes.
I am assuming the error has something to do with the .ser file. When I asked my friend what that file is, he did not know what that file is, and said that it's
automatically generated
When I clicked on 3 of the last errors,
Driver tells me the line MainWindow mainWindow = new MainWindow();
MainWindow tells me line initComponents();
I think that is all the leads I can give you
The problem is with the serialization . Here is the link where it is described nicely why it occurs. Go through this thoroughly to understand how that field is used to make sure the serialized version and what the JVM wants to create from the serialized object are the same.