KEMBAR78
java.lang.UnsatisfiedLinkError is thrown when using Java API · Issue #1451 · async-profiler/async-profiler · GitHub
Skip to content

java.lang.UnsatisfiedLinkError is thrown when using Java API #1451

@FrankChen021

Description

@FrankChen021

Describe the bug

The call of AsyncProfiler.getInstance() throws such exception:

java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: var/tmp/libasyncProfiler-3235132534849877537.so

This is because the target application has set the java.io.tmpdir to a relative path, the returning of the following code returns a relative path.

File file = File.createTempFile("libasyncProfiler-", ".so",
                    extractPath == null || extractPath.isEmpty() ? null : new File(extractPath));

It's not esasy to change the property of java.io.tmpdir to an absolution path for the target application,so it's better to fix this inside the API.

The fix is simple, just get the absolution file after creating the temp file.

File file = File.createTempFile("libasyncProfiler-", ".so",
                    extractPath == null || extractPath.isEmpty() ? null : new File(extractPath));

file = filePath.getAbsoluteFile(); // <=== add this new line

Even though async-profiler allows user to set a directory for the lib via one.profiler.extractPath, if the path is set to a relative path like tmp/test, we will encounter this problem too.

Expected vs. actual behavior

No response

Reproduction Steps

No response

Additional Information/Context

No response

Async-profiler version

4.1

Environment details

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions