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

Bad interaction between generics, instanceof, inner classes, and subclasses

    Details

    • Subcomponent:
    • Introduced In Build:
      5.0
    • Introduced In Version:
      5.0
    • CPU:
      x86
    • OS:
      linux

      Description

      Name: jl125535 Date: 06/22/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Linux 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown
      and
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      In a parameterised class, a test "this instanceof" against a non-parameterised subclass gives a compile-time error.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      javac -source 1.5 Test.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Clean compile.
      ACTUAL -
      Error message.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Test.java:3: inconvertible types
      found : Test<T>
      required: Test.Special
          boolean DEBUG = this instanceof Special;
                          ^
      1 error

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      public class Test<T>
      {
          boolean DEBUG = this instanceof Special;

          public static class Special extends Test<String>
          {
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Cast to a non-generified version. E.g. [code]public class Test<T>
      {
          boolean DEBUG = ((Test)this) instanceof Special;

          public static class Special extends Test<String>
          {
          }
      }[/code]
      (Incident Review ID: 280878)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ahe Peter Ahe
                Reporter:
                jleesunw Jon Lee (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: