xerial / sqlite-jdbc

SQLite JDBC Driver
Apache License 2.0
2.86k stars 619 forks source link

aarch64 native library is tried to be loaded when using a 32-bit JVM #1127

Closed tyilo closed 5 months ago

tyilo commented 5 months ago

Describe the bug When running inside a 32-bit JVM on a aarch64 processor, sqlite-jdbc tries to load the aarch64 native library. This of course fails.

To Reproduce

package org.example;

import java.sql.DriverManager;

public class Main {
  public static void main(String[] args) throws Exception {
    System.out.println("Arch: " + System.getProperty("sun.arch.data.model"));

    try (var connection = DriverManager.getConnection("jdbc:sqlite:/tmp/test.db");
      var statement = connection.createStatement();
      var result = statement.executeQuery("SELECT RANDOM();")) {
      while (result.next()) {
        System.out.println("Output: " + result.getLong(1));
      }
    }
  }
}

Expected behavior As the code is running inside a 32-bit JVM, the arm, armv6 or armv7 native library should be loaded.

Logs Output:

Arch: 32
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
OpenJDK Client VM warning: You have loaded library /tmp/sqlite-3.46.0.0-51c6d6c2-c417-498d-9da6-fb79c3df716a-libsqlitejdbc.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
Exception in thread "main" java.sql.SQLException: Error opening connection
    at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:283)
    at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:67)
    at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:28)
    at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:19)
    at org.sqlite.JDBC.createConnection(JDBC.java:106)
    at org.sqlite.JDBC.connect(JDBC.java:79)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:681)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:252)
    at org.example.Main.main(Main.java:9)
Caused by: org.sqlite.NativeLibraryNotFoundException: No native library found for os.name=Linux, os.arch=aarch64, paths=[/org/sqlite/native/Linux/aarch64:/usr/java/packages/lib:/usr/lib/arm-linux-gnueabihf/jni:/lib/arm-linux-gnueabihf:/usr/lib/arm-linux-gnueabihf:/usr/lib/jni:/lib:/usr/lib]
    at org.sqlite.SQLiteJDBCLoader.loadSQLiteNativeLibrary(SQLiteJDBCLoader.java:361)
    at org.sqlite.SQLiteJDBCLoader.initialize(SQLiteJDBCLoader.java:75)
    at org.sqlite.core.NativeDB.load(NativeDB.java:69)
    at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:280)
    ... 8 more

Environment (please complete the following information):

Additional context

gotson commented 5 months ago

Probably because your Raspberry used to be 32bit and was incorrectly migrated to 64bit. Pretty sure there's existing issues about that.

You can force the detection: https://github.com/xerial/sqlite-jdbc/blob/master/USAGE.md#override-detected-architecture

tyilo commented 5 months ago

Sure I can try that to fix my issue, but this is still a bug in sqlite-jdbc.

A 64-bit native library should never be tried to be loaded into a 32-bit JVM.

gotson commented 5 months ago

It's more of a problem in the Raspberry OS that gets in a weird state it shouldn't be in.

Anyhow, if you think you can fix this behaviour, feel free to send a PR.

github-actions[bot] commented 4 months ago

🎉 This issue has been resolved in 3.46.0.1 (Release Notes)