8331224: ClassCastException in ObjectInputStream hides ClassNotFoundException

Reviewed-by: smarks
This commit is contained in:
Roger Riggs 2024-05-21 14:11:39 +00:00
parent 42e3c842ae
commit 8291c94bcd
2 changed files with 199 additions and 4 deletions

View file

@ -2358,7 +2358,13 @@ public class ObjectInputStream
*/
}
/** Reads a record. */
/**
* Reads and returns a record.
* If an exception is marked for any of the fields, the dependency
* mechanism marks the record as having an exception.
* Null is returned from readRecord and later the exception is thrown at
* the exit of {@link #readObject(Class)}.
**/
private Object readRecord(ObjectStreamClass desc) throws IOException {
ObjectStreamClass.ClassDataSlot[] slots = desc.getClassDataLayout();
if (slots.length != 1) {
@ -2371,6 +2377,9 @@ public class ObjectInputStream
}
FieldValues fieldValues = new FieldValues(desc, true);
if (handles.lookupException(passHandle) != null) {
return null; // slot marked with exception, don't create record
}
// get canonical record constructor adapted to take two arguments:
// - byte[] primValues
@ -2464,8 +2473,11 @@ public class ObjectInputStream
if (slotValues != null) {
slotValues[i] = values;
} else if (obj != null) {
values.defaultCheckFieldValues(obj);
values.defaultSetFieldValues(obj);
if (handles.lookupException(passHandle) == null) {
// passHandle NOT marked with an exception; set field values
values.defaultCheckFieldValues(obj);
values.defaultSetFieldValues(obj);
}
}
}
@ -2484,7 +2496,8 @@ public class ObjectInputStream
}
}
if (obj != null && slotValues != null) {
if (obj != null && slotValues != null && handles.lookupException(passHandle) == null) {
// passHandle NOT marked with an exception
// Check that the non-primitive types are assignable for all slots
// before assigning.
for (int i = 0; i < slots.length; i++) {