Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8367618

Move Utf8Entry length validation earlier

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • 26
    • core-libs
    • None

      Summary

      Move the encoded length validation for java.lang.classfile.constantpool.Utf8Entry to when they are being constructed, instead of when they are written to class files.

      Problem

      java.lang.classfile.constantpool.Utf8Entry can be constructed with oversized String instances that cannot be encoded in the class file format. Such errors are reported only when class files are written, which allows invalid instances to float around in the runtime, which makes such failures hard to track.

      Solution

      Reject oversized Strings used to construct Utf8Entry, so they now fail immediately with an IllegalArgumentException. This makes invalid constant nominal descriptors rejected too.

      Specification

      No specification change proposed for now. This affects the whole ClassFile API, but might be covered in the "Consistency checks, syntax checks and verification" section, which specifies fatal exceptions are thrown as IAE. However, some models can be constructed without being written.

      Possible specification changes include:

      1. Documenting every affected API. This is way too massive and applies to collections of strings, nominal descriptors, and many other sites.
      2. 2.

            liach Chen Liang
            liach Chen Liang
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: