0
  if (packet.hasHeader(ip)) {  
         String str = FormatUtils.ip(ip.source());  

         if (packet.hasHeader(Payload.ID)) {

             try{
             payload = packet.getHeader(new Payload());
             }
             catch(Exception e)
             {
                System.err.println("ERROR"); 

             }


              if(payload!=null){
              String pattern;
              synchronized (MainThread.lockB){ 
              pattern=MPSM.findpatt(payload.toString());
              }
            synchronized (MainThread.lockB){ 
                smpsmCheckPattern(pattern, nameOfAdd, payload.toString() );
                }
              }'

sometimes when i run the programm i get IndexOutOfBoundsEcxeption in try "payload = packet.getHeader(new Payload());" i dont know why i get the exception

Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
Kostas
  • 1

1 Answers1

0

i guess the error is because the if cond checks for the protocol id of a previous packet which might be different from the payload which you are processing now.

Replace the below logic

if (packet.hasHeader(Payload.ID)) {

         try{
         payload = packet.getHeader(new Payload());
         }
         catch(Exception e)
         {
            System.err.println("ERROR"); 
         }

with

Payload pl = new Payload();

if(packet.hasHeader(pl)) //this will check and retrieve the payload

jozef
  • 81
  • 6