oracle / ojdbc-extensions

The Oracle JDBC Driver Extensions include providers for centralized configuration or token providers for authentication with the DB.
Universal Permissive License v1.0
13 stars 5 forks source link

Set Release to JDK 8 #46

Closed Michael-A-McMahon closed 11 months ago

Michael-A-McMahon commented 11 months ago

This branch sets the maven.compiler.release setting to 8. This avoids sneaky runtime failures that can happen when a new JDK version is compiling our code. For instance, calls to CharBuffer.clear() break if compiled by a JDK newer than 8, and then run on JDK 8. This is because the return type of the clear() method changed after JDK 8, and our users will hit:

java.lang.NoSuchMethodError: java.nio.CharBuffer.clear()Ljava/nio/CharBuffer;
    at oracle.jdbc.provider.oci.vault.Secret.toCharArray(Secret.java:99)

Setting the release option ensures that byte code is consistent with the API of the specified JDK 8. With this CharBuffer example, it ensures that byte code calls a method with a Buffer return type, rather than CharBuffer. The release option is documented here: https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-release.html

Michael-A-McMahon commented 11 months ago

The limitation of this release option is that we must compile with a JDK version newer than 8.

We see this first CI run failing due to using JDK 8. I'll see if I can update that.

Michael-A-McMahon commented 11 months ago

Lifting the limitation I mentioned in my last comment, I've added a profile which actives only if the JDK is 9 or newer. This profile will set the release option if the JDK supports it. Otherwise, we are just compiling with JDK 8 so there's no need to set it.

The profile is similar to the one suggested here: https://issues.apache.org/jira/browse/MCOMPILER-339