Mantis - Quercus
Viewing Issue Advanced Details
2345 major always 01-18-08 16:42 01-23-08 21:53
gorck  
nam  
normal  
closed 3.1.3  
fixed  
none    
none 3.1.5  
0002345: Cannot create a BigDecimal, seems to call wrong constructor
It appears BigDecimal is not working.

php script running under tomcat 5.5.25 with quercus jars.

I can run many php scripts and am even able to return a list of my own dtos from a Spring Managed Bean.

However for the life of me I can't get a BigDecimal instantiated via Quercus in a php script. I have even tried to use a my own custom BigDecimalFactory coded in java and it wont work.

I must use BigDecimal in my Dtos. I dont have a choice not to use BigDecimals

If this is not a bug will someone explain to me how to instantiate a java.math.BigDecimal in php.

Here is the simple php script I also tried the lines that are commented out.
<?php
import java.lang.Double;
import java.math.BigDecimal;

$double = Double::parseDouble(3.1);
var_dump($double); //works shows as a float

//none of the following work I get the same stack trace basically for all of them
$bigDecimal = new BigDecimal($double);
//$bigDecimal = new BigDecimal(3.1);
//$bigDecimal = new BigDecimal("3.1");
//$bigDecimal = BigDecimal::valueOf($double);
var_dump($bigDecimal);

The stack trace I get is:

java.lang.NumberFormatException: For input string: "3.1"
java.lang.NumberFormatException.forInputString(Unknown Source)
java.lang.Long.parseLong(Unknown Source)
java.lang.Long.(Unknown Source)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
java.lang.reflect.Constructor.newInstance(Unknown Source)
com.caucho.quercus.env.JavaConstructor.invoke(JavaConstructor.java:96)
com.caucho.quercus.env.JavaInvoker.call(JavaInvoker.java:615)
com.caucho.quercus.env.JavaOverloadMethod.call(JavaOverloadMethod.java:179)
com.caucho.quercus.program.JavaClassDef.callNew(JavaClassDef.java:445)
com.caucho.quercus.env.QuercusClass.callNew(QuercusClass.java:478)
com.caucho.quercus.expr.NewExpr.eval(NewExpr.java:99)
com.caucho.quercus.expr.Expr.evalCopy(Expr.java:399)
com.caucho.quercus.expr.AssignExpr.eval(AssignExpr.java:86)
com.caucho.quercus.program.ExprStatement.execute(ExprStatement.java:64)
com.caucho.quercus.program.BlockStatement.execute(BlockStatement.java:99)
com.caucho.quercus.program.QuercusProgram.execute(QuercusProgram.java:239)
com.caucho.quercus.page.InterpretedPage.execute(InterpretedPage.java:61)
com.caucho.quercus.page.QuercusPage.executeTop(QuercusPage.java:119)
com.caucho.quercus.servlet.QuercusServletImpl.service(QuercusServletImpl.java:163)
com.caucho.quercus.servlet.QuercusServlet.service(QuercusServlet.java:353)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

It appears as though the somehow the incorrect BigDecimal constructor is being called. The one that takes a long instead of a double and Long.parseLong is throwing a NumberFormatException on 3.1.

Any help is much appreciated.

rsinner@cms-solutions.com
 bigDecimal.php [^] (374 bytes) 01-18-08 16:42

Notes
(0002660)
gorck   
01-18-08 17:29   
I also upgrade my jars to version 3.1.4 and the same behavior occurs.

Also I setup my own java factory. That takes in a double and returns a BigDecimal but when I do a var_dump on the php variable it says that its a int instead of a float or a BigDecimal.
ObjectFactory.java
public class ObjectFactory {

    public static BigDecimal getBigDecimal(double val)
    {
        BigDecimal bd = new BigDecimal(val);
        return bd;
    }
}

bigDecimal.php

<?php
import java.lang.Double;
import java.math.BigDecimal;
import com.cms.php.ObjectFactory;

$double = Double::parseDouble(3.1);
var_dump($double); //works shows as a float

//ObjectFactory almost works but showing up as an int
//in the vardump instead of a float
//i.e var_dump($bigDecimal); = int(3) instead of float(3.1) or BigDecimal
$bigDecimal = ObjectFactory::getBigDecimal($double);

//none of the following work all throw stack trace
//$bigDecimal = new BigDecimal($double);
//$bigDecimal = new BigDecimal("3.1");
//$bigDecimal = new BigDecimal(3.1);
//$bigDecimal = BigDecimal::valueOf($double);

var_dump($bigDecimal);

?>
(0002673)
nam   
01-23-08 21:52   
php/0cp-
php/0cq-

Fixed for the upcoming 3.1.5.