mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8210841: test/jdk/vm/runtime/ReflectStackOverflow.java fails with NoClassDefFoundError
Reviewed-by: dholmes, mikael
This commit is contained in:
parent
1adaa503bb
commit
89efb9a78f
1 changed files with 21 additions and 40 deletions
|
@ -25,12 +25,6 @@
|
|||
|
||||
package java.lang.reflect;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamField;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* InvocationTargetException is a checked exception that wraps
|
||||
* an exception thrown by an invoked method or constructor.
|
||||
|
@ -52,6 +46,16 @@ public class InvocationTargetException extends ReflectiveOperationException {
|
|||
*/
|
||||
private static final long serialVersionUID = 4085088731926701167L;
|
||||
|
||||
/**
|
||||
* This field holds the target if the
|
||||
* InvocationTargetException(Throwable target) constructor was
|
||||
* used to instantiate the object
|
||||
*
|
||||
* @serial
|
||||
*
|
||||
*/
|
||||
private Throwable target;
|
||||
|
||||
/**
|
||||
* Constructs an {@code InvocationTargetException} with
|
||||
* {@code null} as the target exception.
|
||||
|
@ -66,7 +70,8 @@ public class InvocationTargetException extends ReflectiveOperationException {
|
|||
* @param target the target exception
|
||||
*/
|
||||
public InvocationTargetException(Throwable target) {
|
||||
super(null, target); // Disallow initCause
|
||||
super((Throwable)null); // Disallow initCause
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,7 +82,8 @@ public class InvocationTargetException extends ReflectiveOperationException {
|
|||
* @param s the detail message
|
||||
*/
|
||||
public InvocationTargetException(Throwable target, String s) {
|
||||
super(s, target); // Disallow initCause
|
||||
super(s, null); // Disallow initCause
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,42 +96,17 @@ public class InvocationTargetException extends ReflectiveOperationException {
|
|||
* @return the thrown target exception (cause of this exception).
|
||||
*/
|
||||
public Throwable getTargetException() {
|
||||
return super.getCause();
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializable fields for UndeclaredThrowableException.
|
||||
* Returns the cause of this exception (the thrown target exception,
|
||||
* which may be {@code null}).
|
||||
*
|
||||
* @serialField target Throwable
|
||||
* @return the cause of this exception.
|
||||
* @since 1.4
|
||||
*/
|
||||
private static final ObjectStreamField[] serialPersistentFields = {
|
||||
new ObjectStreamField("target", Throwable.class)
|
||||
};
|
||||
|
||||
/*
|
||||
* Reconstitutes the InvocationTargetException instance from a stream
|
||||
* and initialize the cause properly when deserializing from an older
|
||||
* version.
|
||||
*
|
||||
* The getException and getCause method returns the private "target" field
|
||||
* in the older implementation and InvocationTargetException::cause
|
||||
* was set to null.
|
||||
*/
|
||||
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream.GetField fields = s.readFields();
|
||||
Throwable exception = (Throwable) fields.get("target", null);
|
||||
if (exception != null) {
|
||||
SharedSecrets.getJavaLangAccess().setCause(this, exception);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* To maintain compatibility with older implementation, write a serial
|
||||
* "target" field with the cause as the value.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
ObjectOutputStream.PutField fields = out.putFields();
|
||||
fields.put("target", super.getCause());
|
||||
out.writeFields();
|
||||
public Throwable getCause() {
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue