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

javac silently accepts illegal integer literals

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description



      Name: laC46010 Date: 04/15/97



      Java compiler (JDK1.0.2 - JDK1.1.2) accepts integer literals
      in interval 49000000000..100930000000 though spec allows only
      integer literals less than 2147483648.
      What especially bad is that compiler silently convert them into
      some wrong values, for example 100000000000 into 1215752192.

      JLS (3.10.1 Integer Literals, p.21) says:

      "A compile-time error occurs if a decimal literal of type int is larger
      than 2147483648 (), or if the literal 2147483648 appears anywhere other
      than as the operand of the unary - operator, or if a hexadecimal or
      octal int literal does not fit in 32 bits."


      --------------------------------------
      public class expr05601 {
      public static void main(String args[]) {
      //int i1 = 2147483648;
      //int i2 = 2150000000;
      int x = 49000000000;
      int i3 = 100000000000;
      int y = 100930000000;
      //int i4 =1000000000000;
      System.out.println(i3);
      }
      }
      --------------------------------------

      > /export/ld13/java/dest/jdk1.1.2/solaris/bin/javac expr05601.java
      > /export/ld13/java/dest/jdk1.1.2/solaris/bin/java expr05601
      1215752192
      > /export/ld13/java/dest/jdk1.1.2/solaris/bin/java -version
      java version "1.1.2"

      After uncommenting commented lines, javac correctly reports error messages
      about illegal literals 2147483648, 2150000000, 1000000000000 but again
      it doesn't say anything about 49000000000, 100000000000, 100930000000

      > /export/ld13/java/dest/jdk1.1.2/solaris/bin/javac expr05601.java
      expr05601.java:3: Numeric overflow.
      int i1 = 2147483648;
      ^
      expr05601.java:4: Numeric overflow.
      int i2 = 2150000000;
      ^
      expr05601.java:8: Numeric overflow.
      int i4 =1000000000000;
      ^
      3 errors



      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dstoutamsunw David Stoutamire (Inactive)
              Reporter:
              leosunw Leo Leo (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: