Selenium Java - JavaScriptExecutor
Identify the error in the following Selenium Java code snippet:
WebElement checkbox = driver.findElement(By.id("agree"));
checkbox.setAttribute("checked", "true");