[weld-commits] Weld SVN: r6065 - in core/trunk: impl/src/main/java/org/jboss/weld/logging/messages and 6 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Wed Mar 24 17:21:48 EDT 2010


Author: nickarls
Date: 2010-03-24 17:21:46 -0400 (Wed, 24 Mar 2010)
New Revision: 6065

Added:
   core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/
   core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/Instantiator.java
   core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/InstantiatorFactory.java
   core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/ReflectionFactoryInstantiator.java
   core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/UnsafeInstantiator.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/
   core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/Bar.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/Foo.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/ProxyTest.java
Modified:
   core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java
   core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ReflectionMessage.java
   core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java
   core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/SecureReflections.java
   core/trunk/impl/src/main/resources/org/jboss/weld/messages/reflection_en.properties
Log:
WELD-56

Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java	2010-03-23 13:06:14 UTC (rev 6064)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java	2010-03-24 21:21:46 UTC (rev 6065)
@@ -66,6 +66,7 @@
 import org.jboss.weld.persistence.PersistenceApiAbstraction;
 import org.jboss.weld.servlet.ServletApiAbstraction;
 import org.jboss.weld.util.reflection.Reflections;
+import org.jboss.weld.util.reflection.instantiation.InstantiatorFactory;
 import org.jboss.weld.ws.WSApiAbstraction;
 import org.slf4j.cal10n.LocLogger;
 
@@ -302,7 +303,7 @@
              !servletApiAbstraction.SERVLET_REQUEST_LISTENER_CLASS.isAssignableFrom(javaClass) && 
              !ejbApiAbstraction.ENTERPRISE_BEAN_CLASS.isAssignableFrom(javaClass) && 
              !jsfApiAbstraction.UICOMPONENT_CLASS.isAssignableFrom(javaClass) && 
-             hasSimpleWebBeanConstructor(clazz);
+             (hasSimpleWebBeanConstructor(clazz) || InstantiatorFactory.useInstantiators());
    }
    
    protected boolean isEEResourceProducerField(WeldField<?, ?> field)

Modified: core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ReflectionMessage.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ReflectionMessage.java	2010-03-23 13:06:14 UTC (rev 6064)
+++ core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ReflectionMessage.java	2010-03-24 21:21:46 UTC (rev 6065)
@@ -50,6 +50,9 @@
    @MessageId("000612") UNABLE_TO_GET_FIELD_ON_DESERIALIZATION,
    @MessageId("000613") UNABLE_TO_GET_PARAMETER_ON_DESERIALIZATION,
    @MessageId("000614") INCORRECT_NUMBER_OF_ANNOTATED_PARAMETERS_METHOD,
-   @MessageId("000615") INCORRECT_NUMBER_OF_ANNOTATED_PARAMETERS_CONSTRUCTOR;
+   @MessageId("000615") INCORRECT_NUMBER_OF_ANNOTATED_PARAMETERS_CONSTRUCTOR,
+   @MessageId("000616") REFLECTIONFACTORY_INSTANTIATION_FAILED,
+   @MessageId("000617") UNSAFE_INSTANTIATION_FAILED,
+   @MessageId("000618") METHODHANDLER_SET_FAILED;
    
 }

Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java	2010-03-23 13:06:14 UTC (rev 6064)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java	2010-03-24 21:21:46 UTC (rev 6065)
@@ -17,6 +17,7 @@
 package org.jboss.weld.util;
 
 import static org.jboss.weld.logging.messages.UtilMessage.CANNOT_PROXY_NON_CLASS_TYPE;
+import static org.jboss.weld.logging.messages.ReflectionMessage.METHODHANDLER_SET_FAILED;
 import static org.jboss.weld.logging.messages.UtilMessage.INSTANCE_NOT_A_PROXY;
 import static org.jboss.weld.logging.messages.ValidatorMessage.NOT_PROXYABLE_ARRAY_TYPE;
 import static org.jboss.weld.logging.messages.ValidatorMessage.NOT_PROXYABLE_FINAL_TYPE_OR_METHOD;
@@ -43,8 +44,10 @@
 
 import org.jboss.weld.exceptions.ForbiddenArgumentException;
 import org.jboss.weld.exceptions.UnproxyableResolutionException;
+import org.jboss.weld.exceptions.WeldException;
 import org.jboss.weld.util.reflection.Reflections;
 import org.jboss.weld.util.reflection.SecureReflections;
+import org.jboss.weld.util.reflection.instantiation.InstantiatorFactory;
 
 /**
  * Utilties for working with Javassist proxies
@@ -55,17 +58,18 @@
  */
 public class Proxies
 {
-   
+
    private static class IgnoreFinalizeMethodFilter implements MethodFilter, Serializable
    {
+      private static final long serialVersionUID = 1L;
 
       public boolean isHandled(Method m)
       {
          return !m.getName().equals("finalize");
       }
-      
+
    }
-   
+
    public static class TypeInfo
    {
 
@@ -109,10 +113,10 @@
       public ProxyFactory createProxyFactory()
       {
          ProxyFactory proxyFactory = new ProxyFactory();
-         ProxyFactory.useCache = false;         
+         ProxyFactory.useCache = false;
          proxyFactory.setFilter(new IgnoreFinalizeMethodFilter());
          Class<?> superClass = getSuperClass();
-         if(superClass != null && superClass != Object.class)
+         if (superClass != null && superClass != Object.class)
          {
             proxyFactory.setSuperclass(superClass);
          }
@@ -136,7 +140,7 @@
          }
          else if (type instanceof ParameterizedType)
          {
-            add(((ParameterizedType)type).getRawType());
+            add(((ParameterizedType) type).getRawType());
          }
          else
          {
@@ -154,16 +158,14 @@
          }
          return typeInfo;
       }
-      
+
       public static TypeInfo create()
       {
          return new TypeInfo();
       }
 
    }
-   
-   private static final String DEFAULT_INTERCEPTOR = "default_interceptor";
-   
+
    /**
     * Create a proxy with a handler, registering the proxy for cleanup
     * 
@@ -176,9 +178,32 @@
     */
    public static <T> T createProxy(MethodHandler methodHandler, TypeInfo typeInfo) throws IllegalAccessException, InstantiationException
    {
-      return SecureReflections.newInstance(Proxies.<T>createProxyClass(methodHandler, typeInfo));
+      if (InstantiatorFactory.useInstantiators())
+      {
+         Class<T> proxyClass = Proxies.<T> createProxyClass(methodHandler, typeInfo);
+         T instance = SecureReflections.newUnsafeInstance(proxyClass);
+         setMethodHandler(proxyClass, instance, methodHandler);
+         return instance;
+      }
+      else
+      {
+         return SecureReflections.newInstance(Proxies.<T> createProxyClass(methodHandler, typeInfo));
+      }
    }
-   
+
+   private static <T> void setMethodHandler(Class<T> clazz, T instance, MethodHandler methodHandler)
+   {
+      try
+      {
+         Method setter = SecureReflections.getDeclaredMethod(clazz, "setHandler", MethodHandler.class);
+         SecureReflections.invoke(instance, setter, methodHandler);
+      }
+      catch (Exception e)
+      {
+         throw new WeldException(METHODHANDLER_SET_FAILED, e, clazz);
+      }
+   }
+
    /**
     * Create a proxy class
     * 
@@ -192,7 +217,7 @@
    {
       return createProxyClass(null, typeInfo);
    }
-   
+
    /**
     * Create a proxy class
     * 
@@ -207,7 +232,7 @@
    {
       ProxyFactory proxyFactory = typeInfo.createProxyFactory();
       attachMethodHandler(proxyFactory, methodHandler);
-      
+
       @SuppressWarnings("unchecked")
       Class<T> clazz = proxyFactory.createClass();
       return clazz;
@@ -223,7 +248,7 @@
    {
       return getUnproxyableTypeException(type) == null;
    }
-   
+
    public static UnproxyableResolutionException getUnproxyableTypeException(Type type)
    {
       if (type instanceof Class<?>)
@@ -240,7 +265,6 @@
       }
       return new UnproxyableResolutionException(NOT_PROXYABLE_UNKNOWN, type);
    }
-   
 
    /**
     * Indicates if a set of types are all proxyable
@@ -269,51 +293,55 @@
       }
       return null;
    }
-   
+
    private static UnproxyableResolutionException getUnproxyableClassException(Class<?> clazz)
    {
       if (clazz.isInterface())
       {
          return null;
       }
-      else
+      Constructor<?> constructor = null;
+      try
       {
-         Constructor<?> constructor = null;
-         try
+         constructor = SecureReflections.getDeclaredConstructor(clazz);
+      }
+      catch (NoSuchMethodException e)
+      {
+         if (!InstantiatorFactory.useInstantiators())
          {
-            constructor = SecureReflections.getDeclaredConstructor(clazz);
-         }
-         catch (NoSuchMethodException e)
-         {
             return new UnproxyableResolutionException(NOT_PROXYABLE_NO_CONSTRUCTOR, clazz);
          }
-         if (constructor == null)
-         {
-            return new UnproxyableResolutionException(NOT_PROXYABLE_NO_CONSTRUCTOR, clazz);
-         }
-         else if (Modifier.isPrivate(constructor.getModifiers()))
-         {
-            return new UnproxyableResolutionException(NOT_PROXYABLE_PRIVATE_CONSTRUCTOR, clazz, constructor);
-         }
-         else if (Reflections.isTypeOrAnyMethodFinal(clazz))
-         {
-            return new UnproxyableResolutionException(NOT_PROXYABLE_FINAL_TYPE_OR_METHOD, clazz, Reflections.getFinalMethodOrType(clazz));
-         }
-         else if (clazz.isPrimitive())
-         {
-            return new UnproxyableResolutionException(NOT_PROXYABLE_PRIMITIVE, clazz);
-         }
-         else if (Reflections.isArrayType(clazz))
-         {
-            return new UnproxyableResolutionException(NOT_PROXYABLE_ARRAY_TYPE, clazz);
-         }
          else
          {
             return null;
          }
       }
+      if (constructor == null)
+      {
+         return new UnproxyableResolutionException(NOT_PROXYABLE_NO_CONSTRUCTOR, clazz);
+      }
+      else if (Modifier.isPrivate(constructor.getModifiers()))
+      {
+         return new UnproxyableResolutionException(NOT_PROXYABLE_PRIVATE_CONSTRUCTOR, clazz, constructor);
+      }
+      else if (Reflections.isTypeOrAnyMethodFinal(clazz))
+      {
+         return new UnproxyableResolutionException(NOT_PROXYABLE_FINAL_TYPE_OR_METHOD, clazz, Reflections.getFinalMethodOrType(clazz));
+      }
+      else if (clazz.isPrimitive())
+      {
+         return new UnproxyableResolutionException(NOT_PROXYABLE_PRIMITIVE, clazz);
+      }
+      else if (Reflections.isArrayType(clazz))
+      {
+         return new UnproxyableResolutionException(NOT_PROXYABLE_ARRAY_TYPE, clazz);
+      }
+      else
+      {
+         return null;
+      }
    }
-   
+
    public static ProxyFactory attachMethodHandler(ProxyFactory proxyFactory, MethodHandler methodHandler)
    {
       if (methodHandler != null)
@@ -322,7 +350,7 @@
       }
       return proxyFactory;
    }
-   
+
    public static <T> T attachMethodHandler(T instance, MethodHandler methodHandler)
    {
       if (instance instanceof ProxyObject)
@@ -337,8 +365,7 @@
       {
          throw new ForbiddenArgumentException(INSTANCE_NOT_A_PROXY, instance);
       }
-      
+
    }
 
-
 }

Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/SecureReflections.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/SecureReflections.java	2010-03-23 13:06:14 UTC (rev 6064)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/SecureReflections.java	2010-03-24 21:21:46 UTC (rev 6065)
@@ -26,6 +26,7 @@
 import java.lang.reflect.Method;
 
 import org.jboss.weld.exceptions.DeploymentException;
+import org.jboss.weld.util.reflection.instantiation.InstantiatorFactory;
 
 /**
  * 
@@ -398,6 +399,29 @@
    }
 
    /**
+    * Creates a new instance of a class using unportable methods, if available
+    * 
+    * @param <T> The type of the instance
+    * @param clazz The class to construct from
+    * @return The new instance
+    * @throws InstantiationException If the instance could not be create
+    * @throws IllegalAccessException If there was an illegal access attempt
+    * @see java.lang.Class#newInstance()
+    */
+   @SuppressWarnings("unchecked")
+   public static <T> T newUnsafeInstance(final Class<T> clazz) throws InstantiationException, IllegalAccessException
+   {
+      return (T) new SecureReflectionAccess()
+      {
+         @Override
+         protected Object work() throws Exception
+         {
+            return InstantiatorFactory.getInstantiator().instantiate(clazz);
+         }
+      }.runAsInstantiation();
+   }
+
+   /**
     * Looks up a method in an inheritance hierarchy
     * 
     * @param instance The instance (class) to start from

Added: core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/Instantiator.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/Instantiator.java	                        (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/Instantiator.java	2010-03-24 21:21:46 UTC (rev 6065)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.util.reflection.instantiation;
+
+/**
+ * An interface for instantiating classes using non-portable reflection methods
+ * 
+ * @author Nicklas Karlsson
+ *
+ */
+public interface Instantiator
+{
+   /**
+    * Create a new instance of a class
+    * @param <T> The type of the class
+    * @param clazz The class
+    * @return The created instance 
+    */
+   public abstract <T> T instantiate(Class<T> clazz);
+   
+   /**
+    * Used for checking if this particular instantiation method is available in the environment
+    * 
+    * @return True if available, false otherwise
+    */
+   public abstract boolean isAvailable();
+}

Added: core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/InstantiatorFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/InstantiatorFactory.java	                        (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/InstantiatorFactory.java	2010-03-24 21:21:46 UTC (rev 6065)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.util.reflection.instantiation;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.weld.bootstrap.api.Service;
+
+/**
+ * A factory class for obtaining the first available instantiator
+ * 
+ * @author Nicklas Karlsson
+ * 
+ */
+ at SuppressWarnings("serial")
+public class InstantiatorFactory implements Service
+{
+   private static Instantiator availableInstantiator;
+
+   private static final List<Instantiator> instantiators = new ArrayList<Instantiator>()
+   {
+      {
+         add(new UnsafeInstantiator());
+         add(new ReflectionFactoryInstantiator());
+      }
+   };
+
+   static
+   {
+      for (Instantiator instantiator : instantiators)
+      {
+         if (instantiator.isAvailable())
+         {
+            availableInstantiator = instantiator;
+            break;
+         }
+      }
+   }
+
+   public static Instantiator getInstantiator()
+   {
+      return availableInstantiator;
+   }
+   
+   public static boolean useInstantiators() 
+   {
+      return "true".equals(System.getProperty("org.jboss.weld.instantiators"));
+   }
+
+   public void cleanup()
+   {
+      instantiators.clear();
+   }
+}

Added: core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/ReflectionFactoryInstantiator.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/ReflectionFactoryInstantiator.java	                        (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/ReflectionFactoryInstantiator.java	2010-03-24 21:21:46 UTC (rev 6065)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.util.reflection.instantiation;
+
+import java.lang.reflect.Constructor;
+import static org.jboss.weld.logging.messages.ReflectionMessage.REFLECTIONFACTORY_INSTANTIATION_FAILED;
+import java.lang.reflect.Method;
+
+import org.jboss.weld.exceptions.WeldException;
+
+/**
+ * A instantiator for sun.reflect.ReflectionFactory
+ * 
+ * @author Nicklas Karlsson
+ *
+ */
+public class ReflectionFactoryInstantiator implements Instantiator
+{
+   private static final String REFLECTION_CLASS_NAME = "sun.reflect.ReflectionFactory";
+
+   private Method generator = null;
+   private Object reflectionFactoryInstance = null;
+
+   public ReflectionFactoryInstantiator()
+   {
+      try
+      {
+         Class<?> reflectionFactory = Class.forName(REFLECTION_CLASS_NAME);
+         Method accessor = reflectionFactory.getMethod("getReflectionFactory");
+         reflectionFactoryInstance = accessor.invoke(null);
+         generator = reflectionFactory.getMethod("newConstructorForSerialization", new Class[] { Class.class, Constructor.class });
+      }
+      catch (Exception e)
+      {
+         // OK to fail
+      }
+   }
+
+   @SuppressWarnings("unchecked")
+   public <T> T instantiate(Class<T> clazz)
+   {
+      T instance = null;
+      try
+      {
+         Constructor<T> instanceConstructor = (Constructor<T>) generator.invoke(reflectionFactoryInstance, new Object[] { clazz, Object.class.getDeclaredConstructor() });
+         instance = instanceConstructor.newInstance();
+      }
+      catch (Exception e)
+      {
+         throw new WeldException(REFLECTIONFACTORY_INSTANTIATION_FAILED, e, clazz);
+      }
+      return instance;
+   }
+
+   public boolean isAvailable()
+   {
+      return generator != null && reflectionFactoryInstance != null;
+   }
+
+}

Added: core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/UnsafeInstantiator.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/UnsafeInstantiator.java	                        (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/UnsafeInstantiator.java	2010-03-24 21:21:46 UTC (rev 6065)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.util.reflection.instantiation;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.jboss.weld.exceptions.WeldException;
+
+import static org.jboss.weld.logging.messages.ReflectionMessage.UNSAFE_INSTANTIATION_FAILED;
+
+
+/**
+ * An instantiator for sun.misc.Unsafe
+ * 
+ * @author Nicklas Karlsson
+ *
+ */
+public class UnsafeInstantiator implements Instantiator
+{
+   private static final String REFLECTION_CLASS_NAME = "sun.misc.Unsafe";
+
+   private Method allocateInstanceMethod = null;
+   private Object unsafeInstance = null;
+
+   public UnsafeInstantiator()
+   {
+      try
+      {
+         Class<?> unsafe = Class.forName(REFLECTION_CLASS_NAME);
+         Field accessor = unsafe.getDeclaredField("theUnsafe");
+         accessor.setAccessible(true);
+         unsafeInstance = accessor.get(null);
+         allocateInstanceMethod = unsafe.getDeclaredMethod("allocateInstance", Class.class);
+      }
+      catch (Exception e)
+      {
+         // OK to fail
+      }
+   }
+
+   @SuppressWarnings("unchecked")
+   public <T> T instantiate(Class<T> clazz)
+   {
+      T instance = null;
+      try
+      {
+         instance = (T) allocateInstanceMethod.invoke(unsafeInstance, clazz);
+      }
+      catch (Exception e)
+      {
+         throw new WeldException(UNSAFE_INSTANTIATION_FAILED, e, clazz);
+      }
+      return instance;
+   }
+
+   public boolean isAvailable()
+   {
+      return allocateInstanceMethod != null && unsafeInstance != null;
+   }
+
+}
\ No newline at end of file

Modified: core/trunk/impl/src/main/resources/org/jboss/weld/messages/reflection_en.properties
===================================================================
--- core/trunk/impl/src/main/resources/org/jboss/weld/messages/reflection_en.properties	2010-03-23 13:06:14 UTC (rev 6064)
+++ core/trunk/impl/src/main/resources/org/jboss/weld/messages/reflection_en.properties	2010-03-24 21:21:46 UTC (rev 6065)
@@ -13,4 +13,7 @@
 UNABLE_TO_GET_METHOD_ON_DESERIALIZATION=Unable to deserialize method. Declaring bean id {0}, declaring class {1}, signature {2}
 UNABLE_TO_GET_PARAMETER_ON_DESERIALIZATION=Unable to deserialize paramter. Declaring bean id {0}, declaring class {1}, parameter {3} of method with signature {2}
 INCORRECT_NUMBER_OF_ANNOTATED_PARAMETERS_METHOD=Incorrect number of AnnotatedParameters {0} on AnnotatedMethod {1}. AnnotatedMethod has {2} as parameters but should have {3} as parameters
-INCORRECT_NUMBER_OF_ANNOTATED_PARAMETERS_CONSTRUCTOR=Incorrect number of AnnotatedParameters {0} on AnnotatedConstructor {1}. AnnotatedConstructor has {2} as parameters but should have {3} as parameters
\ No newline at end of file
+INCORRECT_NUMBER_OF_ANNOTATED_PARAMETERS_CONSTRUCTOR=Incorrect number of AnnotatedParameters {0} on AnnotatedConstructor {1}. AnnotatedConstructor has {2} as parameters but should have {3} as parameters
+REFLECTIONFACTORY_INSTANTIATION_FAILED=Instantiation through ReflectionFactory of {0} failed
+UNSAFE_INSTANTIATION_FAILED=Instantiation through Unsafe of {0} failed
+METHODHANDLER_SET_FAILED=Could not set MethodHandler on {0}
\ No newline at end of file

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/Bar.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/Bar.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/Bar.java	2010-03-24 21:21:46 UTC (rev 6065)
@@ -0,0 +1,8 @@
+package org.jboss.weld.tests.proxy.weld56;
+
+import javax.enterprise.context.RequestScoped;
+
+ at RequestScoped
+public class Bar
+{
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/Foo.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/Foo.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/Foo.java	2010-03-24 21:21:46 UTC (rev 6065)
@@ -0,0 +1,20 @@
+package org.jboss.weld.tests.proxy.weld56;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+
+
+ at RequestScoped
+public class Foo
+{
+
+   @Inject
+   public Foo(Bar bar)
+   {
+   }
+
+   public String ping()
+   {
+      return "ping";
+   }
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/ProxyTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/ProxyTest.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/ProxyTest.java	2010-03-24 21:21:46 UTC (rev 6065)
@@ -0,0 +1,16 @@
+package org.jboss.weld.tests.proxy.weld56;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+
+ at Artifact
+public class ProxyTest extends AbstractWeldTest
+{
+
+   @Test(groups="broken")
+   public void testProxy()
+   {
+      assert "ping".equals(getReference(Foo.class).ping());
+   }
+}



More information about the weld-commits mailing list