[SNMP4J] NPE in OctetString

Jack Holt jackcholt at gmail.com
Thu May 28 20:41:32 CEST 2009


I am developing an SNMP agent based on org.snmp4j.agent.example.SampleAgent.
I have modified Modules.java and Snmp4jDemoMib.java according to what I
think I need but when I run it, I get the following error:

Exception in thread "main" java.lang.NullPointerException
    at org.snmp4j.smi.OctetString.<init>(Unknown Source)
    at
org.snmp4j.agent.mo.snmp4j.Snmp4jConfigMib.setPrimaryProvider(Snmp4jConfigMib.java:526)
    at
org.snmp4j.agent.AgentConfigManager.initSnmp4jConfigMIB(AgentConfigManager.java:284)
    at
org.snmp4j.agent.AgentConfigManager.initOptionalMIBs(AgentConfigManager.java:585)
    at
org.snmp4j.agent.AgentConfigManager.initialize(AgentConfigManager.java:572)
    at net.ccsd.agent.McsAgent.run(McsAgent.java:119)
    at net.ccsd.McStatus.main(McStatus.java:64)

The class level variables and constructor for my Agent looks like this:

protected AgentConfigManager agent;
    protected MOServer server;
    private String configFile = null;
    private File bootCounterFile = new File("mcstatus.bc");
    protected Modules modules;

public McsAgent() throws FileNotFoundException {
        server = new DefaultMOServer();
        MOServer[] moServers = new MOServer[] { server };
        InputStream configInputStream = new
FileInputStream("mcstatus_config.properties");

        final Properties props = new Properties();
        try {
            props.load(configInputStream);
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        MOInputFactory configurationFactory = new MOInputFactory() {
            public MOInput createMOInput() {
                return new PropertyMOInput(props, McsAgent.this);
            }
        };

        List<String> addrList = new ArrayList<String>();
        addrList.add("udp:127.0.0.1/4700");
        addrList.add("tcp:127.0.0.1/4700");

        MessageDispatcher messageDispatcher = new MessageDispatcherImpl();
        addListenAddresses(messageDispatcher,  addrList);
        agent = new AgentConfigManager(new
OctetString(MPv3.createLocalEngineID()), messageDispatcher, null, moServers,
                ThreadPool.create("McsAgent", 3), configurationFactory, new
DefaultMOPersistenceProvider(moServers,
                        configFile), new
EngineBootsCounterFile(bootCounterFile));
    }

Perhaps the first thing I need is some understanding of all the parameters
to the AgentConfigManager constructor.  I honestly have no clue as to what
the contents of the example SampleAgentConfig.properties file are really
doing (I changed the name of that file to "mcstatus_config.properties" but
have made no other changes to it yet), what the configFile should contain
(I'm passing null, which is probably the source of the problem) or why we're
counting something called "engine boots".

Could you point me to some information that will help me understand this
better?  I promise I'll read it.



More information about the SNMP4J mailing list