question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Could not allocate library name" when load native library by JNA.

See original GitHub issue

I tried to load my c library using the following code.

Native.register(com.sun.jna.NativeLibrary.getInstance("c", Collections.emptyMap()));

When Phosphor applied, a fatal error occurs. Here’s the information:

FATAL ERROR in native method: Could not allocate library name
	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	at java.lang.ClassLoader$NativeLibrary.load$$PHOSPHORTAGGED(ClassLoader.java)
	at java.lang.ClassLoader.loadLibrary0$$PHOSPHORTAGGED(ClassLoader.java:1934)
	- locked <0x00000007212e82e8> (a java.util.Vector)
	- locked <0x00000007212cffc8> (a java.util.Vector)
	at java.lang.ClassLoader.loadLibrary$$PHOSPHORTAGGED(ClassLoader.java:1838)
	at java.lang.Runtime.loadLibrary0$$PHOSPHORTAGGED(Runtime.java:871)
	- locked <0x00000007214f7000> (a java.lang.Runtime)
	at java.lang.System.loadLibrary$$PHOSPHORTAGGED(System.java:1122)
	at java.awt.Toolkit$3.run$$PHOSPHORTAGGED(Toolkit.java:1636)
	at java.awt.Toolkit$3.run$$PHOSPHORTAGGED(Toolkit.java:1634)
	at java.awt.Toolkit$3.run(Toolkit.java:0)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessController.doPrivileged$$PHOSPHORTAGGED(AccessController.java)
	at java.awt.Toolkit.loadLibraries(Toolkit.java:1633)
	at java.awt.Toolkit.<clinit>(Toolkit.java:1670)
	at java.awt.Component.<clinit>(Component.java:593)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName0$$PHOSPHORTAGGED(Class.java)
	at java.lang.Class.forName$$PHOSPHORTAGGED(Class.java:264)
	at java.lang.Class.forName(Class.java:0)
	at edu.columbia.cs.psl.phosphor.Instrumenter.isCollection(Instrumenter.java:67)
	at edu.columbia.cs.psl.phosphor.instrumenter.TaintTrackingClassVisitor.visitEnd(TaintTrackingClassVisitor.java:1066)
	at edu.columbia.cs.psl.phosphor.org.objectweb.asm.ClassVisitor.visitEnd(ClassVisitor.java:326)
	at edu.columbia.cs.psl.phosphor.org.objectweb.asm.commons.OurSerialVersionUIDAdder.visitEnd(OurSerialVersionUIDAdder.java:330)
	at edu.columbia.cs.psl.phosphor.org.objectweb.asm.ClassVisitor.visitEnd(ClassVisitor.java:326)
	at edu.columbia.cs.psl.phosphor.org.objectweb.asm.ClassReader.accept(ClassReader.java:692)
	at edu.columbia.cs.psl.phosphor.org.objectweb.asm.ClassReader.accept(ClassReader.java:400)
	at edu.columbia.cs.psl.phosphor.PreMain$PCLoggingTransformer.instrumentWithRetry(PreMain.java:269)
	at edu.columbia.cs.psl.phosphor.PreMain$PCLoggingTransformer.transform(PreMain.java:174)
	at edu.columbia.cs.psl.phosphor.PhosphorBaseTransformer.signalAndTransform(PhosphorBaseTransformer.java:62)
	at edu.columbia.cs.psl.phosphor.PhosphorBaseTransformer.transform$$PHOSPHORTAGGED(PhosphorBaseTransformer.java:31)
	at sun.instrument.TransformerManager.transform$$PHOSPHORTAGGED(TransformerManager.java:188)
	at sun.instrument.InstrumentationImpl.transform$$PHOSPHORTAGGED(InstrumentationImpl.java:428)
	at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:0)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass1$$PHOSPHORTAGGED(ClassLoader.java)
	at java.lang.ClassLoader.defineClass$$PHOSPHORTAGGED(ClassLoader.java:756)
	at java.security.SecureClassLoader.defineClass$$PHOSPHORTAGGED(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass$$PHOSPHORTAGGED(URLClassLoader.java:468)
	at java.net.URLClassLoader.access$100$$PHOSPHORTAGGED(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run$$PHOSPHORTAGGED(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run$$PHOSPHORTAGGED(URLClassLoader.java:363)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:0)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessController.doPrivileged$$PHOSPHORTAGGED(AccessController.java)
	at java.net.URLClassLoader.findClass$$PHOSPHORTAGGED(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass$$PHOSPHORTAGGED(ClassLoader.java:418)
	- locked <0x0000000721230610> (a java.lang.Object)
	at sun.misc.Launcher$AppClassLoader.loadClass$$PHOSPHORTAGGED(Launcher.java:355)
	at java.lang.ClassLoader.loadClass$$PHOSPHORTAGGED(ClassLoader.java:351)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:0)
	at com.sun.jna.NativeLibrary.<clinit>(NativeLibrary.java:84)
	at jna.Main.main$$PHOSPHORTAGGED(Main.java:6)
	at jna.Main.main(Main.java)

My JNA version is 4.2.2. The pom info is as follows

<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>4.2.2</version>
</dependency>

Could you help figure out what happens?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jon-bellcommented, Mar 16, 2021

Ok - in testing on a Ubuntu VM, 2e57a6f seems to resolve the issue and now the example runs. Does this revision fix things on your end?

0reactions
Icysandwichcommented, Mar 17, 2021

Problem fixed! Thanks a lot! Sorry for bothering you again, but I find a new issue. See 165 PLZ.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jna.loadLibrary cannot find native library file - Stack Overflow
The preferred method is to set the jna.library.path system property to the path to your target library. This property is similar to java.library...
Read more >
Using JNA to Access Native Dynamic Libraries - Baeldung
In this tutorial, we'll see how to use the Java Native Access library (JNA for short) to access native libraries without writing any...
Read more >
Developing using native libraries - ImageJ Wiki
Specifying library search paths​​ If you want to use a library that is not installed in one of the locations your platform looks...
Read more >
NativeLibrary (JNA API)
The allocated instance represents a pointer to the named native function from the library. Parameters: name - Name of the native function to...
Read more >
jna/NativeLibrary.java at master · java-native-access/jna · GitHub
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found