0

I know this is a common issue and I have already read some of the posts but could not figure out the root cause for the error yet.

I have devices which get parameters from a json file and the code generate topologies for that devices. I have a list of piconets (small master-slave groups) and the problem is the code works pretty well up to 45 number of device. When I increase the number of devices I get the error below;

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(Unknown Source)
    at java.util.ArrayList.get(Unknown Source)
    at KTHBleMesh.BleMeshDevice.construct(BleMeshDevice.java:508)
    at KTHBleMesh.BleMeshDevice$2.run(BleMeshDevice.java:468)
    at KTHBleMesh.Event.run(l2.java:21)
    at KTHBleMesh.Simulator.doAllEvents(l2.java:50)
    at KTHBleMesh.IteratorEngine.main(IteratorEngine.java:85)

and where the pops up is ;

List<BleMeshDevice> neighboringDevices =this.getTxManager().getNeighbouringDevices(this);
                for (BleMeshDevice neighDevice : neighboringDevices) {
                    if (neighDevice.devMiddleware.getTopologyCtrlBlock().getDevPiconet().get(0).getDevRole()==1) 

` getDevPiconet().get(0) is giving the error and here is the class code,

public BleMeshTopologyCtrlBlock() {
        devPiconet = new ArrayList<BleMeshDevicePiconet>(2);

private void AddMastertoSlave(BleMeshDevice linkMaster,
            BleMeshDevice linkSlave, int devRole) {

        devPiconet.add(new BleMeshDevicePiconet(devRole, linkSlave));
        devPiconet.get(devPiconet.size() -1).getDevSlaves().add(linkMaster);


for (BleMeshDevGatewayTable aRow : getDevPiconet().get(0)
                .getGatewaytable()) {
            if (aRow.getPicRemoteMaster().equals(aNeighPiconetMaster)
                    && aRow.getPicLocalGatewayDev().getDevMiddleware()
                            .getTopologyCtrlBlock().getCapacity() > 0
                    && aRow.getPicRemoteGatewayDev().getDevMiddleware()
                            .getTopologyCtrlBlock().getCapacity() > 0

It looks like it fails because the DevPiconet is empty but it works for other number of devices...I do not understand why it does not working when its increased number of devices.

Please let me know if you have any clue or suggestion,

Thanks in advance,

BR

Dudu OK
  • 3
  • 5
  • so you get the error if you have 46 or more devices? isn't there a mistake in you code at the constructor of `BleMeshTopologyCtrlBlock`? i can't see the `{` be closed before the next method – XtremeBaumer Dec 06 '16 at 14:41
  • Yes I get error after 45 devices. Constructor have } afer the last constructor – Dudu OK Dec 07 '16 at 09:13
  • can you post the full code of your project? – XtremeBaumer Dec 07 '16 at 09:32
  • I can not post all code since some of the code belongs to a private company. But added the part which causes the problem, please ask more details if you need and I can try to explain. – Dudu OK Dec 13 '16 at 14:36

1 Answers1

0

First in order to prevent exceptions you should check for null pointer and array size of your Piconet that is instead of checking the value of the first item dev role:

if (neighDevice.devMiddleware.getTopologyCtrlBlock().getDevPiconet().get(0).getDevRole()==1)

First check that the array is not null and his size is more then 0:

if (neighDevice.devMiddleware.getTopologyCtrlBlock().getDevPiconet() !=  null && neighDevice.devMiddleware.getTopologyCtrlBlock().getDevPiconet().size() > 0 &&  neighDevice.devMiddleware.getTopologyCtrlBlock().getDevPiconet().get(0).getDevRole()==1)

That way you only check valid values.

Regarding the devices number issue its related to business logic and more info about what are you doing is needed to determine

Michael A
  • 5,770
  • 16
  • 75
  • 127