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

Compiler allows illegal cast of anonymous inner class

    XMLWordPrintable

Details

    • b55
    • x86
    • windows_xp
    • Verified

    Description

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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      The following source code compiles although it should be rejected because the anonymous inner class doesn't implement the interface Test231i and therefore it is illegal to cast the this pointer of the anonymous inner class to the interface:

      class Test231 implements Test231i
      {
      void foo()
      {
      new Object()
      {
      Test231i bar()
      {
      return (Test231i)this;
      }
      };
      }
      }


      interface Test231i
      {
      }

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the example given in the description with javac.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Compilation should fail with an error message.
      ACTUAL -
      No errors are reported by javac.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class Test231 implements Test231i
      {
      void foo()
      {
      new Object()
      {
      Test231i bar()
      {
      return (Test231i)this;
      }
      };
      }
      }


      interface Test231i
      {
      }
      ---------- END SOURCE ----------
      ###@###.### 2005-1-21 06:52:01 GMT

      Attachments

        Issue Links

          Activity

            People

              ahe Peter Ahe
              jssunw Jitender S (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: