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 2629 2005-06-09 21:22:01Z twisti $
39 #include "native/jni.h"
40 #include "native/native.h"
41 #include "native/include/java_lang_Object.h"
42 #include "native/include/java_lang_Class.h"
43 #include "native/include/java_lang_reflect_Field.h"
44 #include "vm/builtin.h"
45 #include "vm/exceptions.h"
46 #include "vm/global.h"
47 #include "vm/initialize.h"
48 #include "vm/loader.h"
49 #include "vm/stringlocal.h"
50 #include "vm/tables.h"
51 #include "vm/resolve.h"
52 #include "vm/jit/stacktrace.h"
56 /* XXX 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) \
94 (c) = (c) /* prevent compiler warning */
104 * Class: java/lang/reflect/Field
106 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
108 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
110 jfieldID target_fid; /* the JNI-fieldid of the wrapping object */
111 jfieldID fid; /* the JNI-fieldid of the field containing the value */
112 jobject o; /* the object for wrapping the primitive type */
113 classinfo *c = (classinfo *) this->declaringClass;
116 /* get the fieldid of the field represented by this Field-object */
117 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
118 /*fid = class_findfield_approx((classinfo *) this->declaringClass,javastring_toutf(this->name, false));*/
119 st = (fid->flags & ACC_STATIC); /* true if field is static */
122 CHECKFIELDACCESS(this,fid,c,return 0);
124 /* The fieldid is used to retrieve the value, for primitive types a new
125 object for wrapping the primitive type is created. */
127 switch ((((classinfo *) this->declaringClass)->fields[this->slot]).descriptor->text[0]) {
129 /* create wrapping class */
130 c = class_java_lang_Integer;
132 /* get fieldid to store the value */
133 target_fid = (*env)->GetFieldID(env, c, "value", "I");
139 SetIntField(env,o,target_fid, (*env)->GetStaticIntField(env, c, fid));
142 SetIntField(env,o,target_fid, (*env)->GetIntField(env,(jobject) obj, fid));
144 /* return the wrapped object */
145 return (java_lang_Object *) o;
148 c = class_java_lang_Long;
150 target_fid = (*env)->GetFieldID(env, c, "value", "J");
155 SetLongField(env,o,target_fid, (*env)->GetStaticLongField(env, c, fid));
157 SetLongField(env,o,target_fid, (*env)->GetLongField(env,(jobject) obj, fid));
159 return (java_lang_Object *) o;
162 c = class_java_lang_Float;
164 target_fid = (*env)->GetFieldID(env, c, "value", "F");
169 SetFloatField(env,o,target_fid, (*env)->GetStaticFloatField(env, c, fid));
171 SetFloatField(env,o,target_fid, (*env)->GetFloatField(env, (jobject) obj, fid));
173 return (java_lang_Object *) o;
176 c = class_java_lang_Double;
178 target_fid = (*env)->GetFieldID(env, c, "value", "D");
183 SetDoubleField(env,o,target_fid, (*env)->GetStaticDoubleField(env, c, fid));
185 SetDoubleField(env,o,target_fid, (*env)->GetDoubleField(env, (jobject) obj, fid));
187 return (java_lang_Object *) o;
190 c = class_java_lang_Byte;
192 target_fid = (*env)->GetFieldID(env, c, "value", "B");
197 SetByteField(env,o,target_fid, (*env)->GetStaticByteField(env, c, fid));
199 SetByteField(env,o,target_fid, (*env)->GetByteField(env, (jobject) obj, fid));
201 return (java_lang_Object *) o;
204 c = class_java_lang_Character;
206 target_fid = (*env)->GetFieldID(env, c, "value", "C");
211 SetCharField(env,o,target_fid, (*env)->GetStaticCharField(env, c, fid));
213 SetCharField(env,o,target_fid, (*env)->GetCharField(env, (jobject) obj, fid));
215 return (java_lang_Object *) o;
218 c = class_java_lang_Short;
220 target_fid = (*env)->GetFieldID(env, c, "value", "S");
225 SetShortField(env,o,target_fid, (*env)->GetStaticShortField(env, c, fid));
227 SetShortField(env,o,target_fid, (*env)->GetShortField(env, (jobject) obj, fid));
229 return (java_lang_Object *) o;
232 c = class_java_lang_Boolean;
234 target_fid = (*env)->GetFieldID(env, c, "value", "Z");
239 SetBooleanField(env,o,target_fid, (*env)->GetStaticBooleanField(env, c, fid));
241 SetBooleanField(env,o,target_fid, (*env)->GetBooleanField(env, (jobject) obj, fid));
243 return (java_lang_Object *) o;
249 return (java_lang_Object*) (*env)->GetStaticObjectField(env, c, fid);
252 return (java_lang_Object*) (*env)->GetObjectField(env, (jobject) obj, fid);
255 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
262 * Class: java/lang/reflect/Field
264 * Signature: (Ljava/lang/Object;)Z
266 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
270 classinfo *c = (classinfo *) this->declaringClass;
273 /* check if the specified slot could be a valid field of this class*/
274 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
275 "declaring class: fieldscount mismatch");
277 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
278 CHECKFIELDACCESS(this,fid,c,return 0);
280 /* check if the field really has the same name and check if the type descriptor is not empty*/
281 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
282 "declaring class: field name mismatch");
283 if (fid->descriptor->blength<1) {
284 log_text("Type-Descriptor is empty");
288 /* check if obj would be needed (not static field), but is 0)*/
289 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
290 *exceptionptr = new_exception(string_java_lang_NullPointerException);
294 /*if (!(fid->flags & ACC_PUBLIC)) {
295 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
300 if (fid->flags & ACC_STATIC) {
301 /* initialize class if needed*/
302 fprintf(stderr, "calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
303 initialize_class((classinfo *) this->declaringClass);
304 if (*exceptionptr) return 0;
306 utf_ptr = fid->descriptor->text;
308 case 'Z': return fid->value.i;
310 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
314 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
315 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
318 utf_ptr = fid->descriptor->text;
320 case 'Z':return getField(obj,jboolean,fid);
322 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
330 * Class: java/lang/reflect/Field
332 * Signature: (Ljava/lang/Object;)B
334 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
338 classinfo *c = (classinfo *) this->declaringClass;
341 /* check if the specified slot could be a valid field of this class*/
342 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
343 "declaring class: fieldscount mismatch");
345 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
347 CHECKFIELDACCESS(this,fid,c,return 0);
349 /* check if the field really has the same name and check if the type descriptor is not empty*/
350 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
351 "declaring class: field name mismatch");
352 if (fid->descriptor->blength<1) {
353 log_text("Type-Descriptor is empty");
357 /* check if obj would be needed (not static field), but is 0)*/
358 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
359 *exceptionptr = new_exception(string_java_lang_NullPointerException);
363 /* if (!(fid->flags & ACC_PUBLIC)) {
364 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
369 if (fid->flags & ACC_STATIC) {
370 /* initialize class if needed*/
371 fprintf(stderr, "calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
372 initialize_class((classinfo *) this->declaringClass);
373 if (*exceptionptr) return 0;
375 utf_ptr = fid->descriptor->text;
377 case 'B': return fid->value.i;
379 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
383 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
384 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
387 utf_ptr = fid->descriptor->text;
389 case 'B':return getField(obj,jbyte,fid);
391 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
399 * Class: java/lang/reflect/Field
401 * Signature: (Ljava/lang/Object;)C
403 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
407 classinfo *c = (classinfo *) this->declaringClass;
410 /* check if the specified slot could be a valid field of this class*/
411 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
412 "declaring class: fieldscount mismatch");
414 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
415 CHECKFIELDACCESS(this,fid,c,return 0);
418 /* check if the field really has the same name and check if the type descriptor is not empty*/
419 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
420 "declaring class: field name mismatch");
421 if (fid->descriptor->blength<1) {
422 log_text("Type-Descriptor is empty");
426 /* check if obj would be needed (not static field), but is 0)*/
427 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
428 *exceptionptr = new_exception(string_java_lang_NullPointerException);
432 /*if (!(fid->flags & ACC_PUBLIC)) {
433 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
438 if (fid->flags & ACC_STATIC) {
439 /* initialize class if needed*/
440 fprintf(stderr, "calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
441 initialize_class((classinfo *) this->declaringClass);
442 if (*exceptionptr) return 0;
444 utf_ptr = fid->descriptor->text;
446 case 'C': return fid->value.i;
448 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
452 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
453 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
456 utf_ptr = fid->descriptor->text;
458 case 'C':return getField(obj,jchar,fid);
460 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
468 * Class: java/lang/reflect/Field
470 * Signature: (Ljava/lang/Object;)D
472 JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *obj)
476 classinfo *c = (classinfo *) this->declaringClass;
479 /* check if the specified slot could be a valid field of this class*/
480 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
481 "declaring class: fieldscount mismatch");
483 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
484 CHECKFIELDACCESS(this,fid,c,return 0);
487 /* check if the field really has the same name and check if the type descriptor is not empty*/
488 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
489 "declaring class: field name mismatch");
490 if (fid->descriptor->blength<1) {
491 log_text("Type-Descriptor is empty");
495 /* check if obj would be needed (not static field), but is 0)*/
496 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
497 *exceptionptr = new_exception(string_java_lang_NullPointerException);
501 /*if (!(fid->flags & ACC_PUBLIC)) {
502 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
507 if (fid->flags & ACC_STATIC) {
508 /* initialize class if needed*/
509 fprintf(stderr, "calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
510 initialize_class((classinfo *) this->declaringClass);
511 if (*exceptionptr) return 0;
513 utf_ptr = fid->descriptor->text;
518 case 'I': return fid->value.i;
519 case 'F': return fid->value.f;
520 case 'D': return fid->value.d;
522 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
526 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
527 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
530 utf_ptr = fid->descriptor->text;
532 case 'B':return getField(obj,jbyte,fid);
533 case 'S':return getField(obj,jshort,fid);
534 case 'C':return getField(obj,jchar,fid);
535 case 'I':return getField(obj,jint,fid);
536 case 'D':return getField(obj,jdouble,fid);
538 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
546 * Class: java/lang/reflect/Field
548 * Signature: (Ljava/lang/Object;)F
550 JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
554 classinfo *c = (classinfo *) this->declaringClass;
557 /* check if the specified slot could be a valid field of this class*/
558 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
559 "declaring class: fieldscount mismatch");
561 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
562 CHECKFIELDACCESS(this,fid,c,return 0);
565 /* check if the field really has the same name and check if the type descriptor is not empty*/
566 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
567 "declaring class: field name mismatch");
568 if (fid->descriptor->blength<1) {
569 log_text("Type-Descriptor is empty");
573 /* check if obj would be needed (not static field), but is 0)*/
574 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
575 *exceptionptr = new_exception(string_java_lang_NullPointerException);
579 /*if (!(fid->flags & ACC_PUBLIC)) {
580 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
585 if (fid->flags & ACC_STATIC) {
586 /* initialize class if needed*/
587 fprintf(stderr, "calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
588 initialize_class((classinfo *) this->declaringClass);
589 if (*exceptionptr) return 0;
591 utf_ptr = fid->descriptor->text;
596 case 'I': return fid->value.i;
597 case 'F': return fid->value.f;
599 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
603 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
604 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
607 utf_ptr = fid->descriptor->text;
609 case 'B':return getField(obj,jbyte,fid);
610 case 'S':return getField(obj,jshort,fid);
611 case 'C':return getField(obj,jchar,fid);
612 case 'I':return getField(obj,jint,fid);
613 case 'F':return getField(obj,jfloat,fid);
615 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
623 * Class: java/lang/reflect/Field
625 * Signature: (Ljava/lang/Object;)I
627 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *obj)
631 classinfo *c = (classinfo *) this->declaringClass;
634 /* check if the specified slot could be a valid field of this class*/
635 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
636 "declaring class: fieldscount mismatch");
638 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
639 CHECKFIELDACCESS(this,fid,c,return 0);
641 /* check if the field really has the same name and check if the type descriptor is not empty*/
642 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
643 "declaring class: field name mismatch");
644 if (fid->descriptor->blength<1) {
645 log_text("Type-Descriptor is empty");
649 /* check if obj would be needed (not static field), but is 0)*/
650 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
651 *exceptionptr = new_exception(string_java_lang_NullPointerException);
655 /*if (!(fid->flags & ACC_PUBLIC)) {
656 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
661 if (fid->flags & ACC_STATIC) {
662 /* initialize class if needed*/
663 fprintf(stderr, "calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
664 initialize_class((classinfo *) this->declaringClass);
665 if (*exceptionptr) return 0;
667 utf_ptr = fid->descriptor->text;
672 case 'I': return fid->value.i;
674 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
678 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
679 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
682 utf_ptr = fid->descriptor->text;
684 case 'B':return getField(obj,jbyte,fid);
685 case 'S':return getField(obj,jshort,fid);
686 case 'C':return getField(obj,jchar,fid);
687 case 'I':return getField(obj,jint,fid);
689 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
697 * Class: java/lang/reflect/Field
699 * Signature: (Ljava/lang/Object;)J
701 JNIEXPORT s8 JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
705 classinfo *c = (classinfo *) this->declaringClass;
708 /* check if the specified slot could be a valid field of this class*/
709 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
710 "declaring class: fieldscount mismatch");
712 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
713 CHECKFIELDACCESS(this,fid,c,return 0);
716 /* check if the field really has the same name and check if the type descriptor is not empty*/
717 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
718 "declaring class: field name mismatch");
719 if (fid->descriptor->blength<1) {
720 log_text("Type-Descriptor is empty");
724 /* check if obj would be needed (not static field), but is 0)*/
725 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
726 *exceptionptr = new_exception(string_java_lang_NullPointerException);
730 /*if (!(fid->flags & ACC_PUBLIC)) {
731 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
736 if (fid->flags & ACC_STATIC) {
737 /* initialize class if needed*/
738 fprintf(stderr, "calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
739 initialize_class((classinfo *) this->declaringClass);
740 if (*exceptionptr) return 0;
742 utf_ptr = fid->descriptor->text;
747 case 'I': return fid->value.i;
748 case 'J': return fid->value.l;
750 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
754 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
755 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
758 utf_ptr = fid->descriptor->text;
760 case 'B':return getField(obj,jbyte,fid);
761 case 'S':return getField(obj,jshort,fid);
762 case 'C':return getField(obj,jchar,fid);
763 case 'I':return getField(obj,jint,fid);
764 case 'J':return getField(obj,jlong,fid);
766 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
774 * Class: java/lang/reflect/Field
776 * Signature: (Ljava/lang/Object;)S
778 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
782 classinfo *c = (classinfo *) this->declaringClass;
785 /* check if the specified slot could be a valid field of this class*/
786 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
787 "declaring class: fieldscount mismatch");
789 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
790 CHECKFIELDACCESS(this,fid,c,return 0);
793 /* check if the field really has the same name and check if the type descriptor is not empty*/
794 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
795 "declaring class: field name mismatch");
796 if (fid->descriptor->blength<1) {
797 log_text("Type-Descriptor is empty");
801 /* check if obj would be needed (not static field), but is 0)*/
802 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
803 *exceptionptr = new_exception(string_java_lang_NullPointerException);
807 /*if (!(fid->flags & ACC_PUBLIC)) {
808 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
813 if (fid->flags & ACC_STATIC) {
814 /* initialize class if needed*/
815 fprintf(stderr, "calling initialize_class %s\n",((classinfo*) this->declaringClass)->name->text);
816 initialize_class((classinfo *) this->declaringClass);
817 if (*exceptionptr) return 0;
819 utf_ptr = fid->descriptor->text;
822 case 'S': return fid->value.i;
824 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
828 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
829 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
832 utf_ptr = fid->descriptor->text;
834 case 'B':return getField(obj,jbyte,fid);
835 case 'S':return getField(obj,jshort,fid);
837 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
845 * Class: java/lang/reflect/Field
847 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
849 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, java_lang_Object *val)
851 jfieldID source_fid; /* the field containing the value to be written */
852 jfieldID fid; /* the field to be written */
856 c = (classinfo *) this->declaringClass;
858 fid = class_findfield_approx(c, javastring_toutf(this->name, false));
860 st = (fid->flags & ACC_STATIC); /* true if the field is static */
862 CHECKFIELDACCESS(this,fid,c,return);
864 if (val && (st || obj)) {
866 c = val->header.vftbl->class;
868 /* The fieldid is used to set the new value, for primitive types the value
869 has to be retrieved from the wrapping object */
870 switch ((((classinfo *) this->declaringClass)->fields[this->slot]).descriptor->text[0]) {
872 /* illegal argument specified */
873 if (c != class_java_lang_Integer)
875 /* determine the field to read the value */
876 source_fid = (*env)->GetFieldID(env, c, "value", "I");
880 /* set the new value */
883 (*env)->SetStaticIntField(env, c, fid, GetIntField(env, (jobject) val, source_fid));
886 (*env)->SetIntField(env, (jobject) obj, fid, GetIntField(env, (jobject) val, source_fid));
891 if (c != class_java_lang_Long)
893 source_fid = (*env)->GetFieldID(env, c, "value", "J");
898 (*env)->SetStaticLongField(env, c, fid, GetLongField(env, (jobject) val, source_fid));
900 (*env)->SetLongField(env, (jobject) obj, fid, GetLongField(env, (jobject) val, source_fid));
905 if (c != class_java_lang_Float)
907 source_fid = (*env)->GetFieldID(env, c, "value", "F");
912 (*env)->SetStaticFloatField(env, c, fid, GetFloatField(env, (jobject) val, source_fid));
914 (*env)->SetFloatField(env, (jobject) obj, fid, GetFloatField(env, (jobject) val, source_fid));
919 if (c != class_java_lang_Double)
921 source_fid = (*env)->GetFieldID(env, c, "value", "D");
922 if (!source_fid) break;
925 (*env)->SetStaticDoubleField(env, c, fid, GetDoubleField(env,(jobject) val,source_fid));
927 (*env)->SetDoubleField(env, (jobject) obj, fid, GetDoubleField(env,(jobject) val,source_fid));
932 if (c != class_java_lang_Byte)
934 source_fid = (*env)->GetFieldID(env, c, "value", "B");
939 (*env)->SetStaticByteField(env, c, fid, GetByteField(env, (jobject) val, source_fid));
941 (*env)->SetByteField(env, (jobject) obj, fid, GetByteField(env, (jobject) val, source_fid));
946 if (c != class_java_lang_Character)
948 source_fid = (*env)->GetFieldID(env, c, "value", "C");
953 (*env)->SetStaticCharField(env, c, fid, GetCharField(env, (jobject) val, source_fid));
955 (*env)->SetCharField(env, (jobject) obj, fid, GetCharField(env, (jobject) val, source_fid));
960 if (c != class_java_lang_Short)
962 source_fid = (*env)->GetFieldID(env, c, "value", "S");
967 (*env)->SetStaticShortField(env, c, fid, GetShortField(env, (jobject) val, source_fid));
969 (*env)->SetShortField(env, (jobject) obj, fid, GetShortField(env, (jobject) val, source_fid));
974 if (c != class_java_lang_Boolean)
976 source_fid = (*env)->GetFieldID(env, c, "value", "Z");
981 (*env)->SetStaticBooleanField(env, c, fid, GetBooleanField(env, (jobject) val, source_fid));
983 (*env)->SetBooleanField(env, (jobject) obj, fid, GetBooleanField(env, (jobject) val, source_fid));
990 (*env)->SetStaticObjectField(env, c, fid, (jobject) val);
992 (*env)->SetObjectField(env, (jobject) obj, fid, (jobject) val);
998 /* raise exception */
999 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1004 * Class: java/lang/reflect/Field
1005 * Method: setBoolean
1006 * Signature: (Ljava/lang/Object;Z)V
1008 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
1012 if (this->declaringClass && obj) {
1013 fid = class_findfield_approx((classinfo *) this->declaringClass,
1014 javastring_toutf(this->name, false));
1017 (*env)->SetBooleanField(env, (jobject) obj, fid, val);
1022 /* raise exception */
1023 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1028 * Class: java/lang/reflect/Field
1030 * Signature: (Ljava/lang/Object;B)V
1032 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
1036 if (this->declaringClass && obj) {
1037 fid = class_findfield_approx((classinfo *) this->declaringClass,
1038 javastring_toutf(this->name, false));
1041 (*env)->SetByteField(env, (jobject) obj, fid, val);
1046 /* raise exception */
1047 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1052 * Class: java/lang/reflect/Field
1054 * Signature: (Ljava/lang/Object;C)V
1056 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
1060 if (this->declaringClass && obj) {
1061 fid = class_findfield_approx((classinfo *) this->declaringClass,
1062 javastring_toutf(this->name, false));
1065 (*env)->SetCharField(env, (jobject) obj, fid, val);
1070 /* raise exception */
1071 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1076 * Class: java/lang/reflect/Field
1078 * Signature: (Ljava/lang/Object;D)V
1080 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, double val)
1084 if (this->declaringClass && obj) {
1085 fid = class_findfield_approx((classinfo *) this->declaringClass,
1086 javastring_toutf(this->name, false));
1089 (*env)->SetDoubleField(env, (jobject) obj, fid, val);
1094 /* raise exception */
1095 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1100 * Class: java/lang/reflect/Field
1102 * Signature: (Ljava/lang/Object;F)V
1104 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, float val)
1108 if (this->declaringClass && obj) {
1109 fid = class_findfield_approx((classinfo *) this->declaringClass,
1110 javastring_toutf(this->name, false));
1113 (*env)->SetFloatField(env, (jobject) obj, fid, val);
1118 /* raise exception */
1119 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1124 * Class: java/lang/reflect/Field
1126 * Signature: (Ljava/lang/Object;I)V
1128 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
1132 if (this->declaringClass && obj) {
1133 fid = class_findfield_approx((classinfo *) this->declaringClass,
1134 javastring_toutf(this->name, false));
1137 (*env)->SetIntField(env, (jobject) obj, fid, val);
1142 /* raise exception */
1143 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1148 * Class: java/lang/reflect/Field
1150 * Signature: (Ljava/lang/Object;J)V
1152 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s8 val)
1156 if (this->declaringClass && obj) {
1157 fid = class_findfield_approx((classinfo *) this->declaringClass,
1158 javastring_toutf(this->name, false));
1161 (*env)->SetLongField(env, (jobject) obj, fid, val);
1166 /* raise exception */
1167 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1172 * Class: java/lang/reflect/Field
1174 * Signature: (Ljava/lang/Object;S)V
1176 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
1180 if (this->declaringClass && obj) {
1181 fid = class_findfield_approx((classinfo *) this->declaringClass,
1182 javastring_toutf(this->name, false));
1185 (*env)->SetShortField(env, (jobject) obj, fid, val);
1190 /* raise exception */
1191 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1196 * Class: java_lang_reflect_Field
1198 * Signature: ()Ljava/lang/Class;
1200 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *env, java_lang_reflect_Field *this)
1202 typedesc *desc = (((classinfo *) this->declaringClass)->fields[this->slot]).parseddesc;
1203 java_lang_Class *ret;
1207 if (!resolve_class_from_typedesc(desc,false,(classinfo **)&ret))
1208 return NULL; /* exception */
1210 use_class_as_object((classinfo*)ret);
1216 * Class: java_lang_reflect_Field
1217 * Method: getModifiers
1220 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getModifiers(JNIEnv *env, java_lang_reflect_Field *this)
1222 return (((classinfo *) this->declaringClass)->fields[this->slot]).flags;
1227 * These are local overrides for various environment variables in Emacs.
1228 * Please do not remove this and leave it at the end of the file, where
1229 * Emacs will automagically detect them.
1230 * ---------------------------------------------------------------------
1233 * indent-tabs-mode: t