1 /* src/native/vm/Field.c - java/lang/reflect/Field
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Roman Obermaiser
29 Changes: Joseph Wenninger
32 $Id: Field.c 2424 2005-04-30 13:45:06Z jowenn $
37 #include "native/jni.h"
38 #include "native/native.h"
39 #include "native/include/java_lang_Object.h"
40 #include "native/include/java_lang_Class.h"
41 #include "native/include/java_lang_reflect_Field.h"
42 #include "vm/builtin.h"
43 #include "vm/exceptions.h"
44 #include "vm/global.h"
45 #include "vm/initialize.h"
46 #include "vm/loader.h"
47 #include "vm/stringlocal.h"
48 #include "vm/tables.h"
49 #include "vm/resolve.h"
50 #include "vm/jit/stacktrace.h"
55 #warning FIXE SET NATIVES
58 #if (defined(__ALPHA__) || defined(__I386__))
59 /*this = java_lang_reflect_Field, fi=fieldinfo, c=declaredClass (classinfo)*/
60 #define CHECKFIELDACCESS(this,fi,c,doret) \
61 /*log_text("Checking access rights");*/ \
62 if (!(getField(this,jboolean,getFieldID_critical(env,this->header.vftbl->class,"flag","Z")))) { \
64 struct methodinfo *callingMethod; \
66 if ((fi->flags & ACC_PUBLIC)==0) { \
67 callingMethod=cacao_callingMethod(); \
69 if ((fi->flags & ACC_PRIVATE)!=0) { \
70 if (c!=callingMethod->class) { \
74 if ((fi->flags & ACC_PROTECTED)!=0) { \
75 if (!builtin_isanysubclass(callingMethod->class, c)) { \
79 /* default visibility*/ \
80 if (c->packagename!=callingMethod->class->packagename) { \
88 *exceptionptr = new_exception(string_java_lang_IllegalAccessException); \
93 #define CHECKFIELDACCESS(this,fi,c,doret)
103 * Class: java/lang/reflect/Field
105 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
107 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
109 jfieldID target_fid; /* the JNI-fieldid of the wrapping object */
110 jfieldID fid; /* the JNI-fieldid of the field containing the value */
111 jobject o; /* the object for wrapping the primitive type */
112 classinfo *c = (classinfo *) this->declaringClass;
115 /* get the fieldid of the field represented by this Field-object */
116 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
117 /*fid = class_findfield_approx((classinfo *) this->declaringClass,javastring_toutf(this->name, false));*/
118 st = (fid->flags & ACC_STATIC); /* true if field is static */
121 CHECKFIELDACCESS(this,fid,c,return 0);
123 /* The fieldid is used to retrieve the value, for primitive types a new
124 object for wrapping the primitive type is created. */
126 switch ((((classinfo *) this->declaringClass)->fields[this->slot]).descriptor->text[0]) {
128 /* create wrapping class */
129 c = class_java_lang_Integer;
131 /* get fieldid to store the value */
132 target_fid = (*env)->GetFieldID(env, c, "value", "I");
138 SetIntField(env,o,target_fid, (*env)->GetStaticIntField(env, c, fid));
141 SetIntField(env,o,target_fid, (*env)->GetIntField(env,(jobject) obj, fid));
143 /* return the wrapped object */
144 return (java_lang_Object *) o;
147 c = class_java_lang_Long;
149 target_fid = (*env)->GetFieldID(env, c, "value", "J");
154 SetLongField(env,o,target_fid, (*env)->GetStaticLongField(env, c, fid));
156 SetLongField(env,o,target_fid, (*env)->GetLongField(env,(jobject) obj, fid));
158 return (java_lang_Object *) o;
161 c = class_java_lang_Float;
163 target_fid = (*env)->GetFieldID(env, c, "value", "F");
168 SetFloatField(env,o,target_fid, (*env)->GetStaticFloatField(env, c, fid));
170 SetFloatField(env,o,target_fid, (*env)->GetFloatField(env, (jobject) obj, fid));
172 return (java_lang_Object *) o;
175 c = class_java_lang_Double;
177 target_fid = (*env)->GetFieldID(env, c, "value", "D");
182 SetDoubleField(env,o,target_fid, (*env)->GetStaticDoubleField(env, c, fid));
184 SetDoubleField(env,o,target_fid, (*env)->GetDoubleField(env, (jobject) obj, fid));
186 return (java_lang_Object *) o;
189 c = class_java_lang_Byte;
191 target_fid = (*env)->GetFieldID(env, c, "value", "B");
196 SetByteField(env,o,target_fid, (*env)->GetStaticByteField(env, c, fid));
198 SetByteField(env,o,target_fid, (*env)->GetByteField(env, (jobject) obj, fid));
200 return (java_lang_Object *) o;
203 c = class_java_lang_Character;
205 target_fid = (*env)->GetFieldID(env, c, "value", "C");
210 SetCharField(env,o,target_fid, (*env)->GetStaticCharField(env, c, fid));
212 SetCharField(env,o,target_fid, (*env)->GetCharField(env, (jobject) obj, fid));
214 return (java_lang_Object *) o;
217 c = class_java_lang_Short;
219 target_fid = (*env)->GetFieldID(env, c, "value", "S");
224 SetShortField(env,o,target_fid, (*env)->GetStaticShortField(env, c, fid));
226 SetShortField(env,o,target_fid, (*env)->GetShortField(env, (jobject) obj, fid));
228 return (java_lang_Object *) o;
231 c = class_java_lang_Boolean;
233 target_fid = (*env)->GetFieldID(env, c, "value", "Z");
238 SetBooleanField(env,o,target_fid, (*env)->GetStaticBooleanField(env, c, fid));
240 SetBooleanField(env,o,target_fid, (*env)->GetBooleanField(env, (jobject) obj, fid));
242 return (java_lang_Object *) o;
248 return (java_lang_Object*) (*env)->GetStaticObjectField(env, c, fid);
251 return (java_lang_Object*) (*env)->GetObjectField(env, (jobject) obj, fid);
254 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
261 * Class: java/lang/reflect/Field
263 * Signature: (Ljava/lang/Object;)Z
265 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
269 classinfo *c = (classinfo *) this->declaringClass;
272 /* check if the specified slot could be a valid field of this class*/
273 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
274 "declaring class: fieldscount mismatch");
276 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
277 CHECKFIELDACCESS(this,fid,c,return 0);
279 /* check if the field really has the same name and check if the type descriptor is not empty*/
280 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
281 "declaring class: field name mismatch");
282 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
284 /* check if obj would be needed (not static field), but is 0)*/
285 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
286 *exceptionptr = new_exception(string_java_lang_NullPointerException);
290 /*if (!(fid->flags & ACC_PUBLIC)) {
291 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
296 if (fid->flags & ACC_STATIC) {
297 /* initialize class if needed*/
298 fprintf("calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
299 initialize_class((classinfo *) this->declaringClass);
300 if (*exceptionptr) return 0;
302 utf_ptr = fid->descriptor->text;
304 case 'Z': return fid->value.i;
306 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
310 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
311 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
314 utf_ptr = fid->descriptor->text;
316 case 'Z':return getField(obj,jboolean,fid);
318 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
326 * Class: java/lang/reflect/Field
328 * Signature: (Ljava/lang/Object;)B
330 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
334 classinfo *c = (classinfo *) this->declaringClass;
337 /* check if the specified slot could be a valid field of this class*/
338 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
339 "declaring class: fieldscount mismatch");
341 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
343 CHECKFIELDACCESS(this,fid,c,return 0);
345 /* check if the field really has the same name and check if the type descriptor is not empty*/
346 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
347 "declaring class: field name mismatch");
348 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
350 /* check if obj would be needed (not static field), but is 0)*/
351 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
352 *exceptionptr = new_exception(string_java_lang_NullPointerException);
356 /* if (!(fid->flags & ACC_PUBLIC)) {
357 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
362 if (fid->flags & ACC_STATIC) {
363 /* initialize class if needed*/
364 fprintf("calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
365 initialize_class((classinfo *) this->declaringClass);
366 if (*exceptionptr) return 0;
368 utf_ptr = fid->descriptor->text;
370 case 'B': return fid->value.i;
372 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
376 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
377 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
380 utf_ptr = fid->descriptor->text;
382 case 'B':return getField(obj,jbyte,fid);
384 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
392 * Class: java/lang/reflect/Field
394 * Signature: (Ljava/lang/Object;)C
396 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
400 classinfo *c = (classinfo *) this->declaringClass;
403 /* check if the specified slot could be a valid field of this class*/
404 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
405 "declaring class: fieldscount mismatch");
407 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
408 CHECKFIELDACCESS(this,fid,c,return 0);
411 /* check if the field really has the same name and check if the type descriptor is not empty*/
412 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
413 "declaring class: field name mismatch");
414 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
416 /* check if obj would be needed (not static field), but is 0)*/
417 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
418 *exceptionptr = new_exception(string_java_lang_NullPointerException);
422 /*if (!(fid->flags & ACC_PUBLIC)) {
423 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
428 if (fid->flags & ACC_STATIC) {
429 /* initialize class if needed*/
430 fprintf("calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
431 initialize_class((classinfo *) this->declaringClass);
432 if (*exceptionptr) return 0;
434 utf_ptr = fid->descriptor->text;
436 case 'C': return fid->value.i;
438 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
442 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
443 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
446 utf_ptr = fid->descriptor->text;
448 case 'C':return getField(obj,jchar,fid);
450 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
458 * Class: java/lang/reflect/Field
460 * Signature: (Ljava/lang/Object;)D
462 JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *obj)
466 classinfo *c = (classinfo *) this->declaringClass;
469 /* check if the specified slot could be a valid field of this class*/
470 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
471 "declaring class: fieldscount mismatch");
473 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
474 CHECKFIELDACCESS(this,fid,c,return 0);
477 /* check if the field really has the same name and check if the type descriptor is not empty*/
478 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
479 "declaring class: field name mismatch");
480 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
482 /* check if obj would be needed (not static field), but is 0)*/
483 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
484 *exceptionptr = new_exception(string_java_lang_NullPointerException);
488 /*if (!(fid->flags & ACC_PUBLIC)) {
489 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
494 if (fid->flags & ACC_STATIC) {
495 /* initialize class if needed*/
496 fprintf("calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
497 initialize_class((classinfo *) this->declaringClass);
498 if (*exceptionptr) return 0;
500 utf_ptr = fid->descriptor->text;
505 case 'I': return fid->value.i;
506 case 'F': return fid->value.f;
507 case 'D': return fid->value.d;
509 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
513 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
514 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
517 utf_ptr = fid->descriptor->text;
519 case 'B':return getField(obj,jbyte,fid);
520 case 'S':return getField(obj,jshort,fid);
521 case 'C':return getField(obj,jchar,fid);
522 case 'I':return getField(obj,jint,fid);
523 case 'D':return getField(obj,jdouble,fid);
525 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
533 * Class: java/lang/reflect/Field
535 * Signature: (Ljava/lang/Object;)F
537 JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
541 classinfo *c = (classinfo *) this->declaringClass;
544 /* check if the specified slot could be a valid field of this class*/
545 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
546 "declaring class: fieldscount mismatch");
548 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
549 CHECKFIELDACCESS(this,fid,c,return 0);
552 /* check if the field really has the same name and check if the type descriptor is not empty*/
553 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
554 "declaring class: field name mismatch");
555 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
557 /* check if obj would be needed (not static field), but is 0)*/
558 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
559 *exceptionptr = new_exception(string_java_lang_NullPointerException);
563 /*if (!(fid->flags & ACC_PUBLIC)) {
564 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
569 if (fid->flags & ACC_STATIC) {
570 /* initialize class if needed*/
571 fprintf("calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
572 initialize_class((classinfo *) this->declaringClass);
573 if (*exceptionptr) return 0;
575 utf_ptr = fid->descriptor->text;
580 case 'I': return fid->value.i;
581 case 'F': return fid->value.f;
583 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
587 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
588 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
591 utf_ptr = fid->descriptor->text;
593 case 'B':return getField(obj,jbyte,fid);
594 case 'S':return getField(obj,jshort,fid);
595 case 'C':return getField(obj,jchar,fid);
596 case 'I':return getField(obj,jint,fid);
597 case 'F':return getField(obj,jfloat,fid);
599 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
607 * Class: java/lang/reflect/Field
609 * Signature: (Ljava/lang/Object;)I
611 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *obj)
615 classinfo *c = (classinfo *) this->declaringClass;
618 /* check if the specified slot could be a valid field of this class*/
619 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
620 "declaring class: fieldscount mismatch");
622 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
623 CHECKFIELDACCESS(this,fid,c,return 0);
625 /* check if the field really has the same name and check if the type descriptor is not empty*/
626 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
627 "declaring class: field name mismatch");
628 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
630 /* check if obj would be needed (not static field), but is 0)*/
631 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
632 *exceptionptr = new_exception(string_java_lang_NullPointerException);
636 /*if (!(fid->flags & ACC_PUBLIC)) {
637 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
642 if (fid->flags & ACC_STATIC) {
643 /* initialize class if needed*/
644 fprintf("calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
645 initialize_class((classinfo *) this->declaringClass);
646 if (*exceptionptr) return 0;
648 utf_ptr = fid->descriptor->text;
653 case 'I': return fid->value.i;
655 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
659 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
660 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
663 utf_ptr = fid->descriptor->text;
665 case 'B':return getField(obj,jbyte,fid);
666 case 'S':return getField(obj,jshort,fid);
667 case 'C':return getField(obj,jchar,fid);
668 case 'I':return getField(obj,jint,fid);
670 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
678 * Class: java/lang/reflect/Field
680 * Signature: (Ljava/lang/Object;)J
682 JNIEXPORT s8 JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
686 classinfo *c = (classinfo *) this->declaringClass;
689 /* check if the specified slot could be a valid field of this class*/
690 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
691 "declaring class: fieldscount mismatch");
693 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
694 CHECKFIELDACCESS(this,fid,c,return 0);
697 /* check if the field really has the same name and check if the type descriptor is not empty*/
698 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
699 "declaring class: field name mismatch");
700 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
702 /* check if obj would be needed (not static field), but is 0)*/
703 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
704 *exceptionptr = new_exception(string_java_lang_NullPointerException);
708 /*if (!(fid->flags & ACC_PUBLIC)) {
709 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
714 if (fid->flags & ACC_STATIC) {
715 /* initialize class if needed*/
716 fprintf("calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
717 initialize_class((classinfo *) this->declaringClass);
718 if (*exceptionptr) return 0;
720 utf_ptr = fid->descriptor->text;
725 case 'I': return fid->value.i;
726 case 'J': return fid->value.l;
728 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
732 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
733 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
736 utf_ptr = fid->descriptor->text;
738 case 'B':return getField(obj,jbyte,fid);
739 case 'S':return getField(obj,jshort,fid);
740 case 'C':return getField(obj,jchar,fid);
741 case 'I':return getField(obj,jint,fid);
742 case 'J':return getField(obj,jlong,fid);
744 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
752 * Class: java/lang/reflect/Field
754 * Signature: (Ljava/lang/Object;)S
756 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
760 classinfo *c = (classinfo *) this->declaringClass;
763 /* check if the specified slot could be a valid field of this class*/
764 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
765 "declaring class: fieldscount mismatch");
767 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
768 CHECKFIELDACCESS(this,fid,c,return 0);
771 /* check if the field really has the same name and check if the type descriptor is not empty*/
772 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
773 "declaring class: field name mismatch");
774 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
776 /* check if obj would be needed (not static field), but is 0)*/
777 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
778 *exceptionptr = new_exception(string_java_lang_NullPointerException);
782 /*if (!(fid->flags & ACC_PUBLIC)) {
783 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
788 if (fid->flags & ACC_STATIC) {
789 /* initialize class if needed*/
790 fprintf("calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
791 initialize_class((classinfo *) this->declaringClass);
792 if (*exceptionptr) return 0;
794 utf_ptr = fid->descriptor->text;
797 case 'S': return fid->value.i;
799 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
803 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
804 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
807 utf_ptr = fid->descriptor->text;
809 case 'B':return getField(obj,jbyte,fid);
810 case 'S':return getField(obj,jshort,fid);
812 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
820 * Class: java/lang/reflect/Field
822 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
824 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, java_lang_Object *val)
826 jfieldID source_fid; /* the field containing the value to be written */
827 jfieldID fid; /* the field to be written */
831 fid = class_findfield_approx((classinfo *) this->declaringClass,
832 javastring_toutf(this->name, false));
833 st = (fid->flags & ACC_STATIC); /* true if the field is static */
834 CHECKFIELDACCESS(this,fid,((classinfo *) this->declaringClass),return);
836 if (val && (st || obj)) {
838 c = val->header.vftbl->class;
840 /* The fieldid is used to set the new value, for primitive types the value
841 has to be retrieved from the wrapping object */
842 switch ((((classinfo *) this->declaringClass)->fields[this->slot]).descriptor->text[0]) {
844 /* illegal argument specified */
845 if (c != class_java_lang_Integer)
847 /* determine the field to read the value */
848 source_fid = (*env)->GetFieldID(env, c, "value", "I");
852 /* set the new value */
855 (*env)->SetStaticIntField(env, c, fid, GetIntField(env, (jobject) val, source_fid));
858 (*env)->SetIntField(env, (jobject) obj, fid, GetIntField(env, (jobject) val, source_fid));
863 if (c != class_java_lang_Long)
865 source_fid = (*env)->GetFieldID(env, c, "value", "J");
870 (*env)->SetStaticLongField(env, c, fid, GetLongField(env, (jobject) val, source_fid));
872 (*env)->SetLongField(env, (jobject) obj, fid, GetLongField(env, (jobject) val, source_fid));
877 if (c != class_java_lang_Float)
879 source_fid = (*env)->GetFieldID(env, c, "value", "F");
884 (*env)->SetStaticFloatField(env, c, fid, GetFloatField(env, (jobject) val, source_fid));
886 (*env)->SetFloatField(env, (jobject) obj, fid, GetFloatField(env, (jobject) val, source_fid));
891 if (c != class_java_lang_Double)
893 source_fid = (*env)->GetFieldID(env, c, "value", "D");
894 if (!source_fid) break;
897 (*env)->SetStaticDoubleField(env, c, fid, GetDoubleField(env,(jobject) val,source_fid));
899 (*env)->SetDoubleField(env, (jobject) obj, fid, GetDoubleField(env,(jobject) val,source_fid));
904 if (c != class_java_lang_Byte)
906 source_fid = (*env)->GetFieldID(env, c, "value", "B");
911 (*env)->SetStaticByteField(env, c, fid, GetByteField(env, (jobject) val, source_fid));
913 (*env)->SetByteField(env, (jobject) obj, fid, GetByteField(env, (jobject) val, source_fid));
918 if (c != class_java_lang_Character)
920 source_fid = (*env)->GetFieldID(env, c, "value", "C");
925 (*env)->SetStaticCharField(env, c, fid, GetCharField(env, (jobject) val, source_fid));
927 (*env)->SetCharField(env, (jobject) obj, fid, GetCharField(env, (jobject) val, source_fid));
932 if (c != class_java_lang_Short)
934 source_fid = (*env)->GetFieldID(env, c, "value", "S");
939 (*env)->SetStaticShortField(env, c, fid, GetShortField(env, (jobject) val, source_fid));
941 (*env)->SetShortField(env, (jobject) obj, fid, GetShortField(env, (jobject) val, source_fid));
946 if (c != class_java_lang_Boolean)
948 source_fid = (*env)->GetFieldID(env, c, "value", "Z");
953 (*env)->SetStaticBooleanField(env, c, fid, GetBooleanField(env, (jobject) val, source_fid));
955 (*env)->SetBooleanField(env, (jobject) obj, fid, GetBooleanField(env, (jobject) val, source_fid));
962 (*env)->SetStaticObjectField(env, c, fid, (jobject) val);
964 (*env)->SetObjectField(env, (jobject) obj, fid, (jobject) val);
970 /* raise exception */
971 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
976 * Class: java/lang/reflect/Field
978 * Signature: (Ljava/lang/Object;Z)V
980 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
984 if (this->declaringClass && obj) {
985 fid = class_findfield_approx((classinfo *) this->declaringClass,
986 javastring_toutf(this->name, false));
989 (*env)->SetBooleanField(env, (jobject) obj, fid, val);
994 /* raise exception */
995 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1000 * Class: java/lang/reflect/Field
1002 * Signature: (Ljava/lang/Object;B)V
1004 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
1008 if (this->declaringClass && obj) {
1009 fid = class_findfield_approx((classinfo *) this->declaringClass,
1010 javastring_toutf(this->name, false));
1013 (*env)->SetByteField(env, (jobject) obj, fid, val);
1018 /* raise exception */
1019 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1024 * Class: java/lang/reflect/Field
1026 * Signature: (Ljava/lang/Object;C)V
1028 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
1032 if (this->declaringClass && obj) {
1033 fid = class_findfield_approx((classinfo *) this->declaringClass,
1034 javastring_toutf(this->name, false));
1037 (*env)->SetCharField(env, (jobject) obj, fid, val);
1042 /* raise exception */
1043 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1048 * Class: java/lang/reflect/Field
1050 * Signature: (Ljava/lang/Object;D)V
1052 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, double val)
1056 if (this->declaringClass && obj) {
1057 fid = class_findfield_approx((classinfo *) this->declaringClass,
1058 javastring_toutf(this->name, false));
1061 (*env)->SetDoubleField(env, (jobject) obj, fid, val);
1066 /* raise exception */
1067 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1072 * Class: java/lang/reflect/Field
1074 * Signature: (Ljava/lang/Object;F)V
1076 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, float val)
1080 if (this->declaringClass && obj) {
1081 fid = class_findfield_approx((classinfo *) this->declaringClass,
1082 javastring_toutf(this->name, false));
1085 (*env)->SetFloatField(env, (jobject) obj, fid, val);
1090 /* raise exception */
1091 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1096 * Class: java/lang/reflect/Field
1098 * Signature: (Ljava/lang/Object;I)V
1100 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
1104 if (this->declaringClass && obj) {
1105 fid = class_findfield_approx((classinfo *) this->declaringClass,
1106 javastring_toutf(this->name, false));
1109 (*env)->SetIntField(env, (jobject) obj, fid, val);
1114 /* raise exception */
1115 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1120 * Class: java/lang/reflect/Field
1122 * Signature: (Ljava/lang/Object;J)V
1124 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s8 val)
1128 if (this->declaringClass && obj) {
1129 fid = class_findfield_approx((classinfo *) this->declaringClass,
1130 javastring_toutf(this->name, false));
1133 (*env)->SetLongField(env, (jobject) obj, fid, val);
1138 /* raise exception */
1139 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1144 * Class: java/lang/reflect/Field
1146 * Signature: (Ljava/lang/Object;S)V
1148 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
1152 if (this->declaringClass && obj) {
1153 fid = class_findfield_approx((classinfo *) this->declaringClass,
1154 javastring_toutf(this->name, false));
1157 (*env)->SetShortField(env, (jobject) obj, fid, val);
1162 /* raise exception */
1163 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1168 * Class: java_lang_reflect_Field
1170 * Signature: ()Ljava/lang/Class;
1172 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *env, java_lang_reflect_Field *this)
1174 typedesc *desc = (((classinfo *) this->declaringClass)->fields[this->slot]).parseddesc;
1175 java_lang_Class *ret;
1179 if (!resolve_class_from_typedesc(desc,false,(classinfo **)&ret))
1180 return NULL; /* exception */
1182 use_class_as_object((classinfo*)ret);
1188 * Class: java_lang_reflect_Field
1189 * Method: getModifiers
1192 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getModifiers(JNIEnv *env, java_lang_reflect_Field *this)
1194 return (((classinfo *) this->declaringClass)->fields[this->slot]).flags;
1199 * These are local overrides for various environment variables in Emacs.
1200 * Please do not remove this and leave it at the end of the file, where
1201 * Emacs will automagically detect them.
1202 * ---------------------------------------------------------------------
1205 * indent-tabs-mode: t