harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r598534 - in /harmony/enhanced/drlvm/trunk/vm: tests/kernel/java/lang/reflect/Field5Test.java vmcore/src/kernel_classes/javasrc/java/lang/reflect/Field.java
Date Tue, 27 Nov 2007 07:08:41 GMT
Author: varlax
Date: Mon Nov 26 23:08:41 2007
New Revision: 598534

URL: http://svn.apache.org/viewvc?rev=598534&view=rev
Log:
Fixed HARMONY-4927 [drlvm][kernel] cannot modify final instance fields via reflection

Modified:
    harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/Field5Test.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/reflect/Field.java

Modified: harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/Field5Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/Field5Test.java?rev=598534&r1=598533&r2=598534&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/Field5Test.java (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/Field5Test.java Mon Nov
26 23:08:41 2007
@@ -158,4 +158,51 @@
                 + " java.lang.reflect.AnnotatedField.buz",
                 s);
     }
+    
+    
+    public final int INSTANCE_I = 10;
+    
+    /**
+     * Regression test for HARMONY-4927
+     */    
+    public void testAccessFinalInstance() throws Throwable {
+        Field fi = this.getClass().getField("INSTANCE_I");
+        final Object oldVal = fi.get(this);
+        final Object newVal = new Integer(2134523);
+        
+        try {
+            fi.set(this, newVal);
+            fail("Should not modify final field");
+        } catch (IllegalAccessException expected) {
+            assertEquals(oldVal, fi.get(this));
+        }
+        
+        fi.setAccessible(true);
+        fi.set(this, newVal);        
+        assertEquals(newVal, fi.get(this));
+    }
+    
+    public static final int STATIC_I = 10;
+    
+    public void testAccessFinalStatic() throws Throwable {
+        Field fi = this.getClass().getField("STATIC_I");
+        final Object oldVal = fi.get(null);
+        final Object newVal = new Integer(2134523);
+        
+        try {
+            fi.set(null, newVal);
+            fail("Should not modify final field");
+        } catch (IllegalAccessException expected) {
+            assertEquals(oldVal, fi.get(null));
+        }
+        
+        try {
+            fi.setAccessible(true);
+            fi.set(this, newVal);        
+            fail("Should not modify final field");
+        } catch (IllegalAccessException expected) {
+            assertEquals(oldVal, fi.get(null));
+        }
+    }
+
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/reflect/Field.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/reflect/Field.java?rev=598534&r1=598533&r2=598534&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/reflect/Field.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/reflect/Field.java
Mon Nov 26 23:08:41 2007
@@ -403,9 +403,7 @@
     private Object checkSet(Class callerClass, Object obj)
         throws IllegalArgumentException, IllegalAccessException {
         obj = checkObject(getDeclaringClass(), getModifiers(), obj);
-        if (Modifier.isFinal(getModifiers())) {
-            // TODO perform this check for 1.5.0
-            // && !(isAccessible && obj != null)) {
+        if (Modifier.isFinal(getModifiers()) && !(isAccessible && obj !=
null)) {
             throw new IllegalAccessException(
                 "Can not assign new value to the field with final modifier");
         }



Mime
View raw message