Fix CLI Snowflake JDBC driver error by adding JVM module access#92
Merged
Fix CLI Snowflake JDBC driver error by adding JVM module access#92
Conversation
… module access ## Problem The Snowflake JDBC driver was failing to initialize when used in the CLI tool with the following error: java.lang.reflect.InaccessibleObjectException: Unable to make field long java.nio.Buffer.address accessible: module java.base does not "opens java.nio" to unnamed module This occurred because the Snowflake JDBC driver uses Apache Arrow for high-performance memory management, which requires reflective access to internal `java.nio.Buffer` classes. Java's module system (introduced in Java 9+) blocks this access by default for security reasons. ## Solution Added `--add-opens=java.base/java.nio=ALL-UNNAMED` to the `applicationDefaultJvmArgs` in `ndc-cli/build.gradle.kts`. This JVM argument opens the `java.nio` package from the `java.base` module to unnamed modules, allowing the Snowflake driver's Arrow library to access the necessary internal classes. ## Impact - Fixes native query creation and other CLI operations that use the Snowflake JDBC driver - Safe for all database connectors (Oracle, MySQL, Trino) - this flag only affects libraries that actually need the access - Standard practice for JDBC applications with modern drivers that use direct memory access ## Testing Verified that the CLI can now successfully connect to Snowflake and create native queries without the `InaccessibleObjectException`. This gives a clear explanation of the problem, the technical reason behind it, and why the solution is appropriate and safe.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Snowflake JDBC driver was failing to initialize when used in the CLI tool with the following error:
java.lang.reflect.InaccessibleObjectException: Unable to make field long java.nio.Buffer.address accessible: module java.base does not "opens java.nio" to unnamed module
This occurred because the Snowflake JDBC driver uses Apache Arrow for high-performance memory management, which requires reflective access to internal
java.nio.Bufferclasses. Java's module system (introduced in Java 9+) blocks this access by default for security reasons.Solution
Added
--add-opens=java.base/java.nio=ALL-UNNAMEDto theapplicationDefaultJvmArgsinndc-cli/build.gradle.kts. This JVM argumentopens the
java.niopackage from thejava.basemodule to unnamed modules, allowing the Snowflake driver's Arrow library to access the necessary internal classes.Impact
Testing
Verified that the CLI can now successfully connect to Snowflake and create native queries without the
InaccessibleObjectException.This gives a clear explanation of the problem, the technical reason behind it, and why the solution is appropriate and safe.