8332614: Type-checked ConstantPool.entryByIndex and ClassReader.readEntryOrNull

Reviewed-by: asotona
This commit is contained in:
Chen Liang 2024-05-30 11:51:49 +00:00 committed by Adam Sotona
parent 1b04f6487c
commit f608918df3
15 changed files with 230 additions and 90 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024, 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
@ -76,17 +76,14 @@ public sealed interface ClassReader extends ConstantPool
// Constant pool
/**
* {@return the UTF8 constant pool entry at the given index of the constant
* pool} The given index must correspond to a valid constant pool index
* whose slot holds a UTF8 constant.
* @param index the index into the constant pool
*/
Utf8Entry utf8EntryByIndex(int index);
/**
* {@return the constant pool entry whose index is given at the specified
* offset within the classfile}
*
* @apiNote
* If only a particular type of entry is expected, use {@link #readEntry(
* int, Class) readEntry(int, Class)}.
*
* @param offset the offset of the index within the classfile
* @throws ConstantPoolException if the index is out of range of the
* constant pool size, or zero
@ -108,12 +105,31 @@ public sealed interface ClassReader extends ConstantPool
* {@return the constant pool entry whose index is given at the specified
* offset within the classfile, or null if the index at the specified
* offset is zero}
*
* @apiNote
* If only a particular type of entry is expected, use {@link #readEntryOrNull(
* int, Class) readEntryOrNull(int, Class)}.
*
* @param offset the offset of the index within the classfile
* @throws ConstantPoolException if the index is out of range of the
* constant pool size
*/
PoolEntry readEntryOrNull(int offset);
/**
* {@return the constant pool entry of a given type whose index is given
* at the specified offset within the classfile, or null if the index at
* the specified offset is zero}
*
* @param <T> the entry type
* @param offset the offset of the index within the classfile
* @param cls the entry type
* @throws ConstantPoolException if the index is out of range of the
* constant pool size, or zero, or the entry is not of the given type
* @since 24
*/
<T extends PoolEntry> T readEntryOrNull(int offset, Class<T> cls);
/**
* {@return the UTF8 entry whose index is given at the specified
* offset within the classfile}