sbernard31 / benchmark-clients

Command line tool base on https://www.eclipse.org/leshan/ to simulate a fleet of clients
16 stars 7 forks source link

Registration Failed : java.lang.NullPointerException with PR #7 #8

Open sbernard31 opened 1 year ago

sbernard31 commented 1 year ago

When running https://github.com/sbernard31/benchmark-clients/pull/7 based on Leshan 2.0.0-M10 using , java -jar target/benchmark-clients-0.2.0-SNAPSHOT-jar-with-dependencies.jar -n 2 -u coap://leshan.eclipseprojects.io -e device%08d I get :

2023-01-13 17:31:40,898 DEBUG o.e.l.b.c.BenchClient          - Registration Failed : java.lang.NullPointerException

This doesn't happen with master based on Leshan 1.3.1.

After activating LOG in TRACE I get :

2023-01-13 17:32:59,418 INFO  o.e.l.c.c.LeshanClient         - Starting Leshan client ...
2023-01-13 17:32:59,903 INFO  .c.CaliforniumEndpointsManager - New endpoint created for server coap://leshan.eclipseprojects.io:5683 at coap://0.0.0.0:41041
2023-01-13 17:32:59,905 INFO  .c.e.DefaultRegistrationEngine - Trying to register to coap://leshan.eclipseprojects.io:5683 ...
2023-01-13 17:32:59,907 INFO  o.e.l.c.c.LeshanClient         - Leshan client[endpoint:device00000001] started.
2023-01-13 17:32:59,906 WARN  .c.e.DefaultRegistrationEngine - Unable to send register request
java.lang.NullPointerException: null
    at org.eclipse.leshan.client.servers.ServersInfoExtractor.getDeviceSupportedBindingMode(ServersInfoExtractor.java:281)
    at org.eclipse.leshan.client.engine.DefaultRegistrationEngine.register(DefaultRegistrationEngine.java:319)
    at org.eclipse.leshan.client.engine.DefaultRegistrationEngine.registerWithRetry(DefaultRegistrationEngine.java:295)
    at org.eclipse.leshan.client.engine.DefaultRegistrationEngine.access$600(DefaultRegistrationEngine.java:77)
    at org.eclipse.leshan.client.engine.DefaultRegistrationEngine$RegistrationTask.run(DefaultRegistrationEngine.java:572)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

Debugging this, it seems that client has no Device Object Enabler and so unable to get SupportedBindingMode.

Adding something like initializer.setInstancesForObject(DEVICE, new Device("manufacturer","modelnumber","serialnumber")); seems to solve the issue.

I need to investigate more to understand why this does happen with previous version of Leshan but I guess SupportedBindingMode is new resource from LWM2M 1.1.

jvermillard commented 1 year ago

Since an object device is mandatory, it would be nice to trigger a warning if the client starts without one.

sbernard31 commented 1 year ago

Yep agree with that.

sbernard31 commented 1 year ago

Since an object device is mandatory, it would be nice to trigger a warning if the client starts without one.

@jvermillard, I created a PR about that : https://github.com/eclipse/leshan/pull/1378 , If wanted you could have a look.