Expose annotations on statically compiled code as java.lang.reflect.Proxy instead of the custom attribute object, to deal with broken code that assumes annotations are always implemented with Proxy.

Fix for #3254823.
This commit is contained in:
jfrijters 2011-03-29 12:57:48 +00:00
Родитель 20c2b1c206
Коммит 4337d62994
2 изменённых файлов: 26 добавлений и 12 удалений

Просмотреть файл

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2005, 2006, 2007 Jeroen Frijters Copyright (C) 2005-2011 Jeroen Frijters
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@ -219,15 +219,13 @@ public abstract class AnnotationAttributeBase
} }
@ikvm.lang.Internal @ikvm.lang.Internal
public static void freeze(Object ann) public Map getValues()
{ {
if(ann instanceof AnnotationAttributeBase) return values;
{
((AnnotationAttributeBase)ann).freeze();
}
} }
private synchronized void freeze() @ikvm.lang.Internal
public synchronized void freeze()
{ {
if(!frozen) if(!frozen)
{ {

Просмотреть файл

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2007, 2008, 2010 Jeroen Frijters Copyright (C) 2007-2011 Jeroen Frijters
Copyright (C) 2009 Volker Berlin (i-net software) Copyright (C) 2009 Volker Berlin (i-net software)
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
@ -2707,8 +2707,7 @@ namespace IKVM.NativeCode.java
Annotation a = obj as Annotation; Annotation a = obj as Annotation;
if (a != null) if (a != null)
{ {
global::ikvm.@internal.AnnotationAttributeBase.freeze(a); map.put(a.annotationType(), FreezeOrWrapAttribute(a));
map.put(a.annotationType(), a);
} }
} }
} }
@ -2716,6 +2715,24 @@ namespace IKVM.NativeCode.java
#endif #endif
} }
#if !FIRST_PASS
internal static Annotation FreezeOrWrapAttribute(Annotation ann)
{
global::ikvm.@internal.AnnotationAttributeBase attr = ann as global::ikvm.@internal.AnnotationAttributeBase;
if (attr != null)
{
#if DONT_WRAP_ANNOTATION_ATTRIBUTES
attr.freeze();
#else
// freeze to make sure the defaults are set
attr.freeze();
ann = global::sun.reflect.annotation.AnnotationParser.annotationForMap(attr.annotationType(), attr.getValues());
#endif
}
return ann;
}
#endif
public static object getDeclaredAnnotationsImpl(jlClass thisClass) public static object getDeclaredAnnotationsImpl(jlClass thisClass)
{ {
#if FIRST_PASS #if FIRST_PASS
@ -3566,8 +3583,7 @@ namespace IKVM.NativeCode.java
Annotation a = obj as Annotation; Annotation a = obj as Annotation;
if (a != null) if (a != null)
{ {
global::ikvm.@internal.AnnotationAttributeBase.freeze(a); list.Add(Class.FreezeOrWrapAttribute(a));
list.Add(a);
} }
} }
ann[i] = list.ToArray(); ann[i] = list.ToArray();