-
1. Re: Handling of null native values
alesj Nov 21, 2008 12:06 PM (in response to starksm64)"scott.stark@jboss.org" wrote:
a native valued property
You mean primitive?"scott.stark@jboss.org" wrote:
Is this something that the PropertyInfo implementation should be handling, or should this have been handled when the null MetaValue was unwrapped?
I think it could be either one of them.
But perhaps better if we put it into SimpleMetaData/Type,
since we know there what is primitive and what not. -
2. Re: Handling of null native values
starksm64 Nov 21, 2008 12:16 PM (in response to starksm64)Yes, its a primitive. It looks like we also know whether the value is a primitive at the TypeInfo layer of reflection, so that is why I'm asking whether this applies to non-managed uses like injecting a null value into a primitive bean property. Maybe that already works but is handled at the a layer above the PropertyInfo.set call?
-
3. Re: Handling of null native values
alesj Nov 21, 2008 2:51 PM (in response to starksm64)"scott.stark@jboss.org" wrote:
Maybe that already works but is handled at the a layer above the PropertyInfo.set call?
I don't think we do anything about this.
The only thing I remember is that we suppress this exceptions
when nullifying beans on uninstall/unconfigure. -
4. Re: Handling of null native values
starksm64 Nov 21, 2008 4:13 PM (in response to starksm64)Ok, well I'll add handling of this in the jboss managed layer for now since this is where its showing up and we have a release to do anyway.
https://jira.jboss.org/jira/browse/JBMAN-42 -
5. Re: Handling of null native values
alesj Nov 21, 2008 4:26 PM (in response to starksm64)I'll check how much work is there to add this to jboss reflect.
It should be MethodInfo::invoke and PropertyInfo::set that should probably have this logic.
But does setting null on a primitive really always means
you want default value or should the user get exception? -
6. Re: Handling of null native values
starksm64 Nov 21, 2008 4:35 PM (in response to starksm64)That's a valid question. In this case I believe it actually is a non-null MetaValue whose underlying value is null, so it really should be mapped to a zero.
-
7. Re: Handling of null native values
alesj Nov 21, 2008 5:56 PM (in response to starksm64)"scott.stark@jboss.org" wrote:
That's a valid question.
Thinking about it some more,
I think it's not the job of PropertyInfo/MethodInfo to recognize primitive type + default value,
they should just do what they are instructed - as it is currently implemented.
It should be the code that's using it, that should know what to do.
In your case it's meta value/type, in kernel's case it's configure action.
I'll check how this behaves in MC-Kernel code. -
8. Re: Handling of null native values
starksm64 Nov 21, 2008 6:26 PM (in response to starksm64)Yes. This is implemented in the metavalue project now.
-
9. Re: Handling of null native values
alesj Nov 21, 2008 6:49 PM (in response to starksm64)"scott.stark@jboss.org" wrote:
This is implemented in the metavalue project now.
I think you are again doing it wrong, as with SimpleMetaValueComparator.
You should add this info to SimpleMetaType.
As you have all the info required in AbstractInstanceClassFactory::setValue.protected void setValue(BeanInfo beanInfo, PropertyInfo propertyInfo, Object object, Object unwrapValue) throws Throwable { TypeInfo type = propertyInfo.getType(); if(unwrapValue == null && type.isPrimitive()) { MetaType metaType = MetaTypeFactory.getInstance().resolve(type); SimpleMetaType smt = SimpleMetaType.class.cast(metaType); unwrapValue = smt.getDefaultValue(); // <-- missing method } propertyInfo.set(object, unwrapValue); }
More OO. -
10. Re: Handling of null native values
starksm64 Nov 21, 2008 6:54 PM (in response to starksm64)SimpleMetaType does not differentiate between a primitive, and non-primitive, so how would I know what the default value for a SimpleMetaType.INTEGER would be for example? For an int its 0, for an Integer its null. We would have to add an isPrimitive notion and allow this to be specified in wrap.
-
11. Re: Handling of null native values
alesj Nov 21, 2008 7:00 PM (in response to starksm64)True.
I'll eventually add this to reflect's PrimitiveInfo.
For now I'll change your n if's to use a map. ;-) -
12. Re: Handling of null native values
starksm64 Nov 21, 2008 7:03 PM (in response to starksm64)Ok.
-
-
14. Re: Handling of null native values
starksm64 Nov 21, 2008 7:16 PM (in response to starksm64)Will do