Skip to content

Commit

Permalink
Merge pull request #9244 from pshipton/mtser
Browse files Browse the repository at this point in the history
Partial MethodType created by readObject can be used
  • Loading branch information
DanHeidinga committed Apr 15, 2020
2 parents 31b6c98 + 27129ec commit 7067c2d
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions jcl/src/java.base/share/classes/java/lang/invoke/MethodType.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar18-SE]*/
/*******************************************************************************
* Copyright (c) 2009, 2019 IBM Corp. and others
* Copyright (c) 2009, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -134,6 +134,22 @@ static final class InternTableAddLock { }
/* Indicate that there are no persistent/serializable fields in MethodType */
private static final ObjectStreamField[] serialPersistentFields = new ObjectStreamField[0];
private static final long serialVersionUID = 292L;
private DeserializedFieldsHolder deserializedFields;


/**
* Holder for the deserialized arguments[] and returnType values
* from #readObject() so they can be passed to #readResolve()
*/
private static class DeserializedFieldsHolder {
Class<?> returnType;
Class<?>[] arguments;

DeserializedFieldsHolder(Class<?> rtype, Class<?>[] args) {
returnType = (rtype == null) ? void.class : rtype;
arguments = (args == null) ? EMTPY_PARAMS : args;
}
}

/*
* Private constructor as MethodTypes need to be interned.
Expand Down Expand Up @@ -1195,14 +1211,13 @@ public Object run() {
}
}
);
try {
fReturnType.set(this, in.readObject());
fArguments.set(this, in.readObject());
} catch(Exception e) {
fReturnType.set(this, void.class);
fArguments.set(this, EMTPY_PARAMS);
throw e;
}
fReturnType.set(this, void.class);
fArguments.set(this, EMTPY_PARAMS);
methodDescriptor = "()V";
stackDescriptionBits = stackDescriptionBits(EMTPY_PARAMS, 0);
Class<?> serialReturnType = (Class<?>) in.readObject();
Class<?>[] serialArguments = (Class<?>[]) in.readObject();
deserializedFields = new DeserializedFieldsHolder(serialReturnType, serialArguments);
} catch (IllegalAccessException e) {
} catch (NoSuchFieldException e) {
}
Expand All @@ -1211,7 +1226,14 @@ public Object run() {
/* Hook to ensure that all objects go through the factory */
@SuppressWarnings("unused")
private Object readResolve() throws ObjectStreamException {
return MethodType.methodType(returnType, arguments);
Class<?> ret = void.class;
Class<?>[] args = EMTPY_PARAMS;
DeserializedFieldsHolder localArgs = deserializedFields;
if (localArgs != null) {
ret = deserializedFields.returnType;
args = deserializedFields.arguments;
}
return MethodType.methodType(ret, args);
}

/*
Expand Down

0 comments on commit 7067c2d

Please sign in to comment.