* src/native/llni.h
authorMathias Panzenboeck <e0427417@student.tuwien.ac.at>
Wed, 12 Sep 2007 16:16:50 +0000 (18:16 +0200)
committerMathias Panzenboeck <e0427417@student.tuwien.ac.at>
Wed, 12 Sep 2007 16:16:50 +0000 (18:16 +0200)
(LLNI_classinfo_field_get): New macro.
(LLNI_classinfo_field_set): Likewise.

* src/vmcore/annotation.c
(LLNI_objectarray_copy): New macro. This macro will be replaced by a
appropriate array_* function once such a function exists.
(annotation_bytearrays_resize): Use above macro and improved variable naming.
(annotation_bytearrays_insert): Changed type of parameter 1 and return type and
improved variable naming.
(annotation_load_attribute_body): Use LLNI_CRITICAL_START and LLNI_CRITICAL_END.
(annotation_load_method_attribute_annotationdefault): Use
LLNI_classinfo_field_get and LLNI_classinfo_field_set macros.
(annotation_load_method_attribute_runtimevisibleparameterannotations): Likewise.
(annotation_load_method_attribute_runtimevisibleannotations): Likewise.
(annotation_load_field_attribute_runtimevisibleannotations): Likewise.
(annotation_load_class_attribute_runtimevisibleannotations): Use
LLNI_classinfo_field_set macro.

* src/vmcore/class.c
(class_get_annotations): Use LLNI_classinfo_field_get macro.

* src/vmcore/class.h
(classinfo.annotations),
(classinfo.method_annotations),
(classinfo.method_parameterannotations),
(classinfo.method_annotationdefaults),
(classinfo.field_annotations): Changed type to java_object_t*.

* src/vmcore/field.c
(native/llni.h): Added include.
(field_get_annotations): Use LLNI_classinfo_field_get macro.

* src/vmcore/method.c
(method_get_annotations): Use LLNI_classinfo_field_get macro.
(method_get_parameterannotations): Likewise.
(method_get_annotationdefault): Likewise.

src/native/llni.h
src/vmcore/annotation.c
src/vmcore/class.c
src/vmcore/class.h
src/vmcore/field.c
src/vmcore/method.c

index a0c4cad861ab2cdb9ceac0c270a390b67cced8ea..8d4a8ca4b2c12baf96e64e2d0d2f1b26eb0a7181 100644 (file)
        (variable) = LLNI_field_direct((java_handle_t *) obj, vftbl->class)
 
 
+/* LLNI_classinfo_field_get ***************************************************
+   Get a field from classinfo that is a java object.
+
+******************************************************************************/
+
+#define LLNI_classinfo_field_get(cls, field, variable) \
+       LLNI_CRITICAL_START; \
+       (variable) = LLNI_WRAP((cls)->field); \
+       LLNI_CRITICAL_END
+
+
+/* LLNI_classinfo_field_set ***************************************************
+   Set a field from classinfo that is a java object.
+
+******************************************************************************/
+
+#define LLNI_classinfo_field_set(cls, field, variable) \
+       LLNI_CRITICAL_START; \
+       (cls)->field = LLNI_UNWRAP(variable); \
+       LLNI_CRITICAL_END
+
+
 /* LLNI classinfo wrapping / unwrapping macros *********************************
 
    The following macros are used to wrap or unwrap a classinfo from
index 8c1e4ae8228f9c2c81f65af4cb471eaeaa44263a..a11d798616f512a581e0fedcbde25fe231acd27a 100644 (file)
 #endif
 
 
-/* annotation_bytearrays_resize ***********************************************
+/* LLNI_objectarray_copy ******************************************************
+   Copy nmemb members from object array src to object array dest.
+
+   WARNING: No bound, type or NULL pointer checks are made!
+
+   This should be placed into src/native/llni.h when it's finally decided
+   to do it this way.
+
+******************************************************************************/
+
+#define LLNI_objectarray_copy(dest, src, nmemb) \
+       LLNI_CRITICAL_START; \
+       MCOPY(LLNI_array_data((java_handle_objectarray_t*)(dest)), \
+               LLNI_array_data((java_handle_objectarray_t*)(src)), \
+               java_object_t*, (nmemb)); \
+       LLNI_CRITICAL_END
+
 
+/* annotation_bytearrays_resize ***********************************************
+Set a field from classinfo that is a java objects.
    Resize an array of bytearrays.
 
    IN:
-       bas.....array of bytearrays (bas is short for 'bytearrays')
-       size....new size of the refered array
+       bytearrays.....array of bytearrays
+       size...........new size of the refered array
    
    RETURN VALUE:
        The new array if a resize was neccessarry, the old if the given size
 *******************************************************************************/
 
 static java_handle_objectarray_t *annotation_bytearrays_resize(
-       java_handle_objectarray_t *bas, uint32_t size)
+       java_handle_objectarray_t *bytearrays, uint32_t size)
 {
        java_handle_objectarray_t *newbas = NULL; /* new array     */
        uint32_t minsize = 0;      /* count of object refs to copy */
        uint32_t oldsize = 0;      /* size of old array            */
-       
-       if (bas != NULL) {
-               oldsize = array_length_get((java_handle_t*)bas);
+
+       if (bytearrays != NULL) {
+               oldsize = array_length_get((java_handle_t*)bytearrays);
                
                /* if the size already fits do nothing */
                if (size == oldsize) {
-                       return bas;
+                       return bytearrays;
                }
        }
        
@@ -85,11 +104,10 @@ static java_handle_objectarray_t *annotation_bytearrays_resize(
                primitive_arrayclass_get_by_type(PRIMITIVETYPE_BYTE));
        
        /* is there a old byte array array? */
-       if (newbas != NULL && bas != NULL) {
+       if (newbas != NULL && bytearrays != NULL) {
                minsize = size < oldsize ? size : oldsize;
 
-               MCOPY(LLNI_array_data(newbas), LLNI_array_data(bas),
-                       java_object_t*, minsize);
+               LLNI_objectarray_copy(newbas, bytearrays, minsize);
        }
 
        return newbas;
@@ -101,10 +119,12 @@ static java_handle_objectarray_t *annotation_bytearrays_resize(
    Insert a bytearray into an array of bytearrays.
 
    IN:
-       bas........array of bytearrays where 'ba' has to be insertet into at
-                  position 'index'.
-       index......position where 'ba' has to be inserted into 'bas'.
-       ba.........byte array which has to be inserted into 'bas'.
+       bytearrays........array of bytearrays where 'bytearray' has to be
+                         inserted at position 'index'.
+       index.............position where 'ba' has to be inserted into
+                         'bytearrays'.
+       bytearray.........byte array which has to be inserted into
+                         'bytearrays'.
 
    RETURN VALUE:
        The new array if a resize was neccessarry, the old if the given size
@@ -112,22 +132,26 @@ static java_handle_objectarray_t *annotation_bytearrays_resize(
 
 *******************************************************************************/
 
-static java_handle_objectarray_t *annotation_bytearrays_insert(
-       java_handle_objectarray_t *bas, uint32_t index, java_handle_bytearray_t *ba)
+static java_handle_t *annotation_bytearrays_insert(
+       java_handle_t *bytearrays, uint32_t index,
+       java_handle_bytearray_t *bytearray)
 {
-       uint32_t size = 0; /* current size of the array */
+       java_handle_objectarray_t *bas; /* bytearrays                */
+       uint32_t size = 0;              /* current size of the array */
 
        /* do nothing if NULL is inserted but no array exists */
-       if (ba == NULL && bas == NULL) {
-               return bas;
+       if (bytearray == NULL && bytearrays == NULL) {
+               return NULL;
        }
 
        /* get lengths if array exists */
-       if (bas != NULL) {
-               size = array_length_get((java_handle_t*)bas);
+       if (bytearrays != NULL) {
+               size = array_length_get(bytearrays);
        }
 
-       if (ba == NULL) {
+       bas = (java_handle_objectarray_t*)bytearrays;
+
+       if (bytearray == NULL) {
                /* insert NULL only if array is big enough */
                if (size > index) {
                        array_objectarray_element_set(bas, index, NULL);
@@ -144,10 +168,10 @@ static java_handle_objectarray_t *annotation_bytearrays_insert(
                        }
                }
 
-               array_objectarray_element_set(bas, index, (java_handle_t*)ba);
+               array_objectarray_element_set(bas, index, (java_handle_t*)bytearray);
        }
        
-       return bas;
+       return (java_handle_t*)bas;
 }
 
 
@@ -209,8 +233,12 @@ static bool annotation_load_attribute_body(classbuffer *cb,
                }
 
                /* load data */
+               LLNI_CRITICAL_START;
+
                suck_nbytes((uint8_t*)LLNI_array_data(ba), cb, size);
 
+               LLNI_CRITICAL_END;
+
                /* return data */
                *attribute = ba;
        }
@@ -243,20 +271,18 @@ static bool annotation_load_attribute_body(classbuffer *cb,
 bool annotation_load_method_attribute_annotationdefault(
                classbuffer *cb, methodinfo *m)
 {
-       int                        slot               = 0;
-                                  /* the slot of the method                      */
-       java_handle_bytearray_t   *annotationdefault  = NULL;
-                                  /* unparsed annotation defalut value           */
-       java_handle_objectarray_t *annotationdefaults = NULL;
-                                  /* array of unparsed annotation default values */
+       int                      slot               = 0;
+                                /* the slot of the method                        */
+       java_handle_bytearray_t *annotationdefault  = NULL;
+                                /* unparsed annotation defalut value             */
+       java_handle_t           *annotationdefaults = NULL;
+                                /* array of unparsed annotation default values   */
 
        assert(cb != NULL);
        assert(m != NULL);
 
-       /* XXX: Wait for michis reply if it should be:
-        * LLNI_field_get_ref(m->class, method_annotations, annotationdefaults);
-        */
-       annotationdefaults = m->class->method_annotationdefaults;
+       LLNI_classinfo_field_get(
+               m->class, method_annotationdefaults, annotationdefaults);
 
        if (!annotation_load_attribute_body(
                        cb, &annotationdefault,
@@ -273,10 +299,8 @@ bool annotation_load_method_attribute_annotationdefault(
                        return false;
                }
 
-       /* XXX: Wait for michis reply if it should be:
-        * LLNI_field_set_ref(m->class, method_annotations, annotationdefaults);
-        */
-               m->class->method_annotationdefaults = annotationdefaults;
+               LLNI_classinfo_field_set(
+                       m->class, method_annotationdefaults, annotationdefaults);
        }
 
        return true;
@@ -311,20 +335,18 @@ bool annotation_load_method_attribute_annotationdefault(
 bool annotation_load_method_attribute_runtimevisibleparameterannotations(
                classbuffer *cb, methodinfo *m)
 {
-       int                        slot                 = 0;
-                                  /* the slot of the method */
-       java_handle_bytearray_t   *annotations          = NULL;
-                                  /* unparsed parameter annotations */
-       java_handle_objectarray_t *parameterannotations = NULL;
-                                  /* array of unparsed parameter annotations */
+       int                      slot                 = 0;
+                                /* the slot of the method                  */
+       java_handle_bytearray_t *annotations          = NULL;
+                                /* unparsed parameter annotations          */
+       java_handle_t           *parameterannotations = NULL;
+                                /* array of unparsed parameter annotations */
 
        assert(cb != NULL);
        assert(m != NULL);
 
-       /* XXX: Wait for michis reply if it should be:
-        * LLNI_field_get_ref(m->class, method_parameterannotations, parameterannotations);
-        */
-       parameterannotations = m->class->method_parameterannotations;
+       LLNI_classinfo_field_get(
+               m->class, method_parameterannotations, parameterannotations);
 
        if (!annotation_load_attribute_body(
                        cb, &annotations,
@@ -341,10 +363,8 @@ bool annotation_load_method_attribute_runtimevisibleparameterannotations(
                        return false;
                }
 
-       /* XXX: Wait for michis reply if it should be:
-        * LLNI_field_set_ref(m->class, method_parameterannotations, parameterannotations);
-        */
-               m->class->method_parameterannotations = parameterannotations;
+               LLNI_classinfo_field_set(
+                       m->class, method_parameterannotations, parameterannotations);
        }
 
        return true;
@@ -424,10 +444,8 @@ bool annotation_load_class_attribute_runtimevisibleannotations(
                return false;
        }
 
-       /* XXX: Wait for michis reply if it should be:
-        * LLNI_field_set_ref(cb->class, annotations, annotations);
-        */
-       cb->class->annotations = annotations;
+       LLNI_classinfo_field_set(
+               cb->class, annotations, (java_handle_t*)annotations);
 
        return true;
 }
@@ -469,20 +487,18 @@ bool annotation_load_class_attribute_runtimeinvisibleannotations(
 bool annotation_load_method_attribute_runtimevisibleannotations(
        classbuffer *cb, methodinfo *m)
 {
-       int                        slot               = 0;
-                                  /* slot of the method */
-       java_handle_bytearray_t   *annotations        = NULL;
-                                  /* unparsed annotations */
-       java_handle_objectarray_t *method_annotations = NULL;
-                                  /* array of unparsed method annotations */
+       int                      slot               = 0;
+                                /* slot of the method */
+       java_handle_bytearray_t *annotations        = NULL;
+                                /* unparsed annotations */
+       java_handle_t           *method_annotations = NULL;
+                                /* array of unparsed method annotations */
 
        assert(cb != NULL);
        assert(m != NULL);
 
-       /* XXX: Wait for michis reply if it should be:
-        * LLNI_field_get_ref(m->class, method_annotations, method_annotations);
-        */
-       method_annotations = m->class->method_annotations;
+       LLNI_classinfo_field_get(
+               m->class, method_annotations, method_annotations);
 
        if (!annotation_load_attribute_body(
                        cb, &annotations,
@@ -499,10 +515,8 @@ bool annotation_load_method_attribute_runtimevisibleannotations(
                        return false;
                }
                
-       /* XXX: Wait for michis reply if it should be:
-        * LLNI_field_set_ref(m->class, method_annotations, method_annotations);
-        */
-               m->class->method_annotations = method_annotations;
+               LLNI_classinfo_field_set(
+                       m->class, method_annotations, method_annotations);
        }
 
        return true;
@@ -547,20 +561,18 @@ bool annotation_load_method_attribute_runtimeinvisibleannotations(
 bool annotation_load_field_attribute_runtimevisibleannotations(
        classbuffer *cb, fieldinfo *f)
 {
-       int                        slot              = 0;
-                                  /* slot of the field */
-       java_handle_bytearray_t   *annotations       = NULL;
-                                  /* unparsed annotations */
-       java_handle_objectarray_t *field_annotations = NULL;
-                                  /* array of unparsed field annotations */
+       int                      slot              = 0;
+                                /* slot of the field                   */
+       java_handle_bytearray_t *annotations       = NULL;
+                                /* unparsed annotations                */
+       java_handle_t           *field_annotations = NULL;
+                                /* array of unparsed field annotations */
 
        assert(cb != NULL);
        assert(f != NULL);
 
-       /* XXX: Wait for michis reply if it should be:
-        * LLNI_field_get_ref(f->class, method_annotations, method_annotations);
-        */
-       field_annotations = f->class->field_annotations;
+       LLNI_classinfo_field_get(
+               f->class, field_annotations, field_annotations);
 
        if (!annotation_load_attribute_body(
                        cb, &annotations,
@@ -577,10 +589,8 @@ bool annotation_load_field_attribute_runtimevisibleannotations(
                        return false;
                }
 
-       /* XXX: Wait for michis reply if it should be:
-        * LLNI_field_set_ref(f->class, method_annotations, method_annotations);
-        */
-               f->class->field_annotations = field_annotations;
+               LLNI_classinfo_field_set(
+                       f->class, field_annotations, field_annotations);
        }
 
        return true;
index 0b5e241c33961891ec2870f33cad018aefdefebe..0cb2dce919e7225347de28cb0bd355ddfcdb0359 100644 (file)
@@ -1967,7 +1967,11 @@ java_handle_objectarray_t *class_get_interfaces(classinfo *c)
 java_handle_bytearray_t *class_get_annotations(classinfo *c)
 {
 #if defined(ENABLE_ANNOTATIONS)
-       return c->annotations;
+       java_handle_t *annotations; /* unparsed annotations */
+
+       LLNI_classinfo_field_get(c, annotations, annotations);
+
+       return (java_handle_bytearray_t*)annotations;
 #else
        return NULL;
 #endif
index bb436f10baaf37fdfc30944f531d5571d686974b..179a976dfb95fec9bfc103440fc17b9cadf6bf83 100644 (file)
@@ -147,18 +147,16 @@ struct classinfo {                /* class structure                          */
 #if defined(ENABLE_ANNOTATIONS)
        /* All the annotation attributes are NULL (and not a zero length array)   */
        /* if there is nothing.                                                   */
-       java_handle_bytearray_t   *annotations; /* annotations of this class      */
+       java_object_t *annotations;   /* annotations of this class                */
        
-       java_handle_objectarray_t *method_annotations; /* array of annotations    */
-                                     /* for the methods                          */
-       java_handle_objectarray_t *method_parameterannotations; /* array of       */
-                                     /* parameter annotations for the methods    */
-       java_handle_objectarray_t *method_annotationdefaults; /* array for        */
-                                     /* annotation default values for the        */
-                                     /* methods                                  */
-
-       java_handle_objectarray_t *field_annotations; /* array of annotations for */
-                                     /* the fields                               */
+       java_object_t *method_annotations; /* array of annotations of the methods */
+       java_object_t *method_parameterannotations; /* array of parameter         */
+                                     /* annotations of the methods               */
+       java_object_t *method_annotationdefaults; /* array of annotation default  */
+                                     /* values of the methods                    */
+
+       java_object_t *field_annotations; /* array of annotations of the fields   */
+
 #endif
 #endif
        classloader *classloader;       /* NULL for bootstrap classloader         */
index 31083f1852d26825eebf101f8571c25868727d13..74ab92e7c9c1a9b4a452afb8a6dac2e634f0ad4a 100644 (file)
@@ -33,6 +33,8 @@
 
 #include "mm/memory.h"
 
+#include "native/llni.h"
+
 #include "vm/types.h"
 
 #include "vm/array.h"
@@ -385,7 +387,7 @@ void field_free(fieldinfo *f)
 
 /* field_get_annotations ******************************************************
 
-   Gat a fields' unparsed annotations in a byte array.
+   Get a fields' unparsed annotations in a byte array.
 
    IN:
        f........the field of which the annotations should be returned
@@ -401,21 +403,22 @@ java_handle_bytearray_t *field_get_annotations(fieldinfo *f)
        classinfo               *c;           /* declaring class           */
        int                      slot;        /* slot of this field        */
        java_handle_bytearray_t *annotations; /* unparsed annotations      */
-       java_handle_t           *a;           /* unparsed annotations cast */
-                                             /* into java_handle_t*       */
+       java_handle_t           *field_annotations;  /* array of unparsed  */
+                      /* annotations of all fields of the declaring class */
 
        c           = f->class;
        slot        = f - c->fields;
        annotations = NULL;
-       a           = (java_handle_t*)c->field_annotations;
-       
+
+       LLNI_classinfo_field_get(c, field_annotations, field_annotations);
+
        /* the field_annotations array might be shorter then the field
         * count if the fields above a certain index have no annotations.
         */
-       if (c->field_annotations != NULL && array_length_get(a) > slot) {
-               annotations = (java_handle_bytearray_t*)
-                       array_objectarray_element_get(
-                               c->field_annotations, slot);
+       if (field_annotations != NULL &&
+               array_length_get(field_annotations) > slot) {
+               annotations = (java_handle_bytearray_t*)array_objectarray_element_get(
+                               (java_handle_objectarray_t*)field_annotations, slot);
        }
        
        return annotations;
@@ -547,4 +550,5 @@ void field_fieldref_println(constant_FMIref *fr)
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */
index 011bfc4007ee2b3ea1d8079648e48b9c5af45d60..19c0592cfed2fce2013b34c2da5655439e8cef5f 100644 (file)
@@ -825,26 +825,28 @@ s4 method_count_implementations(methodinfo *m, classinfo *c, methodinfo **found)
 java_handle_bytearray_t *method_get_annotations(methodinfo *m)
 {
 #if defined(ENABLE_ANNOTATIONS)
-       classinfo               *c;           /* methods' declaring class      */
-       int                      slot;        /* methods' slot                 */
-       java_handle_bytearray_t *annotations; /* methods' unparsed annotations */
-       java_handle_t           *a;           /* methods' unparsed annotations */
-                                             /* cast into a java_handle_t*    */
+       classinfo     *c;                  /* methods' declaring class          */
+       int            slot;               /* methods' slot                     */
+       java_handle_t *annotations;        /* methods' unparsed annotations     */
+       java_handle_t *method_annotations; /* all methods' unparsed annotations */
+                                          /* of the declaring class            */
 
        c           = m->class;
        slot        = m - c->methods;
        annotations = NULL;
-       a           = (java_handle_t*)c->method_annotations;
+
+       LLNI_classinfo_field_get(c, method_annotations, method_annotations);
 
        /* the method_annotations array might be shorter then the method
         * count if the methods above a certain index have no annotations.
         */     
-       if (c->method_annotations != NULL && array_length_get(a) > slot) {
-               annotations = (java_handle_bytearray_t*)array_objectarray_element_get(
-                       c->method_annotations, slot);
+       if (method_annotations != NULL &&
+               array_length_get(method_annotations) > slot) {
+               annotations = array_objectarray_element_get(
+                       (java_handle_objectarray_t*)method_annotations, slot);
        }
        
-       return annotations;
+       return (java_handle_bytearray_t*)annotations;
 #else
        return NULL;
 #endif
@@ -869,26 +871,32 @@ java_handle_bytearray_t *method_get_annotations(methodinfo *m)
 java_handle_bytearray_t *method_get_parameterannotations(methodinfo *m)
 {
 #if defined(ENABLE_ANNOTATIONS)
-       classinfo               *c;                  /* methods' declaring class */
-       int                      slot;               /* methods' slot            */
-       java_handle_bytearray_t *parameterAnnotations; /* methods' unparsed      */
-                                                    /* parameter annotations    */
-       java_handle_t           *a;                  /* methods' unparsed        */
-                                                    /* parameter annotations    */
-                                                                                                /* cast into java_handle_t* */
+       classinfo     *c;                           /* methods' declaring class */
+       int            slot;                        /* methods' slot            */
+       java_handle_t *parameterAnnotations;        /* methods' unparsed        */
+                                                   /* parameter annotations    */
+       java_handle_t *method_parameterannotations; /* all methods' unparsed    */
+                                                   /* parameter annotations of */
+                                                   /* the declaring class      */
 
        c                    = m->class;
        slot                 = m - c->methods;
        parameterAnnotations = NULL;
-       a                    = (java_handle_t*)c->method_parameterannotations;
 
-       if (c->method_parameterannotations != NULL && array_length_get(a) > slot) {
-               parameterAnnotations =
-                       (java_handle_bytearray_t*)array_objectarray_element_get(
-                               c->method_parameterannotations, slot);
+       LLNI_classinfo_field_get(
+               c, method_parameterannotations, method_parameterannotations);
+
+       /* the method_annotations array might be shorter then the method
+        * count if the methods above a certain index have no annotations.
+        */     
+       if (method_parameterannotations != NULL &&
+               array_length_get(method_parameterannotations) > slot) {
+               parameterAnnotations = array_objectarray_element_get(
+                               (java_handle_objectarray_t*)method_parameterannotations,
+                               slot);
        }
        
-       return parameterAnnotations;
+       return (java_handle_bytearray_t*)parameterAnnotations;
 #else
        return NULL;
 #endif
@@ -912,26 +920,31 @@ java_handle_bytearray_t *method_get_parameterannotations(methodinfo *m)
 java_handle_bytearray_t *method_get_annotationdefault(methodinfo *m)
 {
 #if defined(ENABLE_ANNOTATIONS)
-       classinfo               *c;                 /* methods' declaring class */
-       int                      slot;              /* methods' slot            */
-       java_handle_bytearray_t *annotationDefault; /* methods' unparsed        */
-                                                   /* annotation default value */
-       java_handle_t           *a;                 /* methods' unparsed        */
-                                                   /* annotation default value */
-                                                   /* cast into java_handle_t* */
+       classinfo     *c;                         /* methods' declaring class     */
+       int            slot;                      /* methods' slot                */
+       java_handle_t *annotationDefault;         /* methods' unparsed            */
+                                                 /* annotation default value     */
+       java_handle_t *method_annotationdefaults; /* all methods' unparsed        */
+                                                 /* annotation default values of */
+                                                 /* the declaring class          */
 
        c                 = m->class;
        slot              = m - c->methods;
        annotationDefault = NULL;
-       a                 = (java_handle_t*)c->method_annotationdefaults;
 
-       if (c->method_annotationdefaults != NULL && array_length_get(a) > slot) {
-               annotationDefault = 
-                       (java_handle_bytearray_t*)array_objectarray_element_get(
-                               c->method_annotationdefaults, slot);
+       LLNI_classinfo_field_get(
+               c, method_annotationdefaults, method_annotationdefaults);
+
+       /* the method_annotations array might be shorter then the method
+        * count if the methods above a certain index have no annotations.
+        */     
+       if (method_annotationdefaults != NULL &&
+               array_length_get(method_annotationdefaults) > slot) {
+               annotationDefault = array_objectarray_element_get(
+                               (java_handle_objectarray_t*)method_annotationdefaults, slot);
        }
        
-       return annotationDefault;
+       return (java_handle_bytearray_t*)annotationDefault;
 #else
        return NULL;
 #endif