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

InstanceOfTree#getType doesn't specify when it returns null

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • 25
    • tools
    • None
    • source
    • minimal
    • Java API
    • JDK

      Summary

      InstanceOfTree.getType() returns null in some cases, but its documentation does not say it does. The proposal herein is to document the existing behavior.

      Problem

      InstanceOfTree.getType() returns null in some cases, but its documentation does not say it does.

      Solution

      Enhance the InstanceOfTree.getType() documentation to specify when the method returns null. The existing behavior is not changed. The method returns null if the instanceof uses a pattern, and the pattern is not a type test (binding) pattern.

      Alternatively, the method could attempt to return a non-null value for patterns, but the semantics is unclear for complex patterns.

      Specification

      This is the proposed change:

      diff --git a/src/jdk.compiler/share/classes/com/sun/source/tree/InstanceOfTree.java b/src/jdk.compiler/share/classes/com/sun/source/tree/InstanceOfTree.java
      index f752f7f31913f..dfbf20f0640fb 100644
      --- a/src/jdk.compiler/share/classes/com/sun/source/tree/InstanceOfTree.java
      +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/InstanceOfTree.java
      @@ -48,8 +48,11 @@ public interface InstanceOfTree extends ExpressionTree {
           ExpressionTree getExpression();
      
           /**
      -     * Returns the type for which to check.
      -     * @return the type
      +     * Returns the type for which to check, or {@code null} if this instanceof
      +     * uses a pattern other the {@link BindingPatternTree}.
      +     *
      +     * @return the type or {@code null} if this instanceof uses a pattern other than
      +     *         the {@linkplain BindingPatternTree}
            * @see #getPattern()
            */
           Tree getType();

            jlahoda Jan Lahoda
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: