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

WRONG implementation of condition evaluation w/ explicit true

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1.3
    • tools
    • None
    • sparc
    • solaris_2.5.1



      Name: tb29552 Date: 07/29/97


      Conditions within a decision point are not being evaluated
      properly when used with an explicit true.

      For example, look at the following block of code:

      public class bar {
        static char g;
        
        public static void main( String argv[] ) {
          g = ( foo() || true )? 'g' : 'G';
        }

        private static boolean foo() {
          System.out.println( "In foo" );
          return true;
        }
      }

      When compiled and run, this code should reach the ternary,
      evaluate the condition by first evaluating the method foo(),
      which would in turn print a message and return true. Since
      it returns true and a short-circuiting operator OR is used,
      the explicit true should not be evaluated and the decision
      point should be true.

      However, this DOES NOT HAPPEN.

      Rather, what happens is the method foo() is never evaluated
      and the condition is short-circuited to the right and the
      decision point is true.

      The important side effect here is conditional evaluation is
      supposed to be left to right and by not evaluating the left
      condition as expected (and guaranteed by the language spec),
      nasty side effects can occur.

      Please fix.

      Please advise : ###@###.###
      company - RST , email - ###@###.###
      ======================================================================

            wmaddoxsunw William Maddox (Inactive)
            tbell Tim Bell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: