On Sep 14, 2007, at 7:58 AM, Timothy Wall wrote:
public static class SecKeychainAttribute extends Structure {
public int tag;
public int length;
public String data;
}
public static class SecKeychainAttributeList extends Structure {
public int count;
public SecKeychainAttribute[] attr;
}
Then I defined a native Library with the following method:
int SecKeychainItemModifyAttributesAndData(
Pointer itemRef,
SecKeychainAttributeList attrList,
int length,
String pw);
When I try to call that method, I get the following
NullPointerException (this is using the latest source in the svn
trunk):
java.lang.NullPointerException
at com.sun.jna.Structure.getNativeSize(Structure.java:712)
The relevant bits start in Structure.getNativeAlignment, line 668:
667 else if (type.isArray()) {
668 alignment = getNativeAlignment(type.getComponentType
(), null, firstElement);
669 }
Note that null is passed as the value. Then getNativeAlignment
line 651:
651 int size = getNativeSize(type, value);
So that is passing null as the value to getNativeSize. Finally,
in Structure.getNativeSize, like 712:
708 protected int getNativeSize(Class type, Object value) {
709 if (Structure.class.isAssignableFrom(type)) {
710 Structure s = (Structure)value;
711 // inline structure
712 return s.size(); //There's the NPE
713 }
This should instead report that the array member of the structure
has not yet been initialized. Normally when this is encountered,
the size calculation is deferred, which allows structures to
initialize their fields inline without requiring a dedicated
constructor.
So I apparently I was using the wrong syntax in Java. The native
struct is defined like this:
struct SecKeychainAttributeList
{
UInt32 count;
SecKeychainAttribute *attr;
};
What I need on the native side is an array of pointers to
SecKeychainAttributes. So once the Pointer[] is working, that should
do the trick, right?
Thanks,
Rob