Liferay 7.4.3-ga123 - Java 21 in a JSF-Portlet

Hello,

I am trying to use Java 21 in a JSF-Portlet in Liferay Portal 7.4.3 ga 132. I am basing my development on this project, which uses PrimeFaces 11: liferay-faces-bridge-impl/demo/primefaces-applicant-portlet at 6.0.0 · liferay/liferay-faces-bridge-impl · GitHub

I am getting this exception during the thin-Wab deployment because the Version 7.1 of ASM which is included with org.apache.aries.spifly.dynamic.framework.extension does not support Java 21.

FrameworkEvent ERROR
java.lang.IllegalArgumentException: Unsupported class file major version 65
at org.objectweb.asm.ClassReader.(ClassReader.java:195) ~[bundleFile:1.2.3]
at org.objectweb.asm.ClassReader.(ClassReader.java:176) ~[bundleFile:1.2.3]
at org.objectweb.asm.ClassReader.(ClassReader.java:162) ~[bundleFile:1.2.3]
at org.objectweb.asm.ClassReader.(ClassReader.java:283) ~[bundleFile:1.2.3]
at org.apache.aries.spifly.dynamic.OSGiFriendlyClassWriter._getSuperClassName(OSGiFriendlyClassWriter.java:116)

I tried to substitute osgi/static/org.apache.aries.spifly.dynamic.framework.extension.jar, which is the version 1.2.3-LIFERAY-PATCHED-3 with the version 1.2.3-LIFERAY-PATCHED-4. But with this change, Liferay does not even start. Here is an excerpt of the causes:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.liferay.asset.kernel.service.persistence.AssetTagPersistence' defined in class path resource [META-INF/portal-spring.xml]: Invocation of init method failed; ...

Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(org.eclipse.osgi.internal.framework.BundleContextImpl, String[], Object, java.util.Dictionary)" because the return value of "org.eclipse.osgi.internal.framework.EquinoxContainer.getServiceRegistry()" is null

Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.notifyHooksPrivileged(org.eclipse.osgi.internal.serviceregistry.HookContext)" because the return value of "org.eclipse.osgi.internal.framework.EquinoxContainer.getServiceRegistry()" is null

	at org.eclipse.osgi.internal.framework.BundleContextImpl.notifyFindHooksPriviledged(BundleContextImpl.java:216) ~[org.eclipse.osgi.jar:?]

Is there a way to use Java 21 in a JSF Portlet

Here is someone which is also having problems with a JSF Portlet: jdk 21 - liferay 7.4 and new faces

1 Answer

1

This means you have compiled code using JDK 21, but you’re not using a JDK 21 runtime, you’re using something older.

Liferay requires JDK 21 for 7.4 ga 132+, so you will need to update all your dependencies (including ASM) to use JDK 21.

This is not optional, you won’t be able to use an older JDK.

[1/2] Thanks for your response, Dave! Unfortunately this is not the case. I am compiling my project with Java 21 and the Runtime is Java 21 as well. I am giving up and going with the thick WAR approach now, although this forces me to restart Liferay after every deployment. During my analysis, I was able to tell which class was responsible for the Exception. So, by modifying the Exception handling in OSGiFriendlyClassWriter, I could get: Exception finding Superclass:org/w3c/dom/Document java/util/concurrent/FutureTask This confirms my suspicions. FutureTask is Java 21 (continue...)

[2/2] This confirms my suspicions. FutureTask is Java 21 (0xCA 0xFE 0xBA 0xBE 0x00 0x00 0x00 0x41), and ASM 7.1 cannot read this class. I cannot upgrade ASM. I tried, and actually substituted it in SPI Fly, There were other errors instead of that exception) Liferay 7.4.3-ga132 ships with org.apache.aries.spifly.dynamic.framework.extension 1.2.3.LIFERAY-PATCHED-3 org.apache.aries.spifly.dynamic.framework.extension 1.2.3.LIFERAY-PATCHED-3 embeds ASM 7.1 As soon as there are files in WEB-INF/classes/META-INF/services in my module, the IllegalArgumentException happens.