-
Enhancement
-
Resolution: Not an Issue
-
P4
-
None
-
1.1.3
-
None
-
generic, x86
-
generic, windows_95
The following was reported in the comments for bug 4056774. It is claimed
that "the readObject method of a Serializable class should be able to make
assigment to a blank final variable that is also transient", e.g. in the
example below:
import java.io.*;
public class BlankFinal implements java.io.Serializable {
final Object var1;
final transient Object var2;
BlankFinal(Object arg1, Object arg2) {
var1 = arg1;
var2 = arg2;
}
BlankFinal(Object arg1) {
this(arg1, arg1);
}
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
try {
in.defaultReadObject();
} catch (NotActiveException nae) {
}
var2 = var1;
}
}
The compiler rejects this program, regarding the assignment to 'var2'
in 'readObject' as a duplicate assignment. This behavior is correct
according to the inner class specification.
It appears then that it is impossible to initialize transient blank
final fields when creating an object from a serialized stream. The
specification needs to clarify the interaction of 'transient' and 'final',
and perhaps forbid their combination, at least in the clase of blank finals.
william.maddox@Eng 1997-08-25
that "the readObject method of a Serializable class should be able to make
assigment to a blank final variable that is also transient", e.g. in the
example below:
import java.io.*;
public class BlankFinal implements java.io.Serializable {
final Object var1;
final transient Object var2;
BlankFinal(Object arg1, Object arg2) {
var1 = arg1;
var2 = arg2;
}
BlankFinal(Object arg1) {
this(arg1, arg1);
}
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
try {
in.defaultReadObject();
} catch (NotActiveException nae) {
}
var2 = var1;
}
}
The compiler rejects this program, regarding the assignment to 'var2'
in 'readObject' as a duplicate assignment. This behavior is correct
according to the inner class specification.
It appears then that it is impossible to initialize transient blank
final fields when creating an object from a serialized stream. The
specification needs to clarify the interaction of 'transient' and 'final',
and perhaps forbid their combination, at least in the clase of blank finals.
william.maddox@Eng 1997-08-25
- relates to
-
JDK-4009144 transient final/static fields - allowed or not?
-
- Closed
-