This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: setting 'final' fields
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 22 Jun 2006 10:51:55 -0600
- Subject: Patch: FYI: setting 'final' fields
- Reply-to: tromey at redhat dot com
I'm checking this in.
In 1.5 you can set a non-static final field via reflection, if the
Field object is marked accessible. JBoss needs this.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* java/lang/reflect/natField.cc (getAddr): Allow setting of final
field when it is accessible.
Index: java/lang/reflect/natField.cc
===================================================================
--- java/lang/reflect/natField.cc (revision 114776)
+++ java/lang/reflect/natField.cc (working copy)
@@ -72,6 +72,10 @@
// Setting a final field is usually not allowed.
if (checkFinal
+ // As of 1.5, you can set a non-static final field if it is
+ // accessible.
+ && (! field->isAccessible()
+ || (field->getModifiers() & java::lang::reflect::Modifier::STATIC))
&& (field->getModifiers() & java::lang::reflect::Modifier::FINAL))
throw new java::lang::IllegalAccessException(JvNewStringUTF
("Field is final"));