Skip to content

NativeLibraryLoader uses some hardcoded hacks #1968

Closed
@Ali-RS

Description

@Ali-RS

While dealing with NativeLibraryLoader in another issue I notices NativeLibraryLoader uses some hardcoded hacks that need to be fixed.

for example, in the below code, when it can not find the file inside the jar instead of immediately failing it tries to load it as a system library using System.loadLibrary(libName); which shouldn't in my opinion.

if (url == null) {
// Attempt to load it as a system library.
String unmappedName = unmapLibraryName(fileNameInJar);
try {
// XXX: HACK. Vary loading method based on library name.
// lwjgl and jinput handle loading by themselves.
if (!name.equals("lwjgl") && !name.equals("jinput")) {
// Need to unmap it from library specific parts.
System.loadLibrary(unmappedName);
logger.log(Level.FINE, "Loaded system installed "
+ "version of native library: {0}", unmappedName);
}
} catch (UnsatisfiedLinkError e) {
if (isRequired) {
throw new UnsatisfiedLinkError(
"The required native library '" + unmappedName + "'"
+ " was not found in the classpath via '" + pathInJar
+ "'. Error message: " + e.getMessage());
} else if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "The optional native library ''{0}''" +
" was not found in the classpath via ''{1}''" +
". Error message: {2}",
new Object[]{unmappedName, pathInJar, e.getMessage()});
}
}
return;
}

or here, for lwjgl and jinput, it does not load them actually just extracts them and sets the path in a system property to be loaded later on by the library itself.

// XXX: HACK. Vary loading method based on library name.
// lwjgl and jinput handle loading by themselves.
if (name.equals("lwjgl") || name.equals("lwjgl3")) {
System.setProperty("org.lwjgl.librarypath",
extractionDirectory.getAbsolutePath());
} else if (name.equals("jinput")) {
System.setProperty("net.java.games.input.librarypath",
extractionDirectory.getAbsolutePath());
} else {
// all other libraries (openal, bulletjme, custom)
// will load directly in here.
System.load(targetFile.getAbsolutePath());
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions