#vulnerable code 
                              @Override
  public Response handle() throws Exception {
    JSONObject payload = getRequest().getPayload();
    String type = payload.getString("using");
    String value = payload.getString("value");

    RemoteWebElement element = null;

    if (getRequest().hasVariable(":reference")) {
      int id = Integer.parseInt(getRequest().getVariableValue(":reference"));
      element = new RemoteWebElement(new NodeId(id), getSession());
    } else {
      element = getSession().getWebInspector().getDocument();
    }

    RemoteWebElement rwe;

    if ("link text".equals(type)) {
      rwe = element.findElementByLinkText(value, false);
    } else if ("partial link text".equals(type)) {
      rwe = element.findElementByLinkText(value, true);
    } else if ("xpath".equals(type)) {
      rwe = element.findElementByXpath(value);
    } else {
      String cssSelector = ToCSSSelectorConvertor.convertToCSSSelector(type, value);
      rwe = element.findElementByCSSSelector(cssSelector);
    }

    JSONObject res = new JSONObject();
    if (rwe == null) {
      throw new NoSuchElementException("No element found for " + type + "=" + value);
    } else {
      res.put("ELEMENT", "" + rwe.getNodeId().getId());
      Response resp = new Response();
      resp.setSessionId(getSession().getSessionId());
      resp.setStatus(0);
      resp.setValue(res);
      return resp;
    }
  } 
                            #location 13 
                            #vulnerability type NULL_DEREFERENCE
#fixed code
                              @Override
  public Response handle() throws Exception {
    waitForPageToLoad();

    int implicitWait = (Integer) getConf("implicit_wait", 0);
    long deadline = System.currentTimeMillis() + implicitWait;
    RemoteWebElement rwe = null;
    do {
      try {
        rwe = findElement();
        break;
      } catch (NoSuchElementException e) {
        //ignore.
      } catch (RemoteExceptionException e2) {
        // ignore.
        // if the page is reloading, the previous nodeId won't be there anymore, resulting in a
        // RemoteExceptionException: Could not find node with given id.Keep looking.
      }
    } while (System.currentTimeMillis() < deadline);

    if (rwe == null) {
      throw new NoSuchElementException(
          "No element found for " + getRequest().getPayload() + " after waiting for " + implicitWait
          + " ms.");
    } else {
      JSONObject res = new JSONObject();
      res.put("ELEMENT", "" + rwe.getNodeId().getId());
      Response resp = new Response();
      resp.setSessionId(getSession().getSessionId());
      resp.setStatus(0);
      resp.setValue(res);
      return resp;
    }
  }