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

Long.parseLong(string) fails to recognise 'l' at the end of long number.

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      Ditto

      REGRESSION : Last worked in version 13.0.2

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run Bugette2 sample java Program

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Did not expect a number format exception for valid number
      ACTUAL -
      Number Format Exception on 123l

      ---------- BEGIN SOURCE ----------
      class Bugette2
      {

      public static void main(String[]args)
      {
              Object[]obj={123,123l,1.2f,1.2d};
              String[]str={"123","123l","1.2f","1.2d"};
              Class[]cl={Integer.class,Long.class,Float.class,Double.class};
              for(Object o:obj)prln(o,o.getClass());
              try{int i=Integer.parseInt("123");prln(i);}catch(Exception e){prln(e);}
              try{long l=Long.parseLong("123l");prln(l);}catch(Exception e){prln(e);}
              try{float f=Float.parseFloat("1.2f");prln(f);}catch(Exception e){prln(e);}
              try{double d=Double.parseDouble("1.2d");prln(d);}catch(Exception e){prln(e);}
      }

      static void prln(Object...s)
      {
              String r="";
              for(Object o:s)r+=" "+o;
              System.out.println(r);
      }
      }

      /* Output: Long.parseLong fails to recognoise trailing 'l'

       123 class java.lang.Integer
       123 class java.lang.Long
       1.2 class java.lang.Float
       1.2 class java.lang.Double
       123
       java.lang.NumberFormatException: For input string: "123l"
       1.2
       1.2

      */
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None known

      FREQUENCY : always


            tongwan Andrew Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: