Skip to content

Commit 6d67cd2

Browse files
committed
core: stateid4: Restore Serialization compatibility
Apparently stateid4 needs to be serialized for dcache, so let's make sure this works again. Signed-off-by: Christian Kohlschütter <[email protected]>
1 parent 3007d90 commit 6d67cd2

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

core/src/main/java/org/dcache/nfs/v4/xdr/stateid4.java

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package org.dcache.nfs.v4.xdr;
2121

2222
import java.io.IOException;
23+
import java.io.ObjectInputStream.GetField;
24+
import java.io.ObjectOutputStream.PutField;
2325
import java.io.Serializable;
2426

2527
import org.dcache.nfs.util.Opaque;
@@ -33,15 +35,17 @@ public class stateid4 implements XdrAble, Serializable, Cloneable {
3335
static final long serialVersionUID = -6677150504723505919L;
3436

3537
private int seqid;
36-
private final Opaque other;
38+
@SuppressWarnings("unused")
39+
private byte[] other; // only declared for Java Serialization
40+
private transient Opaque opaque;
3741

3842
public static stateid4 forBytes(byte[] bytes, int seqid) {
3943
return new stateid4(seqid, Opaque.forBytes(bytes));
4044
}
4145

4246
public stateid4(XdrDecodingStream xdr) throws OncRpcException, IOException {
4347
this.seqid = xdr.xdrDecodeInt();
44-
this.other = Opaque.forBytes(xdr.xdrDecodeOpaque(12));
48+
this.opaque = Opaque.forBytes(xdr.xdrDecodeOpaque(12));
4549
}
4650

4751
@Deprecated(forRemoval = true)
@@ -51,38 +55,38 @@ public stateid4(byte[] bytes, int seqid) {
5155

5256
private stateid4(int seqid, Opaque other) {
5357
this.seqid = seqid;
54-
this.other = other.toImmutableOpaque();
58+
this.opaque = other.toImmutableOpaque();
5559
}
5660

5761
public Opaque getOpaque() {
58-
return other;
62+
return opaque;
5963
}
6064

6165
public int getSeqId() {
6266
return seqid;
6367
}
6468

6569
public long getClientId() {
66-
return other.longAt(0);
70+
return opaque.longAt(0);
6771
}
6872

6973
public static long getClientId(Opaque stateIdOther) {
7074
return stateIdOther.longAt(0);
7175
}
7276

7377
public int getType() {
74-
return other.byteAt(11);
78+
return opaque.byteAt(11);
7579
}
7680

7781
@Override
7882
public stateid4 clone() {
79-
return new stateid4(seqid, other);
83+
return new stateid4(seqid, opaque);
8084
}
8185

8286
public void xdrEncode(XdrEncodingStream xdr)
8387
throws OncRpcException, IOException {
8488
xdr.xdrEncodeInt(seqid);
85-
xdr.xdrEncodeOpaque(other.toBytes(), 12);
89+
xdr.xdrEncodeOpaque(opaque.toBytes(), 12);
8690
}
8791

8892
public void xdrDecode(XdrDecodingStream xdr)
@@ -100,7 +104,7 @@ public boolean equals(Object obj) {
100104

101105
final stateid4 other_id = (stateid4) obj;
102106

103-
return this.other.equals(other_id.other);
107+
return this.opaque.equals(other_id.opaque);
104108
}
105109

106110
/**
@@ -115,26 +119,41 @@ public boolean equalsWithSeq(stateid4 otherState) {
115119
return true;
116120
}
117121

118-
return otherState.seqid == this.seqid && this.other.equals(otherState.other);
122+
return otherState.seqid == this.seqid && this.opaque.equals(otherState.opaque);
119123
}
120124

121125
@Override
122126
public int hashCode() {
123-
return this.other.hashCode();
127+
return this.opaque.hashCode();
124128
}
125129

126130
@Override
127131
public String toString() {
128132
StringBuilder sb = new StringBuilder();
129133

130134
sb.append("[");
131-
sb.append(other);
135+
sb.append(opaque);
132136
sb.append(", seq: ").append(seqid).append("]");
133137
return sb.toString();
134138
}
135139

136140
public void bumpSeqid() {
137141
++seqid;
138142
}
143+
144+
private void writeObject(java.io.ObjectOutputStream out)
145+
throws IOException {
146+
PutField pf = out.putFields();
147+
pf.put("seqid", this.seqid);
148+
pf.put("other", this.opaque.toBytes());
149+
out.writeFields();
150+
}
151+
152+
private void readObject(java.io.ObjectInputStream in)
153+
throws IOException, ClassNotFoundException {
154+
GetField gf = in.readFields();
155+
this.seqid = gf.get("seqid", 0);
156+
this.opaque = Opaque.forBytes((byte[]) gf.get("other", new byte[0]));
157+
}
139158
}
140159
// End of stateid4.java

0 commit comments

Comments
 (0)