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

null handling for opaque (byte[]) data #18

Open
radai-rosenblatt opened this issue Jul 21, 2015 · 4 comments
Open

null handling for opaque (byte[]) data #18

radai-rosenblatt opened this issue Jul 21, 2015 · 4 comments
Labels

Comments

@radai-rosenblatt
Copy link
Contributor

if you leave an opaque value null, you get something like this:

java.lang.NullPointerException
    at org.dcache.xdr.Xdr.xdrEncodeDynamicOpaque(Xdr.java:554)
    at org.dcache.oncrpc4j.rpcgen.Value.xdrEncode(Value.java:33)
    at org.dcache.xdr.RpcCall.acceptedReply(RpcCall.java:238)
    at org.dcache.xdr.RpcCall.reply(RpcCall.java:225)

im not sure if anything can be done, since the specs (rfcs 1014, 1832 and 4056) dont say anything about nulls. and variable-length fields are encoded starting with the length as an unsigned number ...

im opening this just to verify that this should be treated as user error.

@radai-rosenblatt
Copy link
Contributor Author

note - this does not apply to unions, just "plain" variable length opaque fields

@kofemann kofemann added the bug label Jul 22, 2015
@kofemann
Copy link
Member

I think null values for a vector can be treated as a zero length array. The rpcgen code have to be updated as well to generate corresponding encoders.

@radai-rosenblatt
Copy link
Contributor Author

0 length array and null are not equivalent. the closesnt approximation i've been able to come up with is this:

struct Key {
    opaque data<16>;
};

union Value switch (bool notNull) {
    case TRUE:
        opaque data<1024>;
    case FALSE:
        void;
};

program BLOB_STORAGE {
    version BLOB_STORAGE_VERS {
        void put(Key key, Value value) = 1;
        Value get(Key key) = 2;
    } = 1;
} = 118;

this leaves the Value.data field actually null (but requires Value.notNull = false to work). the issue here is that:

1 oncrpc4j doesnt generate any setters for this at all. so user code ends up looking like:

Value res = new Value();
if (value != null) {
    res.notNull = true;
    res.data = value;
}

2 on top of getters/setters would be nice if oncrpc4j could recognize the boolean flag has no meaning and just have getData()/setData() - that return/accept null and update the flag accordingly. i realize this "optimization" would only work for non-primitive fields covered under a boolean union variable.

i'll open a pull request with the above test scenario

@radai-rosenblatt
Copy link
Contributor Author

i've opened a pull request #19 with the blob store code above (as a test)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants