VirtualSatellite4-Core icon indicating copy to clipboard operation
VirtualSatellite4-Core copied to clipboard

Potential NPE in generated Category Beans

Open PhilMFischer opened this issue 5 years ago • 2 comments

As it becomes visible in https://github.com/virtualsatellite/VirtualSatellite4-CEF/issues/99 there is a case where IntPropertiesBeans in CatgeoryBeans may hand back a null as value. Since the Properties hand back the AutoBoxingType which can be null, the Category hands back the primitive type. The cast results in a NullPointerException.

The CodeGenerator for the CatgeoryBean should be adjusted to hand back the AutoBoxingTypes rather than the primitives, e.g.:

				public Long «propertyMethodGet(property)»() {
					«propertyMethodSafeAccess(property)»;
					return «property.name».getValue();
				}
				
				public boolean «propertyMethodIsSet(property)»() {
					«propertyMethodSafeAccess(property)»;
					return «property.name».isSet();
				}

instead of:

				public long «propertyMethodGet(property)»() {
					«propertyMethodSafeAccess(property)»;
					return «property.name».getValue();
				}
				
				public boolean «propertyMethodIsSet(property)»() {
					«propertyMethodSafeAccess(property)»;
					return «property.name».isSet();
				}

But don't change the boolean from the isSet to an AutoBoxingType.

PhilMFischer avatar Mar 31 '20 11:03 PhilMFischer

Shall we also change float properties to return Double null if it's not set insteat of NaN?

andriikovalov-dlr avatar Apr 09 '20 15:04 andriikovalov-dlr

@PhilMFischer Please check ticket.

SaMuellerDLR avatar Jun 11 '20 08:06 SaMuellerDLR