Serial2 port responding even without any input

I am using Arduino Due to have serial communication with a device which takes command in Hex format and immediately sends response.But i encountered a problem where the loop enters serial2.available() even when there were no data available.So i wrote a small test program for Serial2 to test.Below is my code.

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial2.begin(115200);

}

void loop(){
 if (Serial2.available()){
  
  Serial.write("test");
 }
}

So when i run my above program i see "test" is printed again and again even when there is no data available in serial2 port.Am i missing something?

You never empty the Serial2 buffer so the character that was originally there is always there.

See what happens when you add Serial2.read().

You may find some useful stuff in serial input basics

...R