axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philippe Le Berre (JIRA)" <j...@apache.org>
Subject [jira] [Created] (AXIS2-5481) DefaultObjectSupplier fails when the provided class is an enum
Date Fri, 01 Feb 2013 08:37:12 GMT
Philippe Le Berre created AXIS2-5481:
----------------------------------------

             Summary: 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


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: java-dev-unsubscribe@axis.apache.org
For additional commands, e-mail: java-dev-help@axis.apache.org


Mime
View raw message