Appium throws stack overflow size error

Code:

Assert.assertEquals(driver.findElement(By.xpath("//android.widget.LinearLayout[@index='1']")).isDisplayed(), true);

Error:

Encountered internal error running the command: An unknown server-side error occurred while processing the command. Original error: java.lang.StackOverflowError: stack size 1042KB