Bug #102372 v8.0.23 unusable in OSGi
Submitted: 26 Jan 2021 3:59 Modified: 20 Jul 2021 19:55
Reporter: Rakesh Kumar Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:8.0.23 OS:Any
Assigned to: CPU Architecture:Any

[26 Jan 2021 3:59] Rakesh Kumar
Description:
v8.0.23 unusable in OSGi because of non import of javax.security.auth.login package, this was not referenced in v8.0.22 and introduced in v8.0.23 only.

This causes a java.lang.ClassNotFoundException

Here is the stacktrace.

Caused by: org.apache.felix.log.LogException: java.lang.NoClassDefFoundError: javax/security/auth/login/LoginException
	at com.mysql.cj.protocol.a.NativeAuthenticationProvider.loadAuthenticationPlugins(NativeAuthenticationProvider.java:246)
	at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:387)
	at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:174)
	at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1350)
	at com.mysql.cj.NativeSession.connect(NativeSession.java:157)
	at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:953)
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:823)
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
	at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
	at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364)
	at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
	at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476)
	at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
	at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
	at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
	at com.adeptj.modules.commons.jdbc.service.internal.DataSources.createHikariDataSource(DataSources.java:60)
	at com.adeptj.modules.commons.jdbc.service.internal.HikariDataSourceService.<init>(HikariDataSourceService.java:66)
	... 51 common frames omitted

Caused by: java.lang.ClassNotFoundException: javax.security.auth.login.LoginException not found by com.mysql.cj [11]
	at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1585)
	at org.apache.felix.framework.BundleWiringImpl.access$300(BundleWiringImpl.java:79)
	at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1970)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 70 common frames omitted

How to repeat:
Depoly the v8.0.23 to an OSGi runtime and try to get the connection in an OSGi service, this will fail with a ClassNotFoundException

Suggested fix:
Put javax.security.auth.login package in OSGi metadata using the Import-Package instruction.
[26 Jan 2021 4:06] Rakesh Kumar
This is a critical issue which will affect all the usage in OSGi environments.
[26 Jan 2021 4:09] Rakesh Kumar
ConnectorJ Bundle description in OSGi

Attachment: ConnectorJ_Bundle_OSGi.docx (application/vnd.openxmlformats-officedocument.wordprocessingml.document, text), 701.42 KiB.

[2 Feb 2021 11:43] MySQL Verification Team
Hi Rakesh,

When I use "plain java" this works ok. Can you attach a minimal OSGi app example that fails?

Thanks
Bogdan
[2 Feb 2021 12:28] Rakesh Kumar
Hi Bogdan,

This issue only surfaces in OSGi environment because of the missing import package.

Let me try to provide you with a sample OSGi application. This will be an uber jar(runnable), hope you have Java 11 or newer setup at your machine.

Thanks,
Rakesh
[2 Feb 2021 12:42] MySQL Verification Team
Hi Rakesh,

I have Java14 on this test box but I can put any other if needed. I would need both source and jar if possible. The "minimal app".

thanks
Bogdan
[2 Feb 2021 13:06] Rakesh Kumar
Hi Bogdan,

Java 14 will work.

This is an open source project I maintain and here is how the JDBC connection pool is created using HikariCP - https://github.com/AdeptJ/adeptj-modules/blob/master/commons/jdbc/src/main/java/com/adeptj...

If you look at the stack trace I provided.

Caused by: org.apache.felix.log.LogException: java.lang.NoClassDefFoundError: javax/security/auth/login/LoginException
	at com.mysql.cj.protocol.a.NativeAuthenticationProvider.loadAuthenticationPlugins(NativeAuthenticationProvider.java:246)
	at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:387)
	at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:174)
	at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1350)
	at com.mysql.cj.NativeSession.connect(NativeSession.java:157)
	at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:953)
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:823)
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
	at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
	at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364)
	at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
	at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476)
	at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
	at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
	at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
	at com.adeptj.modules.commons.jdbc.service.internal.DataSources.createHikariDataSource(DataSources.java:60)

The AuthenticationLdapSaslClientPlugin fails because it has the usage of following classes from javax.security.auth.login package.

import javax.security.auth.login.AppConfigurationEntry;
import javax.security.auth.login.Configuration;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;

javax.security.auth.login is not imported by connector/J bundle that's why the exception.

v8.0.22 does not have this package reference and that's why it works without any issues.

Hope this will give more clarity.

Thanks,
Rakesh
[2 Feb 2021 13:18] Rakesh Kumar
Hi Bogdan,

In connector/J githib repo, the import package instruction has to be updated with the javax.security.auth.login package.

Seems the repo is using ANT build tool, which I have very limited experience but here is the line I think requires updation.

https://github.com/mysql/mysql-connector-j/blob/18bbd5e68195d0da083cbd5bd0d05d76320df7cd/b...

and this line is importing the javax security packages.

https://github.com/mysql/mysql-connector-j/blob/18bbd5e68195d0da083cbd5bd0d05d76320df7cd/b...

if you could add the import and build locally and provide the resultant jar to me then I can deploy and let you know. 

Meanwhile I'll create a sample app and provide that to you.

Thanks,
Rakesh
[3 Feb 2021 5:03] Rakesh Kumar
Hi Bogdan,

I have uploaded the application zip on Oracle SFTP, please get it from here - /support/incoming/mysql-bug-102372-adeptj-runtime.zip

Please make sure there is a local mysql running on default port 3306.

After extracting the contents please follow the steps given below.

1. in the terminal cd to extracted folder
2. run the server using this command - ./bin/start.sh
3. observer the logs, you would see the exceptions related to connector/J bundle.

Thanks,
Rakesh
[3 Feb 2021 9:33] MySQL Verification Team
Thanks for the report

all best
Bogdan
[21 Apr 2021 17:00] Kevin Schmidt
This is marked as an S1(Critical) and was found in 8.0.23, and 8.0.24 has been released but still has this issue.  Is a fix for this being worked on?  Will it be in 8.0.25?
[21 Apr 2021 23:35] MySQL Verification Team
Hi,

Bug will be updated when the fix is created, tested and put into release.

thanks
[26 May 2021 11:03] Domagoj Cosic
The bug still persists in versions 8.0.24 and 8.0.25.
[29 May 2021 17:52] Daniel So
Posted by developer:
 
Corrected the changelog entry to the following: 

"Connector/J of release 8.0.23 and later could not be used in OSGi. It was because the manifest file was missing a few imports needed for OSGi, and this patch fixed the issue."
[20 Jul 2021 15:34] Rakesh Kumar
I just tested with v8.0.26 and it is working fine now.
[20 Jul 2021 19:55] MySQL Verification Team
Thanks for the confirmation

kind regards