harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r595635 - in /harmony/enhanced/drlvm/trunk/vm: tests/kernel/org/apache/harmony/lang/AnnotatedElementTestFrame.java vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMGenericsAndAnnotations.cpp vmcore/src/reflection/annotations.cpp
Date Fri, 16 Nov 2007 11:58:21 GMT
Author: varlax
Date: Fri Nov 16 03:58:16 2007
New Revision: 595635

URL: http://svn.apache.org/viewvc?rev=595635&view=rev
Log:
Fixed HARMONY-5086 [drlvm][geronimo] AnnotatedElement.getDeclaredAnnotations() throws exception
if annotation is not available

Modified:
    harmony/enhanced/drlvm/trunk/vm/tests/kernel/org/apache/harmony/lang/AnnotatedElementTestFrame.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMGenericsAndAnnotations.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/reflection/annotations.cpp

Modified: harmony/enhanced/drlvm/trunk/vm/tests/kernel/org/apache/harmony/lang/AnnotatedElementTestFrame.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/kernel/org/apache/harmony/lang/AnnotatedElementTestFrame.java?rev=595635&r1=595634&r2=595635&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/kernel/org/apache/harmony/lang/AnnotatedElementTestFrame.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/kernel/org/apache/harmony/lang/AnnotatedElementTestFrame.java
Fri Nov 16 03:58:16 2007
@@ -243,17 +243,13 @@
     }
     
     /**
-     * getAnnotations() should throw TypeNotPresentException
-     * for the element4.
+     * getAnnotations() should skip unresolved annotation
+     * thus should return empty array for the element4.
      */
     public void testGetAnnotations4() throws Throwable {
-        try {
-            getElement4().getAnnotations();
-            fail("Misconfigured test");
-        } catch (TypeNotPresentException tnpe) {
-            assertTrue("reported type name: " + tnpe.typeName(), 
-                    tnpe.typeName().matches("notfound.MissingAntn"));
-        }
+        Annotation[] an = getElement4().getAnnotations();
+        assertNotNull(an);
+        assertEquals(0, an.length);
     }
     
     /**

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMGenericsAndAnnotations.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMGenericsAndAnnotations.cpp?rev=595635&r1=595634&r2=595635&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMGenericsAndAnnotations.cpp
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMGenericsAndAnnotations.cpp
Fri Nov 16 03:58:16 2007
@@ -124,6 +124,9 @@
         return NULL;
     }
 
+    // According to J2SE specification the 0-length array must be added for
+    // the parameter w/o annotation (still this no-annotation-parameter is not
+    // skipped from the resulted array).
     unsigned i;
     for (i = 0; i < param_num; ++i) {
         jobject element = get_annotations(jenv,
@@ -162,6 +165,7 @@
     if (value) {
         Class* antn_class = method->get_class();
         jthrowable error = NULL;
+        // FIXME need to clarify against JSR-175 spec which exception should be raised
         jobject jval = resolve_annotation_value(jenv, *value, antn_class, 
             method->get_name(), &error);
         if (!jval && error) {

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/reflection/annotations.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/reflection/annotations.cpp?rev=595635&r1=595634&r2=595635&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/reflection/annotations.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/reflection/annotations.cpp Fri Nov 16 03:58:16
2007
@@ -46,42 +46,60 @@
 
     unsigned num = table_num + inv_table_num;
 
+    // HARMONY-5086 resolution - because there can be annotations which can't
+    // be resolved (and must be just ignored) the size of result array is
+    // unknown actually, so temporary location is used.
+    jobject* tmp_array = (jobject*) malloc(sizeof(jobject) * num);
+    unsigned result_array_size = 0;
+    jobjectArray result_array = NULL;
+
+    jthrowable skip = NULL;
+    for (unsigned i = 0; i < table_num; i++) {
+        jobject element = resolve_annotation(jenv, table->table[i], clss, &skip);
+        if (exn_raised()) {
+            assert(!element);
+            goto bail;
+        } else if (!element) { 
+            // just skip unresolved annotation
+            continue;
+        }
+        tmp_array[result_array_size++] = element;
+    }
+    for (unsigned i = 0; i < inv_table_num; i++) {
+        jobject element = resolve_annotation(jenv, inv_table->table[i], clss, &skip);
+        if (exn_raised()) {
+            assert(!element);
+            goto bail;
+        } else if (!element) { 
+            // just skip unresolved annotation
+            continue;
+        }
+        tmp_array[result_array_size++] = element;
+   }
+
+    // copy resolved annotations to result java array
     static Class* antn_class;
-    if(antn_class == NULL) {
+
+    if (antn_class == NULL) {
         antn_class = jni_get_vm_env(jenv)->LoadCoreClass(
             "java/lang/annotation/Annotation");
     }
-
-    jobjectArray array = NewObjectArray(jenv, num, 
+    result_array = NewObjectArray(jenv, result_array_size, 
         struct_Class_to_java_lang_Class_Handle(antn_class), NULL);
 
-    if (!array) {
+    if (!result_array) {
         assert(exn_raised());
-        return NULL;
+        goto bail;
     }
 
-    unsigned i;
-    for (i = 0; i < table_num; ++i) {
-        jobject element = resolve_annotation(jenv, table->table[i], clss);
-        if (!element) {
-            assert(exn_raised());
-            return NULL;
-        } else {
-            SetObjectArrayElement(jenv, array, i, element);
-            assert(!exn_raised());
-        }
-    }
-    for (i = table_num; i < num; ++i) {
-        jobject element = resolve_annotation(jenv, inv_table->table[i - table_num], clss);
-        if (!element) {
-            assert(exn_raised());
-            return NULL;
-        } else {
-            SetObjectArrayElement(jenv, array, i, element);
-            assert(!exn_raised());
-        }
+    for (unsigned i = 0; i < result_array_size; i++) {
+        SetObjectArrayElement(jenv, result_array, i, tmp_array[i]);
+        assert(!exn_raised());
     }
-    return array;
+    
+bail:
+    free(tmp_array);
+    return result_array;
 }
 
 static Class* field_descriptor_to_type(JNIEnv* jenv, String* desc, Class* clss, 
@@ -124,8 +142,7 @@
 jobject resolve_annotation(JNIEnv* jenv, Annotation* antn, Class* clss, jthrowable* cause)
 {
     assert(antn);
-    // fail immediately if no annotation type found
-    Class* antn_type = field_descriptor_to_type(jenv, antn->type, clss);
+    Class* antn_type = field_descriptor_to_type(jenv, antn->type, clss, cause);
     if (!antn_type) {
         return NULL;
     }
@@ -192,6 +209,7 @@
     TRACE("resolving enum type of annotation value : " << value.enum_const.type->bytes);
 
     // fail immediately if no enum type found
+    // FIXME this behaviour should be evaluated against JSR-175 spec
     Class* enum_type = field_descriptor_to_type(jenv, value.enum_const.type, clss);
     if (enum_type) {
         if (class_is_enum(enum_type)) {
@@ -296,6 +314,8 @@
             ss << "Encountered value tag \'" << (char)value.tag 
                 << "\' does not match array type " << type->get_name()->bytes
<< "[]";
 
+            // FIXME should it be AnnotationFormatError??
+            // need to check with JSR-175 spec
             *cause = CreateNewThrowable(jenv, genv->java_lang_ArrayStoreException_Class,

                 ss.str().c_str(), NULL);
         }



Mime
View raw message