[
https://issues.apache.org/jira/browse/MATH-1677?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17986090#comment-17986090
]
Alex Herbert commented on MATH-1677:
------------------------------------
{{AccurateMathLiteralArrays}} is an internal class. This will not affect the
end user. A better change would be to remove the clone() call from all the
methods in {{AccurateMathLiteralArrays}} and document the return as a
reference. The caller is a private internal class in {{AccurateMath}} and will
not destroy the data.
Note: Following MATH-1676, please do not raise "bugs" against internal code
when incorrectly used for methods that cannot be called in the public API.
> 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
> Affects Versions: 3.6.1
> Reporter: Ruiqi Dong
> Priority: Critical
> Original Estimate: 0.5h
> Remaining Estimate: 0.5h
>
> 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)