8284871: Use covariant overrides for the resolveConstantDesc(Lookup) method in sub‑interfaces of java.lang.constant.ConstantDesc

Reviewed-by: mchung
This commit is contained in:
Chen Liang 2023-04-11 13:40:56 +00:00 committed by Mandy Chung
parent cd7d53c88c
commit e5ce7d9e43
15 changed files with 100 additions and 83 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, 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
@ -58,8 +58,8 @@ final class AsTypeMethodHandleDesc extends DynamicConstantDesc<MethodHandle>
@Override
public MethodHandle resolveConstantDesc(MethodHandles.Lookup lookup)
throws ReflectiveOperationException {
MethodHandle handle = (MethodHandle) underlying.resolveConstantDesc(lookup);
MethodType methodType = (MethodType) type.resolveConstantDesc(lookup);
MethodHandle handle = underlying.resolveConstantDesc(lookup);
MethodType methodType = type.resolveConstantDesc(lookup);
return handle.asType(methodType);
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, 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
@ -24,6 +24,7 @@
*/
package java.lang.constant;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.TypeDescriptor;
import java.util.stream.Stream;
@ -362,6 +363,9 @@ public sealed interface ClassDesc
*/
String descriptorString();
@Override
Class<?> resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException;
/**
* Compare the specified object with this descriptor for equality. Returns
* {@code true} if and only if the specified object is also a

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, 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
@ -99,9 +99,9 @@ public sealed interface ConstantDesc
* could not be reflectively resolved in the course of resolution
* @throws LinkageError if a linkage error occurs
*
* @apiNote {@linkplain MethodTypeDesc} can represent method type descriptors
* that are not representable by {@linkplain MethodType}, such as methods with
* more than 255 parameter slots, so attempts to resolve these may result in errors.
* @apiNote Some constant descriptors, such as {@linkplain MethodTypeDesc}, can represent
* a value that is not representable by run-time entities. Attempts to resolve these may
* result in errors.
*
* @jvms 5.4.3 Resolution
* @jvms 5.4.4 Access Control

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, 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
@ -152,8 +152,8 @@ final class DirectMethodHandleDescImpl implements DirectMethodHandleDesc {
public MethodHandle resolveConstantDesc(MethodHandles.Lookup lookup)
throws ReflectiveOperationException {
Class<?> resolvedOwner = (Class<?>) owner.resolveConstantDesc(lookup);
MethodType invocationType = (MethodType) this.invocationType().resolveConstantDesc(lookup);
Class<?> resolvedOwner = owner.resolveConstantDesc(lookup);
MethodType invocationType = this.invocationType().resolveConstantDesc(lookup);
return switch (kind) {
case STATIC,
INTERFACE_STATIC -> lookup.findStatic(resolvedOwner, name, invocationType);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, 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
@ -234,7 +234,7 @@ public class DynamicCallSiteDesc {
*/
public CallSite resolveCallSiteDesc(MethodHandles.Lookup lookup) throws Throwable {
assert bootstrapMethod.invocationType().parameterType(1).equals(CD_String);
MethodHandle bsm = (MethodHandle) bootstrapMethod.resolveConstantDesc(lookup);
MethodHandle bsm = bootstrapMethod.resolveConstantDesc(lookup);
Object[] args = new Object[bootstrapArgs.length + 3];
args[0] = lookup;
args[1] = invocationName;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, 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
@ -252,7 +252,7 @@ public abstract non-sealed class DynamicConstantDesc<T>
@SuppressWarnings("unchecked")
public T resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException {
try {
MethodHandle bsm = (MethodHandle) bootstrapMethod.resolveConstantDesc(lookup);
MethodHandle bsm = bootstrapMethod.resolveConstantDesc(lookup);
if (bsm.type().parameterCount() < 2 ||
!MethodHandles.Lookup.class.isAssignableFrom(bsm.type().parameterType(0))) {
throw new BootstrapMethodError(

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, 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
@ -204,6 +204,9 @@ public sealed interface MethodHandleDesc
*/
MethodTypeDesc invocationType();
@Override
MethodHandle resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException;
/**
* Compares the specified object with this descriptor for equality. Returns
* {@code true} if and only if the specified object is also a

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, 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
@ -24,6 +24,7 @@
*/
package java.lang.constant;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.invoke.TypeDescriptor;
import java.util.List;
@ -188,6 +189,16 @@ public sealed interface MethodTypeDesc
returnType().displayName());
}
/**
* {@inheritDoc}
*
* @apiNote {@linkplain MethodTypeDesc} can represent method type descriptors
* that are not representable by {@linkplain MethodType}, such as methods with
* more than 255 parameter slots, so attempts to resolve these may result in errors.
*/
@Override
MethodType resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException;
/**
* Compares the specified object with this descriptor for equality. Returns
* {@code true} if and only if the specified object is also a