Skip to content
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

(0.20.0) Partial MethodType created by readObject can be used #9245

Merged
merged 3 commits into from
Apr 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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