harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jimmy,Jing Lv" <firep...@gmail.com>
Subject [classlib][sql]RI redefine elements in a pass-in parameter
Date Fri, 11 May 2007 05:31:12 GMT
Hi,

    I meet another strange thing in
javax.sql.rowset.serial.SerialArray.Its constructor SerialArray(Array
array),  get all elements from array.getArray(), and store them as its
elements. To my surprise, RI redefine elements in array that it gets
from array.getArray() when the base type of that array is JAVA_OBJECT.
 A simple test shows this modification:

public class Sqltest extends TestCase {
    public Object[] testElements = new Object[2];

    public void testname() throws Exception {
        testElements[0] = new Object();
        testElements[1] = new Object();
        Array mock = new MockArray();
        SerialArray sa = new SerialArray(mock);
        assertNotSame(sa.getArray(),mock.getArray());
        // elements in mock array has been changed to SerialJavaObject
        assertSame(((Object[])sa.getArray())[0],((Object[])mock.getArray())[0]);
    }
   class MockArray implements Array {

        public boolean returnNull = false;

        public int basetype = Types.JAVA_OBJECT;

        public Object getArray() throws SQLException {
            return testElements;
        }

        public Object getArray(long index, int count) throws SQLException {
            return testElements;
        }

        public Object getArray(long index, int count, Map<String, Class<?>> map)
                throws SQLException {
            return testElements;
        }

        public Object getArray(Map<String, Class<?>> map) throws SQLException
{
            return testElements;
        }

        public int getBaseType() throws SQLException {
            return basetype;
        }

        public String getBaseTypeName() throws SQLException {
            return "BaseName";
        }

        public ResultSet getResultSet() throws SQLException {
            return null;
        }

        public ResultSet getResultSet(long index, int count)
                throws SQLException {
            return null;
        }

        public ResultSet getResultSet(long index, int count,
                Map<String, Class<?>> map) throws SQLException {
            return null;
        }

        public ResultSet getResultSet(Map<String, Class<?>> map)
                throws SQLException {
            return null;
        }

        public void free() throws SQLException {
            // donothing
        }
    }
}

You see,  the original Array.getArray() return a array of Objects, but
after SerialArray is initialized,  it returns an array of
SerialJavaObject, as the same as the SerialJavaObject array we get
from SerialArray.getArray(), the test shows that inside the
constructor, RI replace all elements in Array.getArray().
No Spec says that Array.getArray() should return a copy of Array
elements, so it may just return the array it contains as the MockArray
do. And Spec say nothing about the constructor should modify that
array. However, I doubt if it is suitable for a class constructor to
modify elements of another Array that passes in as a parameter( like a
c-style output parameter without document clearly what it should do)?
I prefer NOT follow RI here, mark it as a non-bug difference, unless
we find some important reason.

Any comments/suggestions?

-- 

Best Regards!

Jimmy, Jing Lv
China Software Development Lab, IBM

Mime
View raw message