Author: pete.muir(a)jboss.org
Date: 2009-07-28 15:32:32 -0400 (Tue, 28 Jul 2009)
New Revision: 3318
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBClassImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBConstructorImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBFieldImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBMethodImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java
Log:
WBRI-292
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBClassImpl.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBClassImpl.java 2009-07-28
17:50:13 UTC (rev 3317)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBClassImpl.java 2009-07-28
19:32:32 UTC (rev 3318)
@@ -175,7 +175,7 @@
{
field.setAccessible(true);
}
- WBField<?> annotatedField = new WBFieldImpl<Object>(field, this,
classTransformer);
+ WBField<?> annotatedField = WBFieldImpl.of(field, this,
classTransformer);
this.fields.add(annotatedField);
if (c == rawType)
{
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBConstructorImpl.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBConstructorImpl.java 2009-07-28
17:50:13 UTC (rev 3317)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBConstructorImpl.java 2009-07-28
19:32:32 UTC (rev 3318)
@@ -16,6 +16,8 @@
*/
package org.jboss.webbeans.introspector.jlr;
+import static org.jboss.webbeans.util.Reflections.ensureAccessible;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -69,7 +71,7 @@
public static <T> WBConstructor<T> of(Constructor<T> constructor,
WBType<T> declaringClass, ClassTransformer classTransformer)
{
- return new WBConstructorImpl<T>(constructor, declaringClass,
classTransformer);
+ return new WBConstructorImpl<T>(ensureAccessible(constructor),
declaringClass, classTransformer);
}
/**
@@ -80,7 +82,7 @@
* @param constructor The constructor method
* @param declaringClass The declaring class
*/
- protected WBConstructorImpl(Constructor<T> constructor, WBType<T>
declaringClass, ClassTransformer classTransformer)
+ private WBConstructorImpl(Constructor<T> constructor, WBType<T>
declaringClass, ClassTransformer classTransformer)
{
super(AnnotationStore.of(constructor, classTransformer.getTypeStore()),
constructor, constructor.getDeclaringClass(), constructor.getDeclaringClass());
this.constructor = constructor;
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBFieldImpl.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBFieldImpl.java 2009-07-28
17:50:13 UTC (rev 3317)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBFieldImpl.java 2009-07-28
19:32:32 UTC (rev 3318)
@@ -16,6 +16,8 @@
*/
package org.jboss.webbeans.introspector.jlr;
+import static org.jboss.webbeans.util.Reflections.ensureAccessible;
+
import java.lang.reflect.Field;
import org.jboss.webbeans.introspector.AnnotationStore;
@@ -45,6 +47,11 @@
// Cached string representation
private String toString;
+ public static <T> WBFieldImpl<T> of(Field field, WBType<?>
declaringClass, ClassTransformer classTransformer)
+ {
+ return new WBFieldImpl<T>(ensureAccessible(field), declaringClass,
classTransformer);
+ }
+
/**
* Constructor
*
@@ -54,11 +61,10 @@
* @param field The actual field
* @param declaringClass The abstraction of the declaring class
*/
- protected WBFieldImpl(Field field, WBType<?> declaringClass, ClassTransformer
classTransformer)
+ private WBFieldImpl(Field field, WBType<?> declaringClass, ClassTransformer
classTransformer)
{
super(AnnotationStore.of(field, classTransformer.getTypeStore()), field,
(Class<T>) field.getType(), field.getGenericType());
this.field = field;
- field.setAccessible(true);
this.declaringClass = declaringClass;
}
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBMethodImpl.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBMethodImpl.java 2009-07-28
17:50:13 UTC (rev 3317)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/WBMethodImpl.java 2009-07-28
19:32:32 UTC (rev 3318)
@@ -16,6 +16,8 @@
*/
package org.jboss.webbeans.introspector.jlr;
+import static org.jboss.webbeans.util.Reflections.ensureAccessible;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -74,7 +76,7 @@
public static <T> WBMethodImpl<T> of(Method method, WBType<?>
declaringClass, ClassTransformer classTransformer)
{
- return new WBMethodImpl<T>(method, declaringClass, classTransformer);
+ return new WBMethodImpl<T>(ensureAccessible(method), declaringClass,
classTransformer);
}
/**
@@ -87,11 +89,10 @@
* @param declaringClass The declaring class abstraction
*/
@SuppressWarnings("unchecked")
- protected WBMethodImpl(Method method, WBType<?> declaringClass, ClassTransformer
classTransformer)
+ private WBMethodImpl(Method method, WBType<?> declaringClass, ClassTransformer
classTransformer)
{
super(AnnotationStore.of(method, classTransformer.getTypeStore()), method,
(Class<T>) method.getReturnType(), method.getGenericReturnType());
this.method = method;
- this.method.setAccessible(true);
this.declaringClass = declaringClass;
this.parameters = new ArrayList<WBParameter<?>>();
this.annotatedParameters = Multimaps.newListMultimap(new HashMap<Class<?
extends Annotation>, Collection<WBParameter<?>>>(), new Supplier<
List<WBParameter<?>>>()
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java 2009-07-28
17:50:13 UTC (rev 3317)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java 2009-07-28
19:32:32 UTC (rev 3318)
@@ -686,5 +686,32 @@
{
return clazz.isPrimitive() || Serializable.class.isAssignableFrom(clazz);
}
+
+ public static Field ensureAccessible(Field field)
+ {
+ if (!field.isAccessible() &&
!field.getDeclaringClass().getPackage().getName().startsWith("java.util"))
+ {
+ field.setAccessible(true);
+ }
+ return field;
+ }
+
+ public static Method ensureAccessible(Method method)
+ {
+ if (!method.isAccessible() &&
!method.getDeclaringClass().getPackage().getName().startsWith("java.util"))
+ {
+ method.setAccessible(true);
+ }
+ return method;
+ }
+
+ public static <T> Constructor<T> ensureAccessible(Constructor<T>
constructor)
+ {
+ if (!constructor.isAccessible() &&
!constructor.getDeclaringClass().getPackage().getName().startsWith("java.util"))
+ {
+ constructor.setAccessible(true);
+ }
+ return constructor;
+ }
}