[CONJ-1120] MariaDB Connector/J 3.3.0 compatibility with java8 Created: 2023-11-11  Updated: 2023-11-23  Resolved: 2023-11-21

Status: Closed
Project: MariaDB Connector/J
Component/s: java8
Affects Version/s: 3.3.0
Fix Version/s: 3.3.1

Type: Bug Priority: Blocker
Reporter: Andreas Dangel Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None


 Description   

https://mariadb.com/kb/en/about-mariadb-connector-j/ says, that minimum Java is Java8.

When using MariaDB Connector/J with Java8, the following exception is thrown:

Caused by: java.lang.NoSuchMethodError: java.lang.String.repeat(I)Ljava/lang/String;
    at org.mariadb.jdbc.DatabaseMetaData.parseIdentifier (DatabaseMetaData.java:86)
    at org.mariadb.jdbc.DatabaseMetaData.getImportedKeys (DatabaseMetaData.java:235)
    at org.mariadb.jdbc.DatabaseMetaData.getImportedKeysUsingShowCreateTable (DatabaseMetaData.java:1104)
    at org.mariadb.jdbc.DatabaseMetaData.getImportedKeys (DatabaseMetaData.java:458)

The reason is, that String.repeat is only available in Java11+, but not in Java8. It is used here:
https://github.com/mariadb-corporation/mariadb-connector-j/blob/13cee5a93a441a9326810de39bc30eef4c33c6e1/src/main/java/org/mariadb/jdbc/DatabaseMetaData.java#L86

One way to avoid such incompatibilities is, to use the "release" flag in maven-compiler-plugin instead of source/target. However, that requires to use e.g. a Java11 JDK for building - but thanks to the release flag, the compiled code is still java8 compatible (both binary compatible and API level compatible). But that seems to be ok, since you already use Java17 for building (according to travis.yml).

Problem seems to have been introduced with https://github.com/mariadb-corporation/mariadb-connector-j/commit/2acd4376742bcb17322cfb5d98b159c6bd6502d9#diff-6d3a1153c463711756ad718e88ae89c3f12458576e928305ae428ea10bd72b2a (CONJ-1112)



 Comments   
Comment by Diego Dupin [ 2023-11-13 ]

that's right, there will be a correction soon, and CI will be modified to avoid this kind of error in the future.
Since the driver uses Multi-Version JARs (MRJAR), to contain implementations for different versions of Java simultaneously. This permit still supports Java 8, but provides solutions for higher versions of Java to, such as the extended Java 11 socket option TCP_KEEPIDLE, TCP_KEEPCOUNT and TCP_KEEPINTERVAL for example. Problem is that java 8

btw, there is another place where java 8+ code is used : Statement.enquoteLiteral but that's less a problem since this method is JDBC 4.3 (java 9) new features, but to be correted at the same time.

Comment by Diego Dupin [ 2023-11-21 ]

CI now test java 8 to ensure not having those kind of issue.
Correction is available using snapshot for now:

<repositories>
		<repository>
				<id>sonatype-nexus-snapshots</id>
				<name>Sonatype Nexus Snapshots</name>
				<url>https://oss.sonatype.org/content/repositories/snapshots</url>
		</repository>
</repositories>
 
<dependencies>
		<dependency>
				<groupId>org.mariadb.jdbc</groupId>
				<artifactId>mariadb-java-client</artifactId>
				<version>3.3.1-SNAPSHOT</version>
		</dependency>
</dependencies>

Comment by Andreas Dangel [ 2023-11-23 ]

Thanks for fixing! I can confirm, in 3.3.1-SNAPSHOT, this issue is solved.

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