1. Derby
  2. DERBY-4892

Unsafe use of BigDecimal constructors


    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s:
    • Fix Version/s:
    • Component/s: JDBC, Test
    • Labels:


      We have some code that's supposed to work on Java 1.4, but that uses BigDecimal constructors that were not added until Java 5. The problematic constructors are the ones that take a single int or long.

      The constructors are used in the following classes:

      All of the classes are compiled against $


      , so one would expect the build to fail when java14compile.classpath pointed to proper Java 1.4 libraries. However, there is a constructor with a double parameter in Java 1.4, and the compiler picks that constructor if it cannot find the ones for int and long. If that happens, the compiled byte-code works on Java 1.4 and newer, and everything is fine.

      The problem appears when the build does not use the Java 1.4 libraries. This can easily happen if you build without a customized, and PropertySetter ends up building java14compile.classpath based on the auto-detected java15compile.classpath. In that case, the compiler finds the int and long variants of the constructor, even when building against java14compile.classpath. The compiled byte-code will therefore use those Java 5 constructors, and the code will fail at run-time if ever executed on a Java 1.4 JVM.

      To reproduce, build Derby without on a system where PropertySetter doesn't find JDK 1.4. Verify with -DprintCompilerProperties=true that java14compile.classpath is built up of jar files from a Java 5 or Java 6 directory. Then run org.apache.derbyTesting.functionTests.tests.lang.UDTTest using a Java 1.4 JVM. You'll see two errors of this kind:

      1) test_06_casts(org.apache.derbyTesting.functionTests.tests.lang.UDTTest)java.lang.NoSuchMethodError: java.math.BigDecimal.<init>(I)V
      at org.apache.derbyTesting.functionTests.tests.lang.Price.makePrice(
      at org.apache.derbyTesting.functionTests.tests.lang.UDTTest.test_06_casts(
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at org.apache.derbyTesting.junit.BaseTestCase.runBare(
      at junit.extensions.TestDecorator.basicRun(
      at junit.extensions.TestSetup$1.protect(
      at junit.extensions.TestDecorator.basicRun(
      at junit.extensions.TestSetup$1.protect(

      The problem in can be seen if you follow the same procedure as above, and instead of UDTTest run ParameterMappingTest with the patch for DERBY-4891 that enables testing of booleans.

      1. valueof.diff
        2 kB
        Knut Anders Hatlen


        No work has yet been logged on this issue.


          • Assignee:
            Knut Anders Hatlen
            Knut Anders Hatlen
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: