提交 49f9de84 编写于 作者: B briangoetz

8019646: Clarify javadoc contract of LambdaMetafactory

Reviewed-by: briangoetz, rfield
Contributed-by: dan.smith@oracle.com
上级 210ffe56
...@@ -101,7 +101,6 @@ import static sun.invoke.util.Wrapper.isWrapperType; ...@@ -101,7 +101,6 @@ import static sun.invoke.util.Wrapper.isWrapperType;
* should implement. * should implement.
* @param additionalBridges Method types for additional signatures to be * @param additionalBridges Method types for additional signatures to be
* bridged to the implementation method * bridged to the implementation method
* @throws ReflectiveOperationException
* @throws LambdaConversionException If any of the meta-factory protocol * @throws LambdaConversionException If any of the meta-factory protocol
* invariants are violated * invariants are violated
*/ */
...@@ -114,7 +113,7 @@ import static sun.invoke.util.Wrapper.isWrapperType; ...@@ -114,7 +113,7 @@ import static sun.invoke.util.Wrapper.isWrapperType;
boolean isSerializable, boolean isSerializable,
Class<?>[] markerInterfaces, Class<?>[] markerInterfaces,
MethodType[] additionalBridges) MethodType[] additionalBridges)
throws ReflectiveOperationException, LambdaConversionException { throws LambdaConversionException {
this.targetClass = caller.lookupClass(); this.targetClass = caller.lookupClass();
this.invokedType = invokedType; this.invokedType = invokedType;
...@@ -160,7 +159,7 @@ import static sun.invoke.util.Wrapper.isWrapperType; ...@@ -160,7 +159,7 @@ import static sun.invoke.util.Wrapper.isWrapperType;
* @throws ReflectiveOperationException * @throws ReflectiveOperationException
*/ */
abstract CallSite buildCallSite() abstract CallSite buildCallSite()
throws ReflectiveOperationException, LambdaConversionException; throws LambdaConversionException;
/** /**
* Check the meta-factory arguments for errors * Check the meta-factory arguments for errors
......
...@@ -128,7 +128,6 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; ...@@ -128,7 +128,6 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
* should implement. * should implement.
* @param additionalBridges Method types for additional signatures to be * @param additionalBridges Method types for additional signatures to be
* bridged to the implementation method * bridged to the implementation method
* @throws ReflectiveOperationException
* @throws LambdaConversionException If any of the meta-factory protocol * @throws LambdaConversionException If any of the meta-factory protocol
* invariants are violated * invariants are violated
*/ */
...@@ -141,7 +140,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; ...@@ -141,7 +140,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
boolean isSerializable, boolean isSerializable,
Class<?>[] markerInterfaces, Class<?>[] markerInterfaces,
MethodType[] additionalBridges) MethodType[] additionalBridges)
throws ReflectiveOperationException, LambdaConversionException { throws LambdaConversionException {
super(caller, invokedType, samMethodName, samMethodType, super(caller, invokedType, samMethodName, samMethodType,
implMethod, instantiatedMethodType, implMethod, instantiatedMethodType,
isSerializable, markerInterfaces, additionalBridges); isSerializable, markerInterfaces, additionalBridges);
...@@ -179,7 +178,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; ...@@ -179,7 +178,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
* is not found * is not found
*/ */
@Override @Override
CallSite buildCallSite() throws ReflectiveOperationException, LambdaConversionException { CallSite buildCallSite() throws LambdaConversionException {
final Class<?> innerClass = spinInnerClass(); final Class<?> innerClass = spinInnerClass();
if (invokedType.parameterCount() == 0) { if (invokedType.parameterCount() == 0) {
final Constructor[] ctrs = AccessController.doPrivileged( final Constructor[] ctrs = AccessController.doPrivileged(
...@@ -190,7 +189,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; ...@@ -190,7 +189,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
} }
}); });
if (ctrs.length != 1) { if (ctrs.length != 1) {
throw new ReflectiveOperationException("Expected one lambda constructor for " throw new LambdaConversionException("Expected one lambda constructor for "
+ innerClass.getCanonicalName() + ", got " + ctrs.length); + innerClass.getCanonicalName() + ", got " + ctrs.length);
} }
// The lambda implementing inner class constructor is private, set // The lambda implementing inner class constructor is private, set
...@@ -202,14 +201,24 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; ...@@ -202,14 +201,24 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
return null; return null;
} }
}); });
try {
Object inst = ctrs[0].newInstance(); Object inst = ctrs[0].newInstance();
return new ConstantCallSite(MethodHandles.constant(samBase, inst)); return new ConstantCallSite(MethodHandles.constant(samBase, inst));
}
catch (ReflectiveOperationException e) {
throw new LambdaConversionException("Exception instantiating lambda object", e);
}
} else { } else {
try {
return new ConstantCallSite( return new ConstantCallSite(
MethodHandles.Lookup.IMPL_LOOKUP MethodHandles.Lookup.IMPL_LOOKUP
.findConstructor(innerClass, constructorType) .findConstructor(innerClass, constructorType)
.asType(constructorType.changeReturnType(samBase))); .asType(constructorType.changeReturnType(samBase)));
} }
catch (ReflectiveOperationException e) {
throw new LambdaConversionException("Exception finding constructor", e);
}
}
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册