Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0002345 [Quercus] major always 01-18-08 16:42 01-23-08 21:53
Reporter gorck View Status public  
Assigned To nam
Priority normal Resolution fixed  
Status closed   Product Version 3.1.3
Summary 0002345: Cannot create a BigDecimal, seems to call wrong constructor
Description 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
Additional Information
Attached Files  bigDecimal.php [^] (374 bytes) 01-18-08 16:42

- Relationships

- 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.
 

- Issue History
Date Modified Username Field Change
01-18-08 16:42 gorck New Issue
01-18-08 16:42 gorck File Added: bigDecimal.php
01-18-08 17:29 gorck Note Added: 0002660
01-23-08 12:04 nam Status new => assigned
01-23-08 12:04 nam Assigned To  => nam
01-23-08 21:52 nam Status assigned => closed
01-23-08 21:52 nam Note Added: 0002673
01-23-08 21:53 nam Resolution open => fixed
01-23-08 21:53 nam Fixed in Version  => 3.1.5


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
32 total queries executed.
27 unique queries executed.
Powered by Mantis Bugtracker