-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
JDK-8282696: Add constructors taking a cause to InvalidObjectException and InvalidClassException #7711
JDK-8282696: Add constructors taking a cause to InvalidObjectException and InvalidClassException #7711
Changes from 2 commits
afc1d01
7ff24c2
2b2219e
80f97dc
5a29e7c
948269c
2de370f
2aeb7f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
|
@@ -48,4 +48,18 @@ public class InvalidObjectException extends ObjectStreamException { | |
public InvalidObjectException(String reason) { | ||
super(reason); | ||
} | ||
|
||
/** | ||
* Constructs an {@code InvalidObjectException} with the given | ||
* reason and cause. | ||
* | ||
* @param reason Detailed message explaining the reason for the failure. | ||
* @param cause the cause | ||
* | ||
* @see ObjectInputValidation | ||
* @since 19 | ||
*/ | ||
public InvalidObjectException(String reason, Throwable cause) { | ||
jddarcy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
super(reason); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes; good catch -- will fix in the next push. Thanks. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1429,9 +1429,7 @@ private void filterCheck(Class<?> clazz, int arrayLength) | |
event.commit(); | ||
} | ||
if (serialFilter != null && (status == null || status == ObjectInputFilter.Status.REJECTED)) { | ||
InvalidClassException ice = new InvalidClassException("filter status: " + status); | ||
ice.initCause(ex); | ||
throw ice; | ||
throw new InvalidClassException("filter status: " + status, ex); | ||
} | ||
} | ||
|
||
|
@@ -1996,14 +1994,10 @@ private ObjectStreamClass readProxyDesc(boolean unshared) | |
} catch (ClassNotFoundException ex) { | ||
resolveEx = ex; | ||
} catch (IllegalAccessError aie) { | ||
IOException ice = new InvalidClassException(aie.getMessage()); | ||
ice.initCause(aie); | ||
throw ice; | ||
throw new InvalidClassException(aie.getMessage(), aie); | ||
} catch (OutOfMemoryError memerr) { | ||
IOException ex = new InvalidObjectException("Proxy interface limit exceeded: " + | ||
Arrays.toString(ifaces)); | ||
ex.initCause(memerr); | ||
throw ex; | ||
throw new InvalidObjectException("Proxy interface limit exceeded: " + | ||
Arrays.toString(ifaces), memerr); | ||
} | ||
|
||
// Call filterCheck on the class before reading anything else | ||
|
@@ -2016,10 +2010,8 @@ private ObjectStreamClass readProxyDesc(boolean unshared) | |
depth++; | ||
desc.initProxy(cl, resolveEx, readClassDesc(false)); | ||
} catch (OutOfMemoryError memerr) { | ||
IOException ex = new InvalidObjectException("Proxy interface limit exceeded: " + | ||
Arrays.toString(ifaces)); | ||
ex.initCause(memerr); | ||
throw ex; | ||
throw new InvalidObjectException("Proxy interface limit exceeded: " + | ||
Arrays.toString(ifaces), memerr); | ||
} finally { | ||
depth--; | ||
} | ||
|
@@ -2050,8 +2042,8 @@ private ObjectStreamClass readNonProxyDesc(boolean unshared) | |
try { | ||
readDesc = readClassDescriptor(); | ||
} catch (ClassNotFoundException ex) { | ||
throw (IOException) new InvalidClassException( | ||
"failed to read class descriptor").initCause(ex); | ||
throw new InvalidClassException("failed to read class descriptor", | ||
ex); | ||
} | ||
|
||
Class<?> cl = null; | ||
|
@@ -2221,9 +2213,9 @@ private Enum<?> readEnum(boolean unshared) throws IOException { | |
Enum<?> en = Enum.valueOf((Class)cl, name); | ||
result = en; | ||
} catch (IllegalArgumentException ex) { | ||
throw (IOException) new InvalidObjectException( | ||
"enum constant " + name + " does not exist in " + | ||
cl).initCause(ex); | ||
throw new InvalidObjectException("enum constant " + | ||
name + " does not exist in " + | ||
cl, ex); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be reflowed to be on two lines instead of 3? Your call. |
||
} | ||
if (!unshared) { | ||
handles.setObject(enumHandle, result); | ||
|
@@ -2262,9 +2254,8 @@ private Object readOrdinaryObject(boolean unshared) | |
try { | ||
obj = desc.isInstantiable() ? desc.newInstance() : null; | ||
} catch (Exception ex) { | ||
throw (IOException) new InvalidClassException( | ||
desc.forClass().getName(), | ||
"unable to create instance").initCause(ex); | ||
throw new InvalidClassException(desc.forClass().getName(), | ||
"unable to create instance", ex); | ||
} | ||
|
||
passHandle = handles.assign(unshared ? unsharedMarker : obj); | ||
|
@@ -2388,16 +2379,12 @@ private Object readRecord(ObjectStreamClass desc) throws IOException { | |
try { | ||
return (Object) ctrMH.invokeExact(fieldValues.primValues, fieldValues.objValues); | ||
} catch (Exception e) { | ||
InvalidObjectException ioe = new InvalidObjectException(e.getMessage()); | ||
ioe.initCause(e); | ||
throw ioe; | ||
throw new InvalidObjectException(e.getMessage(), e); | ||
} catch (Error e) { | ||
throw e; | ||
} catch (Throwable t) { | ||
ObjectStreamException ose = new InvalidObjectException( | ||
"ReflectiveOperationException during deserialization"); | ||
ose.initCause(t); | ||
throw ose; | ||
throw new InvalidObjectException("ReflectiveOperationException " + | ||
"during deserialization", t); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.