[CONJ-1123] java.lang.ClassNotFoundException: javax.crypto.Cipher cannot be found by mariadb-java-client_3.0.11 Created: 2023-11-16  Updated: 2023-11-20  Resolved: 2023-11-20

Status: Closed
Project: MariaDB Connector/J
Component/s: MySQL compatibility
Affects Version/s: 3.0.11
Fix Version/s: 3.3.1

Type: Bug Priority: Blocker
Reporter: Adan Espinoza Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

The issue happens on Windows 10, or Linux Ubuntu. The application runs on top of OSGi 3.11. The connection string contains the parameter. allowPublicKeyRetrieval=true



 Description   

The problem happens when the application tries to connect to MySQL 8.0

17:08:37.068 E [FrontRunnerStarter] exceptions->y:2942 - Uncaught exception in Thread<Thread[FrontRunnerStarter,10,main]>
java.lang.NoClassDefFoundError: javax/crypto/Cipher
	at org.mariadb.jdbc.plugin.authentication.standard.CachingSha2PasswordPlugin.encrypt(CachingSha2PasswordPlugin.java:248)
	at org.mariadb.jdbc.plugin.authentication.standard.CachingSha2PasswordPlugin.process(CachingSha2PasswordPlugin.java:165)
	at org.mariadb.jdbc.client.impl.ConnectionHelper.authenticationHandler(ConnectionHelper.java:301)
	at org.mariadb.jdbc.client.impl.StandardClient.<init>(StandardClient.java:189)
	at org.mariadb.jdbc.Driver.connect(Driver.java:70)
	at org.mariadb.jdbc.Driver.connect(Driver.java:101)
	at org.mariadb.jdbc.Driver.connect(Driver.java:27)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:208)
...
Caused by: java.lang.ClassNotFoundException: javax.crypto.Cipher cannot be found by mariadb-java-client_3.0.11



 Comments   
Comment by Adan Espinoza [ 2023-11-16 ]

I confirmed that adding javax.crypto;resolution:=optional to the Import-Packages in the POM file fixes the issue.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.2.0</version>
    <configuration>
        <archive>
            <manifestEntries>
                <Multi-Release>true</Multi-Release>
                <Export-Package>org.mariadb.jdbc</Export-Package>
                <Import-Package>
                   javax.crypto;resolution:=optional, <!-- .... This would fix the issue -->  
                </Import-Package>
            </manifestEntries>
            <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
        </archive>
    </configuration>
</plugin>

Comment by Adan Espinoza [ 2023-11-16 ]

Consider also adding the missing reference into bnd.bnd file

Import-Package: \
    javax.naming,\
    javax.naming.ldap,\
    javax.management,\
    javax.sql,\
    #This would be also part of the fix
    javax.crypto;resolution:=optional,\ 

Comment by Adan Espinoza [ 2023-11-16 ]

@diego dupin
I did cherry pick commit 4ad1941 from release tag 3.0.11, built the library on my end. And I confirm the fix works.
Now I have the following questions.

  1. Is there an ETA of when a new release is going to be available?
  2. Is it possible to have a new hotfix release for 3.0?

BTW Thanks for your support

Generated at Thu Feb 08 03:20:47 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.