[SNMP4J] Initial scalar value is null with custom TC
forum at friendlysnmp.org
forum at friendlysnmp.org
Fri Aug 21 16:40:44 CEST 2009
Iâve upgraded to agent v1.3 (and AgenPro 2.7.5) and discovered many NPEs in my application.
The AgenPro generates:
=========
private MOScalar myTest;
protected void createMO(..) {
myTest = moFactory.createScalar(oidMyTest,
moFactory.createAccess(..),
null, <-- problem. Was: new OctetString()
TC_MODULE_TEST_MIB, TC_TESTTC);
}
=========
Itâs expected that generated custom class
public class TestTC implements TextualConvention {
public MOScalar createScalar(..) {..}
public Variable createInitialValue() {..}
}
will create and initialize the scalar.
However the TestTC.createScalar() never calls TestTC.createInitialValue() to set scalar initial value.
The trivial solution to add the missing call and initialize scalar maybe is not good at all. The problem
is in scalar constraints which may contradict the initial value. Hopefully AgenPro could generate smart
initial values for all possible custom TCs.
On other hand leaving the scalar value null gives an option for the application to set scalar value of
ANY "Variable" type. This easily breaks scalar type safety because MOScalar does not have any
information of the scalar value syntax or TC.
As a solution I see adding value syntax and TC data into MOScalar class and define them through
constructor. This will make them immutable in the MOScalar class. The call MOScalar.setValue() with not
matching scalar syntax and value syntax will return error code.
What do you think about proposed solution?
How to deal with NPEs described above? Iâd like not to set initial values manually in the code. This
breaks regression tests in my old applications.
-fs
More information about the SNMP4J
mailing list