Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use logger instead of System.out/System.err in JLineNativeLoader #907

Closed
tincore opened this issue Nov 24, 2023 · 2 comments
Closed

Use logger instead of System.out/System.err in JLineNativeLoader #907

tincore opened this issue Nov 24, 2023 · 2 comments
Milestone

Comments

@tincore
Copy link

tincore commented Nov 24, 2023

jline 3.24.1

Motivation from this request: I'm experiencing cases where jline new native libraries are forbidden to be loaded because of corporate security software installed on user machines. Basically, that software prevents execution of dll files on tmp directory (in Windows user/Temp).

As part of the terminal available provider detection process JLineNativeLoader.loadNativeLibrary() can be called one or multiple times. For each failed call messages are displayed in System.err/System.out. It seems like there is no way (except upfront disabling exec and jni provider) to prevent this messages polluting application startup.

By using logger instead of System.out/System.err we would have the possibility to, optionally, hide those non critical errors from console.

@gnodet
Copy link
Member

gnodet commented Nov 24, 2023

Sure, can you point to the message displayed to sysout/syserr ? Or maybe raise a PR ?
That said, there's also a way to extract the library to a given directory and point to that one instead of letting the loader extract the binary DLL from inside the jar and loading it.

@tincore
Copy link
Author

tincore commented Nov 24, 2023

Thanks for the response.

This particular error comes from UnsatisfiedLinkError

I think that something like the following snippet should be fine. Could be that Warning is more adequate than Severe though.

    /**
     * Loads native library using the given path and name of the library.
     *
     * @param libPath Path of the native library.
     * @return True for successfully loading; false otherwise.
     */
    private static boolean loadNativeLibrary(File libPath) {
        if (libPath.exists()) {

            try {
                String path = libPath.getAbsolutePath();
                System.load(path);
                nativeLibraryPath = path;
                return true;
            } catch (UnsatisfiedLinkError e) {
                logger.log(Level.SEVERE, "Failed to load native library:%s. osinfo: %s".formatted(libPath.getName(), OSInfo.getNativeLibFolderPathForCurrentOS()), e);
                return false;
            }

        } else {
            return false;
        }
    }

I've already implemented an equivalent temporary hack on my side as I don't have jline as direct dependency.

gnodet added a commit to gnodet/jline3 that referenced this issue Dec 21, 2023
@gnodet gnodet added this to the 3.25.0 milestone Dec 21, 2023
gnodet added a commit to gnodet/jline3 that referenced this issue Dec 21, 2023
@gnodet gnodet closed this as completed in b2749c4 Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants