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

ConstantPoolBuilder::loadableConstantEntry and constantValueEntry should throw NPE

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • 26
    • core-libs
    • None
    • behavioral
    • low
    • An exceptional behavior is changed, though this behavior is unlikely to be relied on.
    • Java API
    • SE

      Summary

      In java.lang.classfile.constantpool.ConstantPoolBuilder, make loadableConstantEntry and constantValueEntry throw NullPointerException instead of IllegalArgumentException on incoming null arguments.

      Problem

      These two methods are specified, by the package, as other methods in this class, to throw NullPointerException if the incoming argument is null. However, the actual behavior of these methods is they throw IllegalArgumentException instead.

      Solution

      Convert the actual behavior to follow the specification, that they should throw NPE when treatment for null arguments is not otherwise specified.

      An alternative approach would be to specify them to throw IAE for null arguments. However, this would make the two APIs hard for composition - for example, bsmEntry in the same class accepts a List<ConstantDesc>, and uses this API. Currently, IAE would be thrown for nested null in such a list; this is not desirable to users as it increases debugging complexity and the APIs that need the specification change is too many.

      Specification

      None. This is purely behavioral.

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

              Created:
              Updated: