|
Quick Lists
|
|
Bug ID:
|
6226858
|
|
Votes
|
0
|
|
Synopsis
|
NoSuchMethodError in BigDecimal when compiling with 1.5 targetted for 1.4
|
|
Category
|
java:compiler
|
|
Reported Against
|
|
|
Release Fixed
|
|
|
State
|
11-Closed,
Not a Defect,
bug
|
|
Priority:
|
3-Medium
|
|
Related Bugs
|
6419828
,
6578661
|
|
Submit Date
|
08-FEB-2005
|
|
Description
|
FULL PRODUCT VERSION :
Both :
java version "1.4.2_07"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_07-b05)
Java HotSpot(TM) Client VM (build 1.4.2_07-b05, mixed mode)
And
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux dub-280-41 2.6.10-gentoo-r4 #1 SMP Mon Jan 10 12:03:01 GMT 2005 i686 customer (R) Pentium(R) 4 CPU 3.00GHz GenuineIntel GNU/Linux
A DESCRIPTION OF THE PROBLEM :
I was looking into migrating from JDK1.4 to JDK1.5, and given the code (in the example code section)
when I compile this on JDK1.4, it compiles and runs correctly
However, when I compile it as:
/opt/sun-jdk-1.5.0.01/bin/javac -source 1.4 Test.java
And run it (using the 1.4 JVM), I get the following error at runtime:
Exception in thread "main" java.lang.NoSuchMethodError: java.math.BigDecimal.<init>(I)V
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the example source using JDK1.4, run -- works correctly
Compile the example source using JDK1.5, and run against the 1.5 JVM -- works correctly
Compile the example source using JDK1.5, and run against the 1.4 JVM -- fails with NoSuchMethodError
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should work on all releases.
ACTUAL -
NoSuchMethodError
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NoSuchMethodError: java.math.BigDecimal.<init>(I)V
at Test.main(Test.java:6)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.math.BigDecimal;
public class Test
{
public static void main(String[] args)
{
BigDecimal dec = new BigDecimal(1);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Change the code to
BigDecimal dec = new BigDecimal((double) 1);
xxxxx@xxxxx 2005-2-08 21:09:42 GMT
|
|
Work Around
|
N/A
|
|
Evaluation
|
As part of jsr 13, a new constructor, BigDecimal(int val), was added to BigDecimal in JDK 5. Therefore, in 1.4 and earlier
new BigDecimal(1)
in the source resolves to BigDecimal(double) while in 1.5 it resolves to BigDecimal(int), which is not present in earlier JDKs. The -source flag of javac only restricts the constructs in the source languge (e.g. assert, generics); it does *not* restrict or filter the contents of the libraries. Therefore, in JDK5 if you compile with "javac -source 1.4" you will still be compiling against the 1.5 version of the libraries. Therefore, in cases like the one in this bug, code compiled at a lower language level might not be able to be used with an ealier release supporting that language level.
To match both the language and libraries of an ealier jdk, use -source and the -bootclasspath flag to specify the earlier rt.jar as well. Of course the ealier jdk could be used too.
Closing as not a bug.
xxxxx@xxxxx 2005-2-08 21:43:19 GMT
|
|
Comments
|
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |