harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leo Li" <liyilei1...@gmail.com>
Subject [classlib][math]BigInteger should have an unexpected "protected clone()" method
Date Sun, 08 Oct 2006 09:09:49 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message