Hi, all
    I found that BigInteger have a protected clone() method while as the
spec says BigInteger itself does not implement Cloneable. The clone() method
just new an instance of itself instead of super().clone.Although it is not
public, the Clone() method might lead to side-effect if some Object extends
from it and implements Cloneable.

Here is an testcase:

public class TestCloneable extends TestCase {

public void testClone()
{
 MyBigInteger myBigInteger = new MyBigInteger("12345");
 myBigInteger = (MyBigInteger)myBigInteger.clone();
}
}


class MyBigInteger extends BigInteger implements Cloneable {

public MyBigInteger(String val) {
 super(val);
}

public Object clone()
{
 try {
  return super.clone();
 } catch (CloneNotSupportedException e) {
  return null;
 }
}
}
RI passes while Harmony fails.

Actually this method is called just in order to copy itself so as to remain
immutable in BigInteger's other methods, I recommend to rename the method
not so sensitivly as "Clone". If no one objects, I will raise a jira and
create a patch for it.
--
Leo Li
China Software Development Lab, IBM

Reply via email to