MCPcopy Create free account
hub / github.com/java-native-access/jna / loadLibraryInstance

Method loadLibraryInstance

src/com/sun/jna/Native.java:751–771  ·  view source on GitHub ↗

Attempts to force initialization of an instance of the library interface by loading a public static field of the requisite type. Returns whether an instance variable was instantiated. Expects that lock on libraries is already held

(Class<?> cls)

Source from the content-addressed store, hash-verified

749 * Expects that lock on libraries is already held
750 */
751 private static void loadLibraryInstance(Class<?> cls) {
752 if (cls != null && !libraries.containsKey(cls)) {
753 try {
754 Field[] fields = cls.getFields();
755 for (int i=0;i < fields.length;i++) {
756 Field field = fields[i];
757 if (field.getType() == cls
758 && Modifier.isStatic(field.getModifiers())) {
759 // Ensure the field gets initialized by reading it
760 field.setAccessible(true); // interface might be private
761 libraries.put(cls, new WeakReference<>(field.get(null)));
762 break;
763 }
764 }
765 }
766 catch (Exception e) {
767 throw new IllegalArgumentException("Could not access instance of "
768 + cls + " (" + e + ")");
769 }
770 }
771 }
772
773 /**
774 * Find the library interface corresponding to the given class. Checks

Callers 1

getLibraryOptionsMethod · 0.95

Calls 6

isStaticMethod · 0.80
getModifiersMethod · 0.80
putMethod · 0.80
getFieldsMethod · 0.45
getTypeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected