[ 
https://issues.apache.org/jira/browse/AXIS2-5481?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Sagara Gunathunga  resolved AXIS2-5481.
---------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.6.3
                   1.7.0

Provided patch available on r1441907and thanks for your contribution.  
                
> 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
>             Fix For: 1.7.0, 1.6.3
>
>         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(<enum?>, 
> 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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to