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

Compiler removes cast checks whent the result is dead

    XMLWordPrintable

Details

    • 1.1
    • sparc
    • solaris_2.4, solaris_2.5
    • Not verified

    Description


      This program compiles, and runs, without any errors. The problem
      is that compiler is too ambitious and it removes the cast check
      to A since a is dead. This is wrong.

      - eduardo


      class A {}

      public class test {
        private static Object foo() {
          return new Object();
        }
        public static void main(String argv[]) {
          A a = (A) foo();
        }
      }

      The description field as copied from bug report 1239134 follows:

      >From: ###@###.### (Mike Montwill )
      This does not look like form output to me.


      when running the following code:

      class baseClass {

              public baseClass() {}

      }

      class derivedClass extends baseClass {

              public derivedClass () {}

              public void doSomething () {}

      }


      class testClass {

              public testClass () {

                      baseClass baseVar = new baseClass();
                      derivedClass derivedVar = (derivedClass) baseVar; //******
                      // derivedVar.doSomething();

              }

              static public void main (String argv[]) {

                      testClass t = new testClass();
              }
      }

      through the java interpreter after compiling it with javac
      the program terminates normally even though the starred line
      should throw an exception.

      The exception is only thrown if the following line is uncommented.

      The bug here is that a sideeffect (an exception) is optimized away when
      derivedVar is not utilized.

      Environment:
      Win95, JDK release ver 1.0

      Mike Montwill - ###@###.###

      Attachments

        Issue Links

          Activity

            People

              fyellinsunw Frank Yellin (Inactive)
              epelegrisunw Eduardo Pelegrillopart (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: