[SNMP4J] Initial scalar value is null with custom TC

Frank Fock fock at agentpp.com
Tue Sep 1 00:35:45 CEST 2009


The introduction of the createInitialValue was necessary
*because* the default initial values of the base syntaxes
*could* violate constraints defined by a TC.

createScalar does not directly use createInitialValue
because this would not allow a MOFactory instance to
control this usage.

DefaultMOFactory sets the initial value and thus
ensures type safety.

If you want to centralized cope with this change,
then use your own MOFactory instance.

Hope this helps.

Best regards,
Frank

forum at friendlysnmp.org wrote:
> 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
> 
> 
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.snmp4j.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list