Hi Craig,
the changes look good!
I would like to propose a few improvements of the method mangleObject
you changed. Maybe this should be an extra check in, because they are
not related to the fix for JDO-77.
(1) We plan to add configuration running the TCK with a security
manager. Then the reflection access of method mangleObject should be
enclosed in a doPivileged block.
(2) The method checks for fields of specific types. Should we add date,
BigDecimal, BigInteger, float, double, Float and Double?
(3) We could use 'else if' when checking the field types.
Regards Michael
> Hi,
>
> Please review this patch. It fixes an illegal access exception when
> mangleObject tries to change a final field. The final field was added
> to the PCPoint$Oid class.
>
> The fix checks for final and static modifiers on the field before it
> changes it.
>
> I also changed the method to actually change each field, instead of
> simply changing its value to a constant.
>
> Thanks,
>
> Craig
>
>------------------------------------------------------------------------
>
>Index: test/java/org/apache/jdo/tck/JDO_Test.java
>===================================================================
>--- test/java/org/apache/jdo/tck/JDO_Test.java (revision 208860)
>+++ test/java/org/apache/jdo/tck/JDO_Test.java (working copy)
>@@ -757,43 +757,47 @@
> Field[] fields = oidClass.getFields();
> for (int i = 0; i < fields.length; ++i) {
> Field field = fields[i];
>+ int modifiers = field.getModifiers();
>+ if (java.lang.reflect.Modifier.isFinal(modifiers) ||
>+ java.lang.reflect.Modifier.isStatic(modifiers))
>+ break;
> field.setAccessible(true);
> if (debug)
> logger.debug("field" + i + " has name: " + field.getName() +
> " type: " + field.getType());
> Class fieldType = field.getType();
> if (fieldType == long.class) {
>- field.setLong(oid, 10000L);
>+ field.setLong(oid, 10000L + field.getLong(oid));
> }
> if (fieldType == int.class) {
>- field.setInt(oid, 10000);
>+ field.setInt(oid, 10000 + field.getInt(oid));
> }
> if (fieldType == short.class) {
>- field.setShort(oid, (short)10000);
>+ field.setShort(oid, (short)(10000 + field.getShort(oid)));
> }
> if (fieldType == byte.class) {
>- field.setByte(oid, (byte)100);
>+ field.setByte(oid, (byte)(100 + field.getByte(oid)));
> }
> if (fieldType == char.class) {
>- field.setChar(oid, '0');
>+ field.setChar(oid, (char)(10 + field.getChar(oid)));
> }
> if (fieldType == String.class) {
>- field.set(oid, "This is certainly a challenge");
>+ field.set(oid, "This is certainly a challenge" + (String)field.get(oid));
> }
> if (fieldType == Integer.class) {
>- field.set(oid, new Integer(10000));
>+ field.set(oid, new Integer(10000 + ((Integer)field.get(oid)).intValue()));
> }
> if (fieldType == Long.class) {
>- field.set(oid, new Long(10000L));
>+ field.set(oid, new Long(10000L + ((Long)field.get(oid)).longValue()));
> }
> if (fieldType == Short.class) {
>- field.set(oid, new Short((short)10000));
>+ field.set(oid, new Short((short)(10000 + ((Short)field.get(oid)).shortValue())));
> }
> if (fieldType == Byte.class) {
>- field.set(oid, new Byte((byte)100));
>+ field.set(oid, new Byte((byte)(100 + ((Byte)field.get(oid)).byteValue())));
> }
> if (fieldType == Character.class) {
>- field.set(oid, new Character('0'));
>+ field.set(oid, new Character((char)(10 + ((Character)(field.get(oid))).charValue())));
> }
> }
> }
>
>
>
> ------------------------------------------------------------------------
>
>
> Craig Russell
>
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
>
> 408 276-5638 mailto:Craig.Russell@sun.com
>
> P.S. A good JDO? O, Gasp!
>
>
--
Michael Bouschen Tech@Spree Engineering GmbH
mailto:mbo.tech@spree.de http://www.tech.spree.de/
Tel.:++49/30/235 520-33 Buelowstr. 66
Fax.:++49/30/2175 2012 D-10783 Berlin
|