[YANGTOOLS-200] code generator should not generate this.value = null Created: 02/Jul/14  Updated: 10/Apr/22  Due: 18/Jul/14  Resolved: 21/Jul/14

Status: Resolved
Project: yangtools
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Tomas Olvecky Assignee: Martin Vitez
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


External issue ID: 1276

 Description   

org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress

public IpAddress(Ipv4Address _ipv4Address)

{ super(); this._ipv4Address = _ipv4Address; this._ipv6Address = null; this._value = null; }

This constructor is possibly wrong because it returns null on getValue(). If the instance is created using this constructor it cannot be sent over JMX.

Consider this example:
client.setAddress(new IpAddress(new Ipv4Address("127.0.0.1")));
will fail
client.setAddress(new IpAddress("127.0.0.1".toCharArray()));
will succeed (value != null)

Proposed fix: _value should be filled using _ipv4Address.getValue()

Detail:

The failure looks like this:
Caused by: java.io.InvalidObjectException: Exception constructing org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress
at com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.invalidObjectException(DefaultMXBeanMappingFactory.java:1415)
at com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory$CompositeBuilderViaConstructor.fromCompositeData(DefaultMXBeanMappingFactory.java:1335)
at com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory$CompositeMapping.fromNonNullOpenValue(DefaultMXBeanMappingFactory.java:918)
at com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory$NonNullMXBeanMapping.fromOpenValue(DefaultMXBeanMappingFactory.java:132)
at com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory$CompositeBuilderViaSetters.fromCompositeData(DefaultMXBeanMappingFactory.java:1119)
... 48 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory$CompositeBuilderViaConstructor.fromCompositeData(DefaultMXBeanMappingFactory.java:1331)
... 51 more
Caused by: java.lang.NullPointerException
at java.lang.String.<init>(String.java:168)
at org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress.<init>(IpAddress.java:38)
... 56 more



 Comments   
Comment by Maros Marsalek [ 04/Jul/14 ]

In addition, value field is compared in equals method. Equal result depends on which constructor was used for union type. Basic constructors set value to null and Artificial constructor sets the value to input value.

Comment by Tomas Olvecky [ 07/Jul/14 ]

this is a bug in code generator (not enhancement) that forces programmers to use workarounds and document them in their code base, see bgpcep, e.g.
https://github.com/opendaylight/bgpcep/blob/master/bgp/rib-impl-config/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPPeerModuleTest.java#L148

Comment by Martin Vitez [ 15/Jul/14 ]

Proposed patch:

https://git.opendaylight.org/gerrit/#/c/9006/

Generated at Wed Feb 07 20:52:33 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.