Skip to content

Commit a80b37c

Browse files
fix: automatically load library when using loaderLookup
1 parent 6928e75 commit a80b37c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/main/java/io/github/treesitter/jtreesitter/internal/ChainedLibraryLookup.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ private static SymbolLookup findLibrary(Arena arena) {
2828
try {
2929
var library = System.mapLibraryName("tree-sitter");
3030
return SymbolLookup.libraryLookup(library, arena);
31-
} catch (IllegalArgumentException e) {
32-
return SymbolLookup.loaderLookup();
31+
} catch (IllegalArgumentException ex1) {
32+
try {
33+
System.loadLibrary("tree-sitter");
34+
return SymbolLookup.loaderLookup();
35+
} catch (UnsatisfiedLinkError ex2) {
36+
ex1.addSuppressed(ex2);
37+
throw ex1;
38+
}
3339
}
3440
}
3541
}

src/main/java/io/github/treesitter/jtreesitter/package-info.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@
4343
* SymbolLookup.libraryLookup(String, Arena)}.
4444
* </li>
4545
* <li>
46-
* The libraries can be loaded manually by calling
47-
* {@link java.lang.System#loadLibrary(String) System.loadLibrary(String)},
48-
* if the library is installed in {@systemProperty java.library.path},
49-
* or {@link java.lang.System#load(String) System.load(String)}.
46+
* If the libraries are installed in {@systemProperty java.library.path} instead,
47+
* they will be loaded automatically by {@link java.lang.foreign.SymbolLookup#loaderLookup()
48+
* SymbolLookup.loaderLookup()}.
5049
* </li>
5150
* <li>
5251
* The libraries can be loaded manually by registering a custom implementation of

0 commit comments

Comments
 (0)