Permalink
Browse files

deprecate ParseDouble and remove it's usage

  • Loading branch information...
1 parent 41703ce commit cbe903789be8b71b2a3fa4263f0fa6aa4a695e93 @indrajitr indrajitr committed Aug 21, 2011
@@ -21,7 +21,13 @@ package common
* Safely parse a String into a Double, avoiding the JVM bug
* that causes the thread to hang if the String is
* 2.2250738585072012e-308
+ *
+ * This wonkaround is not recommended anymore. Instead consider using a
+ * newer version of JVM which has the necessary fix.
+ *
+ * @see http://blogs.oracle.com/security/entry/security_alert_for_cve-2010-44
*/
+@deprecated("Use a newer or patched JVM instead.")
object ParseDouble {
private val BrokenDouble = BigDecimal("2.2250738585072012e-308")
@@ -233,7 +233,7 @@ object AsInt {
/**
* Safely convert the specified String to an Int.
*/
- def asDouble(in: String): Box[Double] = tryo{ParseDouble(in.trim)}
+ def asDouble(in: String): Box[Double] = tryo{in.trim.toDouble}
/**
* A helpful Int extractor
@@ -379,6 +379,6 @@ final class PartialFunctionWrapper[A](around: PartialFunction[A, _]) {
def isDefinedAt(a: A) = around.isDefinedAt(a) && other.isDefinedAt(a)
def apply(a: A): B = other.apply(a)
}
-
+
}
@@ -18,9 +18,7 @@ package net.liftweb
package util
import scala.util.parsing.combinator.{Parsers, ImplicitConversions}
-import Helpers._
import common._
-import common.{ParseDouble => SafeParseDouble}
object JSONParser extends SafeSeqParser with ImplicitConversions {
implicit def strToInput(in: String): Input = new scala.util.parsing.input.CharArrayReader(in.toCharArray)
@@ -102,21 +100,21 @@ object JSONParser extends SafeSeqParser with ImplicitConversions {
lazy val e = ('e' ~ '-' ^^ {case _ => -1}) | ('e' ~ '+' ^^ {case _ => 1}) | ('e' ^^ {case _ => 1}) |
('E' ~ '-' ^^ {case _ => -1}) | ('E' ~ '+' ^^ {case _ => 1}) | ('E' ^^ {case _ => 1})
- lazy val intFracExp: Parser[Double] = anInt ~ frac ~ exp ^^ {case i ~ f ~ exp => (SafeParseDouble(i.toString+"."+f+"e"+exp))}
+ lazy val intFracExp: Parser[Double] = anInt ~ frac ~ exp ^^ {case i ~ f ~ exp => ((i.toString+"."+f+"e"+exp).toDouble)}
- lazy val intFrac: Parser[Double] = anInt ~ frac ^^ {case i ~ f => (SafeParseDouble(i.toString+"."+f))}
+ lazy val intFrac: Parser[Double] = anInt ~ frac ^^ {case i ~ f => ((i.toString+"."+f).toDouble)}
- lazy val intExp = anInt ~ exp ^^ {case i ~ e => (SafeParseDouble(i.toString+"e"+e))}
+ lazy val intExp = anInt ~ exp ^^ {case i ~ e => ((i.toString+"e"+e).toDouble)}
lazy val anInt: Parser[Long] = (digit19 ~ digits ^? {case x ~ xs if xs.length < 12 => (x :: xs).mkString("").toLong}) |
(digit ^^ {case x => x.toString.toLong}) |
('-' ~> digit19 ~ digits ^? {case x ~ xs if xs.length < 12 => ((x :: xs).mkString("").toLong * -1L)}) |
('-' ~> digit ^^ {case x => x.toString.toLong * -1L})
- lazy val manyCharInt: Parser[Double] = (digit19 ~ digits ^^ {case x ~ xs => SafeParseDouble((x :: xs).mkString)}) |
- (digit ^^ {case x => SafeParseDouble(x.toString)}) |
- ('-' ~> digit19 ~ digits ^^ {case x ~ xs => SafeParseDouble(((x :: xs).mkString)) * -1d}) |
- ('-' ~> digit ^^ {case x => SafeParseDouble(x.toString) * -1d})
+ lazy val manyCharInt: Parser[Double] = (digit19 ~ digits ^^ {case x ~ xs => (x :: xs).mkString.toDouble}) |
+ (digit ^^ {case x => x.toString.toDouble}) |
+ ('-' ~> digit19 ~ digits ^^ {case x ~ xs => (x :: xs).mkString.toDouble * -1d}) |
+ ('-' ~> digit ^^ {case x => x.toString.toDouble * -1d})
lazy val digit19 = elem("digit", c => c >= '1' && c <= '9')
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package net.liftweb
-package record
-package field
+package net.liftweb
+package record
+package field
import scala.xml._
import net.liftweb.common._
@@ -29,7 +29,7 @@ import S._
trait DoubleTypedField extends NumericTypedField[Double] {
def setFromAny(in: Any): Box[Double] = setNumericFromAny(in, _.doubleValue)
- def setFromString(s: String): Box[Double] = setBox(tryo(ParseDouble(s)))
+ def setFromString(s: String): Box[Double] = setBox(tryo(java.lang.Double.parseDouble(s)))
def defaultValue = 0.0

0 comments on commit cbe9037

Please sign in to comment.