Convert.ToDouble(String, Locale) crashes on a leading '+' sign


(Marko Bohanec) #1

On Java, the last call of Convert.ToDouble crashes with java.lang.NullPointerException

namespace TestDouble;

interface

uses
  RemObjects.Elements.RTL;

type
  ConsoleApp = class
  public
    class method Main(args: array of String);
  end;

implementation

class method ConsoleApp.Main(args: array of String);
begin

  var d := Convert.ToDouble('1.0', Locale.Invariant); // ok
  d := Convert.ToDouble('-1.0', Locale.Invariant); // ok
  d := Double.parseDouble('+1.0'); // ok
  d := Convert.ToDouble('+1.0', Locale.Invariant); // java.lang.NullPointerException
    
end;

end.

(marc hoffman) #2

Fixed, both the NEW for invalid doubles in general, and that it didn’t handle a double with a leading +. I’ve also added Double test cases to the test suite, if you feel like adding more, a pull request would be appreciated :wink: