RFR: 8313258: RuntimeInvisibleTypeAnnotationsAttribute.annotations() API Index out of Bound error

Chen Liang liach at openjdk.org
Thu Aug 31 14:21:05 UTC 2023


On Thu, 31 Aug 2023 11:09:05 GMT, Adam Sotona <asotona at openjdk.org> wrote:

> Classfile API suppose to throw IllegalArgumentException in situations where bytecode offset is out of allowed range. Such situation includes invalid offset parsed from a TypeAnnotation as well as from other CodeAttribute attributes.
> 
> This patch throws IAE for invalid bytecode offset when requested Label for the parsed CodeAttribute, so it cover even wider range of cases than mentioned in the bug report.
> 
> Please review.
> 
> Thanks,
> Adam

src/java.base/share/classes/jdk/internal/classfile/impl/CodeImpl.java line 101:

> 99:     public Label getLabel(int bci) {
> 100:         if (bci < 0 || bci > codeLength)
> 101:             throw new IllegalArgumentException(String.format("Bytecode offset out of range; bci=%d, codeLength=%d",

Should we get an IAE formatter in `jdk.internal.util.Preconditons` for classfile-specific bound checking, so we can do `Preconditions.checkIndex(bci, codeLength, Preconditions.IAE_FORMATTER);` and share it with other use sites of classfile-specific exceptions.

In addition, we might move the `new IllegalArgumentException` constructor calls to a utility method in our `Util` class in case we migrate our exceptions to a new subclass of IAE. Thoughts?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15511#discussion_r1311708857


More information about the core-libs-dev mailing list