Ruiqi Dong created MATH-1677:
--------------------------------

             Summary:  Inconsistent array cloning in AccurateMathLiteralArrays 
- loadLnMant() returns shallow copy while other load methods return deep copies
                 Key: MATH-1677
                 URL: https://issues.apache.org/jira/browse/MATH-1677
             Project: Commons Math
          Issue Type: Bug
            Reporter: Ruiqi Dong


In the class 
{{{}org.apache.commons.math4.core.jdkmath.AccurateMathLiteralArrays{}}}, the 
method {{loadLnMant()}} returns a shallow copy of the two-dimensional array 
{{{}LN_MANT{}}}, which is inconsistent with the behavior of other load methods 
in the same class. For 2D arrays, {{clone()}} only copies the outer array 
reference, leaving the inner arrays shared between the original and the clone. 
This means modifications to the returned array can affect the original constant 
data.




Test Case:
@Test
voidtestLoadLnMantShallowCopyIssue(){
// Get first copy
double[][] firstCopy = AccurateMathLiteralArrays.loadLnMant();
doubleoriginalValue = firstCopy[0][0];
 
// Modify the first copy
firstCopy[0][0] = originalValue + 999.0;
 
// Get second copy
double[][] secondCopy = AccurateMathLiteralArrays.loadLnMant();
 
// This assertion fails - secondCopy contains the modified value
assertEquals(originalValue, secondCopy[0][0]);
}
 
Test Result:

[*ERROR*]   *AccurateMathLiteralArraysTest.testLoadLnMantShallowCopyIssue:169 
expected: <999.0> but was: <1998.0>*



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to