Unexpected overflow to zero due to default int literal evaluation

XMLWordPrintable

    • generic

      ADDITIONAL SYSTEM INFORMATION :
      It's from the JDK20 used in Netbeans. Obviously there is an arithmetic overflow, but the compiler does not notice it.

      A DESCRIPTION OF THE PROBLEM :
      The lines

        final long all=256*256*256*256;
        System.out.println(" all="+all);

      results in

       all=0

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      see description; use a 64bit machine

      ---------- BEGIN SOURCE ----------
      see description
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      using long constants 256L*256*256*256 removes the bug

      FREQUENCY :
      ALWAYS

            Assignee:
            Raghu Kale
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: