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

|| doesn't short-circuit empty if's

XMLWordPrintable

    • 1.0.2
    • sparc
    • solaris_2.4
    • Not verified

      The following code invokes func() in the empty-if case, and it shouldn't:

      public class Test {
          static boolean func()
          {
              System.out.println("Func called");
              return true;
          }

          public static void main(String args[]) {
              boolean val = true;

              if (val || func()) {
              }

              System.out.println("Not Prevented");

              if (val || func()) {
                  System.out.println("Prevented");
              }
          }
      }

      The output is:

      Func called
      Not Prevented
      Prevented

            fyellinsunw Frank Yellin (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: