#vulnerable code 
                                public void captureScreenshot(String methodName, String device, String className)
        throws IOException, InterruptedException {
        String context = getDriver().getContext();
        boolean contextChanged = false;
        if (getDriver().toString().split(":")[0].trim().equals("AndroidDriver") && !context
            .equals("NATIVE_APP")) {
            getDriver().context("NATIVE_APP");
            contextChanged = true;
        }
        scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        if (contextChanged) {
            getDriver().context(context);
        }
        FileUtils.copyFile(scrFile, new File(
            CI_BASE_URI + "/target/screenshot/" + device + "/" + device_udid.replaceAll("\\W", "_")
                + "/" + className + "/" + methodName + "/" + deviceModel + "_" + methodName
                + "_failed" + ".png"));
        Thread.sleep(3000);
    } 
                            #location 14 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                                public void captureScreenshot(String methodName, String device, String className)
        throws IOException, InterruptedException {
        String context = getDriver().getContext();
        boolean contextChanged = false;
        if (getDriver().toString().split(":")[0].trim().equals("AndroidDriver") && !context
            .equals("NATIVE_APP")) {
            getDriver().context("NATIVE_APP");
            contextChanged = true;
        }
        scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        if (contextChanged) {
            getDriver().context(context);
        }
        FileUtils.copyFile(scrFile, new File(
            "screenshot/" + device + "/" + device_udid.replaceAll("\\W", "_")
                + "/" + className + "/" + methodName + "/" + deviceModel + "_" + methodName
                + "_failed" + ".png"));
        Thread.sleep(3000);
    }