On Thu, 31 Aug 2023 14:18:00 GMT, Chen Liang <li...@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? I think it is a bit overkill for this simple fix. We may discuss it as a part of some wider code cleanups. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/15511#discussion_r1316081838