Return-Path: X-Original-To: apmail-axis-java-dev-archive@www.apache.org Delivered-To: apmail-axis-java-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7B2AAE264 for ; Fri, 1 Feb 2013 08:47:16 +0000 (UTC) Received: (qmail 88879 invoked by uid 500); 1 Feb 2013 08:47:14 -0000 Delivered-To: apmail-axis-java-dev-archive@axis.apache.org Received: (qmail 88604 invoked by uid 500); 1 Feb 2013 08:47:14 -0000 Mailing-List: contact java-dev-help@axis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-dev@axis.apache.org Delivered-To: mailing list java-dev@axis.apache.org Received: (qmail 88565 invoked by uid 99); 1 Feb 2013 08:47:13 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Feb 2013 08:47:13 +0000 Date: Fri, 1 Feb 2013 08:47:13 +0000 (UTC) From: "Philippe Le Berre (JIRA)" To: java-dev@axis.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (AXIS2-5481) DefaultObjectSupplier fails when the provided class is an enum MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/AXIS2-5481?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13568584#comment-13568584 ] Philippe Le Berre commented on AXIS2-5481: ------------------------------------------ If someone is interested, a jar with the proposed fixed is available at http://esis.svn.sourceforge.net/viewvc/esis/main/jars/axis2-1.6.2/lib/axis2-kernel-1.6.2.jar?revision=3837 . > DefaultObjectSupplier fails when the provided class is an enum > -------------------------------------------------------------- > > Key: AXIS2-5481 > URL: https://issues.apache.org/jira/browse/AXIS2-5481 > Project: Axis2 > Issue Type: Bug > Components: kernel > Affects Versions: 1.6.2 > Environment: Mac OS X > Reporter: Philippe Le Berre > Labels: patch > Attachments: patch.diff > > > org.apache.axis2.engine.DefaultObjectSupplier > - public Object getObject(Class clazz) throws AxisFault { > if the clazz parameter is an enum the object supplier fails as it tries to call newInstance on an enum. > There's two way to fix this : > 1/ Simply check that clazz is an enum (clazz.isEnum()) and then throw an exception to indicate that this is not supported. However that would be limitation which can be resolved see next. > 2/ To instanciate an enum one needs to have a value (Enum.valueOf(, value)) however there is no default value for an enum like for instance null. So if we make the assumption - and that's then a specific of Axis2 - that the developer can add a "NULL" value to its enum it can be tried. > ------ Proposed fixed ------ > public Object getObject(Class clazz) throws AxisFault { > try { > Class parent = clazz.getDeclaringClass(); > Object instance = null; > if (parent != null && !Modifier.isStatic(clazz.getModifiers())) { > // if this is an inner class then that can be a non static inner class. > // those classes have to be instantiated in a different way than a normal initialization. > instance = clazz.getConstructor(new Class[] { parent }) > .newInstance(new Object[] { getObject(parent) }); > //----------------------------------------------------- > } else if (clazz.isEnum()) { > // enum just can create a new instance, so we have to resort > // to a default value, obviously many options are possible. > try { > instance = Enum.valueOf(clazz, "NULL"); > } catch (IllegalArgumentException iae) { > throw AxisFault.makeFault(new Exception("Cannot create an enum object of type ("+clazz.getName()+") without a default value, please add a 'NULL' value to the enum that can be used as default.")); > } > //----------------------------------------------------- > } else { > instance = clazz.newInstance(); > } > return instance; > } catch (Exception e) { > throw AxisFault.makeFault(e); > } > } -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: java-dev-unsubscribe@axis.apache.org For additional commands, e-mail: java-dev-help@axis.apache.org