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

A string headded by "+" causes NumberFormatException

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      Exception occurs with such string on :
         Integer.valueOf
         Long.ValueOf
         Short.ValueOf

      No problem:
         Double.valueOf
         Float.valueOf
       
       
      Sample program:

      public class test2{
         public static void main(String aa[]){
            Double doubleValue;
            Float floatValue;
            Integer integerValue;
            Long longValue;
            Short shortValue;
            doubleValue = Double.valueOf("+3.21"); // OK
            floatValue = Float.valueOf("+3.21"); // OK
            integerValue = Integer.valueOf("+321"); // NumberFormatException
            longValue = Long.valueOf("+321"); // NumberFormatException
            shortValue = Short.valueOf("+321"); // NumberFormatException
         }
      }

      Attachments

        Activity

          People

            tlindholsunw Timothy Lindholm (Inactive)
            sishidasunw Shoji Ishida (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: