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

Integer.parseInt and Long.parseLong throw the wrong exception with zero radix.

    XMLWordPrintable

Details

    • 1.2alpha
    • generic
    • solaris_2.5.1
    • Not verified

    Description


      allan.jacobs@Eng 1997-03-21

      The methods Integer.parseInt and Long.parseLong throw
      ArithmeticExceptions when fed a radix of 0. The specification says
      that they should throw NumberFormatExceptions when this happens.
      See sections 20.7.18 and 20.8.18 .

      algol% cat excps.java

      class excps {
              public static void main ( String[] argv ) {
                      int i;
                      try {
                              i = Integer.parseInt("11",0);
                              System.out.println( i );
                      }
                      catch ( NumberFormatException e ) {
                              System.out.println( "11,0: NumberFormatException" );
                      }
                      catch ( ArithmeticException e ) {
                              System.out.println( "11,0: ArithmeticException" );
                      }

                      long l;
                      try {
                              l = Long.parseLong("11",0);
                              System.out.println( l );
                      }
                      catch ( NumberFormatException e ) {
                              System.out.println( "11,0: NumberFormatException" );
                      }
                      catch ( ArithmeticException e ) {
                              System.out.println( "11,0: ArithmeticException" );
                      }
              }
      }

      algol% javac excps.java
      algol% java excps
      11,0: ArithmeticException
      11,0: ArithmeticException

      Attachments

        Activity

          People

            apalanissunw Anand Palaniswamy (Inactive)
            ajacobssunw Allan Jacobs (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: