Return-Path: X-Original-To: apmail-openwebbeans-commits-archive@www.apache.org Delivered-To: apmail-openwebbeans-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E15AF1075F for ; Fri, 21 Nov 2014 15:53:36 +0000 (UTC) Received: (qmail 22344 invoked by uid 500); 21 Nov 2014 15:53:36 -0000 Delivered-To: apmail-openwebbeans-commits-archive@openwebbeans.apache.org Received: (qmail 22320 invoked by uid 500); 21 Nov 2014 15:53:36 -0000 Mailing-List: contact commits-help@openwebbeans.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openwebbeans.apache.org Delivered-To: mailing list commits@openwebbeans.apache.org Received: (qmail 22309 invoked by uid 99); 21 Nov 2014 15:53:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Nov 2014 15:53:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Nov 2014 15:53:35 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9030723889BB; Fri, 21 Nov 2014 15:52:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1640945 - /openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java Date: Fri, 21 Nov 2014 15:52:14 -0000 To: commits@openwebbeans.apache.org From: struberg@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20141121155214.9030723889BB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: struberg Date: Fri Nov 21 15:52:14 2014 New Revision: 1640945 URL: http://svn.apache.org/r1640945 Log: OWB-1029 fallback from Unsafe to newInstance if not allowed (mainly for GoogleAppEngine) Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java?rev=1640945&r1=1640944&r2=1640945&view=diff ============================================================================== --- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java (original) +++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java Fri Nov 21 15:52:14 2014 @@ -24,9 +24,11 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.logging.Logger; import org.apache.webbeans.config.WebBeansContext; import org.apache.webbeans.exception.WebBeansException; +import org.apache.webbeans.logger.WebBeansLoggerFacade; import org.apache.xbean.asm5.ClassWriter; import org.apache.xbean.asm5.MethodVisitor; import org.apache.xbean.asm5.Opcodes; @@ -47,15 +49,18 @@ public abstract class AbstractProxyFacto public static final int MODIFIER_VARARGS = 0x00000080;; + private static final Logger logger = WebBeansLoggerFacade.getLogger(AbstractProxyFactory.class); + protected WebBeansContext webBeansContext; + /** * contains the instance of sun.misc.Unsafe. * We use it for creating the proxy instance without fully * initializing the class. */ private Object unsafe = null; - private Method unsafeAllocateInstance; + private Method unsafeAllocateInstance = null; /** @@ -542,7 +547,21 @@ public abstract class AbstractProxyFacto { try { - return (T) unsafeAllocateInstance.invoke(unsafe, clazz); + if (unsafeAllocateInstance != null) + { + return (T) unsafeAllocateInstance.invoke(unsafe, clazz); + } + else + { + try + { + return (T) clazz.newInstance(); + } + catch (InstantiationException e) + { + throw new IllegalStateException("Failed to allocateInstance of Proxy class " + clazz.getName(), e); + } + } } catch (IllegalAccessException e) { @@ -603,30 +622,34 @@ public abstract class AbstractProxyFacto } catch (Exception e) { - throw new IllegalStateException("Cannot get sun.misc.Unsafe", e); + logger.warning("ATTENTION: Cannot get sun.misc.Unsafe - will use newInstance() instead! Intended for GAE only!"); + return null; } } }); this.unsafe = unsafe; - unsafeAllocateInstance = AccessController.doPrivileged(new PrivilegedAction() + if (unsafe != null) { - @Override - public Method run() + unsafeAllocateInstance = AccessController.doPrivileged(new PrivilegedAction() { - try - { - Method mtd = unsafeClass.getDeclaredMethod("allocateInstance", Class.class); - mtd.setAccessible(true); - return mtd; - } - catch (Exception e) + @Override + public Method run() { - throw new IllegalStateException("Cannot get sun.misc.Unsafe.allocateInstance", e); + try + { + Method mtd = unsafeClass.getDeclaredMethod("allocateInstance", Class.class); + mtd.setAccessible(true); + return mtd; + } + catch (Exception e) + { + throw new IllegalStateException("Cannot get sun.misc.Unsafe.allocateInstance", e); + } } - } - }); + }); + } } /**